0
$\begingroup$

I'm running the following simple python code with no issues as far as the .blend file with the object I'm modifying is already open.

obj = bpy.data.objects['obj']
obj = C.scene.objects.active
obj.select = True
obj.rigid_body.type = 'PASSIVE'

However, if I add a line at the beginning of my code to open the file,

bpy.ops.wm.open_mainfile(filepath=task_path+ str(x) +".blend")

it opens the file and then I get an AttributeError after obj.rigid_body.type (object has no attribute 'type'). I've already spent several days trying different things. Could anyone help me to understand this? Thanks!

$\endgroup$
3
  • $\begingroup$ Perhaps the file you're loading doesn't have rigid body physics enabled for the object? $\endgroup$ Commented Jul 11, 2019 at 13:24
  • $\begingroup$ In the physics tab the object should have rigid body enabled. Or you can add bpy.ops.rigidbody.object_add() to your script to initialize it. $\endgroup$ Commented Jul 15, 2019 at 14:11
  • $\begingroup$ @gtzkw Thank you. That makes sense. I had that line (bpy.ops.rigidbody.object_add()) in my code before, but that gave me another error I wasn't able to understand: RuntimeError: Operator bpy.ops.rigidbody.object_add.poll() failed, context i incorrect $\endgroup$
    – ANB
    Commented Jul 15, 2019 at 14:19

0

You must log in to answer this question.

Browse other questions tagged .