Hi, I have a recurring problem in blender with a python module I wrote. I have to take an existing object, make it active, then copy it's property into another object. It's been a pain in the ass since I tried to do so . For now the recurring error I get is :
Error: Python: Traceback (most recent call last):
File "C:\Users\Alexandre\AppData\Roaming\Blender Foundation\Blender\3.1\scripts\addons\Nameplate_bender\nbe_op.py", line 692, in execute
finish_dupliker(active_obj,params)
File "C:\Users\Alexandre\AppData\Roaming\Blender Foundation\Blender\3.1\scripts\addons\Nameplate_bender\nbe_op.py", line 657, in finish_dupliker
create_full_large_element(active_obj,nameplate_size,mirror_model,autoremesh,decimate_replace)
File "C:\Users\Alexandre\AppData\Roaming\Blender Foundation\Blender\3.1\scripts\addons\Nameplate_bender\nbe_op.py", line 418, in create_full_large_element
func_duplicateNfinish(active_obj,decimate_replace_active,mirror_model_active,autoremesh_active,element)
File "C:\Users\Alexandre\AppData\Roaming\Blender Foundation\Blender\3.1\scripts\addons\Nameplate_bender\nbe_op.py", line 331, in func_duplicateNfinish
new_obj = bpy.context.active_object.copy()
AttributeError: 'NoneType' object has no attribute 'copy'
location: <unknown location>:-1
the code that is causing the error is this one:
def func_duplicateNfinish(obj,decimate_replace,mirror_model,autoremesh,params):
print_timestamp("func_duplicateNfinish")
(nameplate_size,xvalue,yvalue,zvalue,xscale,yscale,zscale,xrotate,yrotate,zrotate,version,kind)=params
active_obj=obj
func_apply_transforms(active_obj)
decimate_replace_active=decimate_replace
mirror_model_active=mirror_model
autoremesh_active=autoremesh
func_activate_object(active_obj)
bpy.context.view_layer.objects.active = bpy.data.objects["Empty"]
bpy.context.object.hide_set(False)
if bpy.context.active_object is not None:
bpy.ops.view3d.snap_cursor_to_active()
bpy.context.view_layer.objects.active = active_obj
active_obj.select_set(True)
new_obj = bpy.context.active_object.copy()
bpy.context.collection.objects.link(new_obj)
new_obj.data = new_obj.data.copy()
bpy.ops.object.select_all(action='DESELECT')
bpy.context.view_layer.objects.active = bpy.data.objects[new_obj.name]
new_obj.name= nameplate_size + "_" + kind + "_" + obj.name + "_style_" + version
bpy.ops.object.origin_set(type='ORIGIN_CURSOR', center='MEDIAN')
bpy.context.object.location[0] = float(xvalue)
bpy.context.object.location[1] = float(yvalue)
bpy.context.object.location[2] = float(zvalue)
bpy.context.object.scale[0] = float(xscale)
bpy.context.object.scale[1] = float(yscale)
bpy.context.object.scale[2] = float(zscale)
bpy.context.object.rotation_euler[0] = float(xrotate)
bpy.context.object.rotation_euler[1] = float(yrotate)
bpy.context.object.rotation_euler[2] = float(zrotate)
params= (nameplate_size,True,True,mirror_model_active,True,autoremesh_active,True,True,True,True,decimate_replace_active,True)
finish_greeblie(new_obj,params)
bpy.ops.object.select_all(action='DESELECT')
and the part that is really annoying, causing the error is this :
active_obj.select_set(True)
new_obj = bpy.context.active_object.copy()
Any idea on how to pass all parameters of an object to a new one? and how to desactivate this error?
What I have tried:
I have tried running this script many times. It fails for reason I don't understand, and sometimes it runs, and I still don't understand why. I feel like I'm turning around, and I don't know how to solve it.