'Object' object has no attribute 'my_tool'

Viewed 175

We try that the variables that we initialize in the addon pass to the execute function but it gives us an error in mytool. We want the variables to be taken out of the objects appear in the scene so we use mytool = Object.my_tool

class Propiedades(PropertyGroup):
    Frecuencia = FloatProperty(name = "Frecuencia",
    description = "La frecuencia con la que ocurren las interpolaciones",
    default = 23.7,
    min = 0.0,
    max = 50.0)

    Amplitud = FloatProperty(name = "Amplitud",
    description = "La amplitud maxima",
    default = 23.7,
    min = 0.01, 
    max = 50.0)

    Metodo = StringProperty(name="Metodo de Interpolacion",
    description="Añada el metodo que se va a usar",
    default="Lineal",
    maxlen=1024)

    Tension = FloatProperty(name = "Tension",
    description = "La tensión en la interpolación de Catmull-Rom",
    default = 0.0)

    Oscilacion = BoolProperty(name = "Oscilación Aleatoria",
    description = "Activa la oscilacion aleatoria",
    default = False)

    Velocidad = FloatVectorProperty(name = "Velocidad",
    description = "Velocidad en Hermite")

    Numobjetos = IntProperty(name = "Número de objetos",
    description = "Número de objetos en escena",
    default = 1)

class Panel_Operadores(Operator):
    bl_idname = "wm.hacer_interpolacion"
    bl_label = "Interpolación"

    def execute(self, context):
        Object = context.object
        
        fotogramas = bpy.data.actions['CubeAction'].fcurves.find('location', index = 0)
        for j in range(0, mytool.Numobjetos):
            for i in range(1, len(fotogramas.keyframe_points)-1):
                vec_pos = get_pos(mytool.Metodo, fotogramas.keyframe_points[i], context)
                bpy.data.objects['Cube'].keyframe_insert(frame = i, data_path="location")
                if mytool.Oscilacion == True:
                    vec_pos += modif_ale(mytool.Amplitud, mytool.Frecuencia)

        return {'FINISHED'}



class Panel_Custom(Panel):
    bl_label = "Panel";
    bl_idname ="OBJECT_PT_custom_panel"
    bl_space_type = "VIEW_3D"
    bl_region_type = "UI"
    bl_category = "Tools"
    bl_context = "objectmode"
    bl_label = "Hacer interpolación"

    @classmethod
    def poll(self, context):
        return context.object is not None

    def draw(self, context):
        layout =self.layout
        scene = context.scene
        mytool = scene.my_tool

        layout.prop(mytool, "Frecuencia")
        layout.prop(mytool, "Amplitud")
        layout.prop(mytool, "Metodo")
        layout.prop(mytool, "Tension")
        layout.prop(mytool, "Oscilacion")
        layout.prop(mytool, "Velocidad")
        layout.prop(mytool, "Numobjetos")
        TheCol = self.layout.column(align = True)
        TheCol.operator("wm.hacer_interpolacion", text="Hacer interpolacion")



classes = {Propiedades, Panel_Operadores, Panel_Custom}
#bpy.data.objects['Cube'].animation_data_clear()


def register():
    from bpy.utils import register_class
    for cls in classes:
        bpy.utils.register_class(cls)

    bpy.types.Scene.my_tool = bpy.props.PointerProperty(type = Propiedades)


def unregister():
    from bpy.utils import unregister_class
    for cls in reversed(classes):
        unregister_class(cls)

    del bpy.types.Scene.my_tool
    del bpy.types.Scene.make_Interpolacion


if __name__ == "__main__":
    register()

bl_info = \
    {
        "name" : "Hacer interpolación",
        "author" : "Grupo 4 Animación",
        "version" : (1,0,0),
        "blender" : (2,8,3),
        "location" : "View 3D > UI > Tools",
        "description" : "Realizar la interpolación",
        "warning" : "",
        "wiki_url" : "",
        "tracker_url" : "",
        "category" : "Tools"
    }

Now we try to use the Object values ​​in the execute

def interpola_valores(pos, pos1, pos2, pos3, metodo, numfot, context, velAnt, velPost):

    Object = context.object
    mytool = Object.my_tool    

    u = (numfot - (numfot-1))/((numfot+1)-(numfot-1))

    #interpolación lineal
    if metodo == "lineal":
        valorInterp = lin_interp (u, pos1, pos2)          

    #interpolación de Hermite
    if metodo == "Hermite":
        valorInterp = hermite_interp(u, numfot, pos, pos1, pos2, velAnt, velPost)

    #interpolación de Catmull-Rom
    if metodo == "Catmull-Rom":
        valorInterp = CatRom_interp(u, pos, pos1, pos2, pos3, mytool.Tension)
        

    return valorInterp

The error ocurs in mytool = Object.my_tool AttributeError: 'Object' object has no attribute 'my_tool'

0 Answers
Related