How to check if Rigid Body exists on Object

I’m fluent with AS3 and C# but have only started using Python as part of my learning Blender. I have been working on a little script that automates a few things for me, but i’m having trouble checking for if an object has a rigid body physics modifier applied to it.

I tried checking the object for bpy.context.object.rigid_body.enabled = True but that throws an error and stops the script even when put inside a try/except. Apparently the rigid_body.enabled flag only exists if a rigid body is applied to the object.

I searched the documentation but can’t seem to find a flag that i can check to see if a rigid body is applied.

I’m fairly new to Python so please feel free to assume I know nothing when assisting me.

Nevermind. I figured it out.

I was simply building my Try/Except statement incorrectly.

can you show your final solution?I Have the same probleme

you don’t need a try-except, you can do a none-check:

if bpy.context.object.rigid_body is None:
    print("no rigid_body")
else:
    print("has rigid_body")

thank you,
sorry but I am a real beginner in scripting. I want to add Active Rigid Body to a Group. I do this:

    for ob in bpy.context.selected_objects :
        ob.rigid_body.enabled = True
        ob.rigid_body.type = 'ACTIVE'  

but sometimes return an error AttributeError:NoneType’ objecthas no attribute ‘enable’
Any idea?