0
$\begingroup$

I'm just starting my journey learning python + blender. However this was working until blender 2.9.3 and now throws an error

I'm sure there's tons of noob errors here, but could someone explain (like I'm 5) why this isn't working any longer? Thanks!

the error is as follows:

Python: Traceback (most recent call last): File "\ez_deform_v_1.py", line 81, in execute TypeError: bpy_struct: item.attr = val: expected a string enum, not _PropertyDeferred

location: :-1

    #import basic blender python api data
import bpy

class EZdeform(bpy.types.Operator):
    """EZDeformer"""
    bl_idname = "object.ez_deformer"
    bl_label = "EZDeformer"
    bl_options = {'REGISTER', 'UNDO'}
    
    defdivu = bpy.props.IntProperty(name= "Divisions X", default = 2)
    defdivv = bpy.props.IntProperty(name= "Y", default = 2)
    defdivw = bpy.props.IntProperty(name= "Z", default = 2)
    
    divtype = bpy.props.EnumProperty(
                    name='Lattice Type',
                    description='changes deformer type',
                    items={
                    ('KEY_LINEAR', 'Linear', 'a rigid influence'),
                    ('KEY_BSPLINE', 'BSpline', 'a smooth influence'),
                    ('KEY_CATMUL_ROM', 'Catmul Rom', 'a smooth influence'),
                    ('KEY_CARDINAL', 'Cardinal', 'Cardinal style influence')},
                    default='KEY_LINEAR')
    
    def execute(self, context):
        
        div_u = self.defdivu
        div_v = self.defdivv
        div_w = self.defdivw
        dtype = self.divtype
        
        bpy.ops.object.modifier_add(type='LATTICE')
        deftarget = bpy.context.object
        
        from mathutils import Vector
        #create a quick reference to the currently active object called "ob"
        bpy.ops.object.duplicate()
        bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY', center='BOUNDS')

        ob = bpy.context.object   
        
        obj = bpy.data.objects.new("dummy", None)
        scene = bpy.context.scene
        scene.collection.objects.link(obj)
        obj.matrix_world  = context.object.matrix_world
        


        #get boundingbox centerpoint offset from origin
        bboxcenter = sum((Vector(b) for b in ob.bound_box), Vector())
        bboxcenter /= 8 

        print("bbox center offset from origin")
        print(bboxcenter)

        # add a lattice modifier 
        bpy.ops.object.modifier_add(type='LATTICE')

        #get and store the deftarget's dimensions and location
        targetdim = ob.dimensions
        targetloc = obj.location
        targetloc = targetloc
        targetrot = obj.rotation_euler

        #create a new lattice object and set the location to that of the user's selected object, then name the lattice latestlattice
        bpy.ops.object.add(type='LATTICE', enter_editmode=False, align='WORLD')
        bpy.context.object.name = "ezdeformer"
        bpy.context.object.scale = targetdim
        bpy.context.object.location = targetloc
        bpy.context.object.rotation_euler = targetrot
        

        #assign divisions
        bpy.context.object.data.points_u = max(div_u, 2)
        bpy.context.object.data.points_v = max(div_v, 2)
        bpy.context.object.data.points_w = max(div_w, 2)
        
        bpy.context.object.data.interpolation_type_u = dtype
        bpy.context.object.data.interpolation_type_v = dtype
        bpy.context.object.data.interpolation_type_w = dtype
        
        mydeformer = bpy.context.object
        deftarget.modifiers["Lattice"].object = bpy.data.objects["ezdeformer"]

                
        mydeformer.select_set(state=False)
        ob.select_set(state=True)
        obj.select_set(state=True)
        bpy.ops.object.delete(use_global=False, confirm=False)
        
        deftarget.select_set(state=True)
        

        #select the orginal object (deftarget)
        
        
        

        mydeformer.select_set(state=True)
        bpy.ops.object.editmode_toggle()
        
        ## ------------ end script ------------
        return {'FINISHED'}

    def invoke(self, context, event):
        return context.window_manager.invoke_props_dialog(self)

# store keymaps here to access after registration
addon_keymaps = []


def register():
    bpy.utils.register_class(EZdeform)

    # handle the keymap
    wm = bpy.context.window_manager
    km = wm.keyconfigs.addon.keymaps.new(name='Object Mode', space_type='EMPTY')
    kmi = km.keymap_items.new(EZdeform.bl_idname, 'T', 'PRESS', ctrl=True, shift=False)
    addon_keymaps.append(km)

def unregister():
    bpy.utils.unregister_class(EZdeform)

    # handle the keymap
    wm = bpy.context.window_manager
    for km in addon_keymaps:
        wm.keyconfigs.addon.keymaps.remove(km)
    # clear the list
    del addon_keymaps[:]


if __name__ == "__main__":
    register()
$\endgroup$
1

Browse other questions tagged or ask your own question.