0
$\begingroup$

I have two objects which I want to make copies of them and apply transforms for these copies. I'm using the below script but it doesn't work and I don't know why?

obj1c=bpy.data.objects['Obj1']
obj2c=bpy.data.objects['Obj2']

obj1c = obj1c.copy()
obj2c = obj2c.copy()
obj1c.data = obj1c.data.copy()
obj2c.data = obj2c.data.copy()

bpy.ops.object.select_all(action='DESELECT')

obj1c.select = True
bpy.context.scene.objects.active = obj1c
bpy.ops.object.transform_apply(location = True, scale = True, rotation = True)
obj1c.select = False
bpy.ops.object.select_all(action='DESELECT')

obj2c.select = True
bpy.context.scene.objects.active = obj2c
bpy.ops.object.transform_apply(location = True, scale = True, rotation = True)
obj2c.select = False
$\endgroup$
4
$\begingroup$

It's because the copies are not on the scene so you can't make them active. To do so the command is bpy.context.scene.objects.link(ob)

import bpy


obj1c=bpy.data.objects['Obj1']
obj2c=bpy.data.objects['Obj2']

obj1c = obj1c.copy()
obj2c = obj2c.copy()

obj1c.data = obj1c.data.copy()
obj2c.data = obj2c.data.copy()

bpy.context.scene.objects.link(obj1c)
bpy.context.scene.objects.link(obj2c)

bpy.ops.object.select_all(action='DESELECT')

obj1c.select = True
bpy.context.scene.objects.active = obj1c
bpy.ops.object.transform_apply(location = True, scale = True, rotation = True)
obj1c.select = False
bpy.ops.object.select_all(action='DESELECT')

obj2c.select = True
bpy.context.scene.objects.active = obj2c
bpy.ops.object.transform_apply(location = True, scale = True, rotation = True)
obj2c.select = False
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.