If I print dir(physx_scene_object) I get a list with object attributes. The Gravity Direction and the Gravity Magnitude are in this list, but there is no mention of the other attributes.
Is there an easy way to list all attributes of such an object and a general way to change them?
The following snippet shows how to list all prim attributes and how to change one of them.
You can try it in the ScriptEditor
To get or set an attribute’s value, you need to use its name (one way to obtain it is by placing the cursor over the attribute)
import omni
stage = omni.usd.get_context().get_stage()
prim = stage.GetPrimAtPath("/physicsScene")
# list all attributes
for attribute in prim.GetAttributes():
print()
print("name:", "{}:{}".format(attribute.GetNamespace(), attribute.GetBaseName()) if attribute.GetNamespace() else attribute.GetBaseName())
print("display name:", attribute.GetDisplayName())
# set an attribute
prim.GetAttribute("physxScene:timeStepsPerSecond").Set(120)
thank you very much, that is what I was looking for.
But unfortunately, this doesn’t work for a freshly created physics scene.
If I, for example, create the physics scene directly in the code snipped, or through: create → Physics → Physics Scene
I only get the gravity direction and gravity magnitude as prim attributes. You can test it with this code snipped in an empty project:
import omni
from pxr import UsdPhysics
stage = omni.usd.get_context().get_stage()
# Physics scene definition
scenePath = "/physicsScene"
scene = UsdPhysics.Scene.Define(stage, scenePath)
prim = stage.GetPrimAtPath("/physicsScene")
# list all attributes
for attribute in prim.GetAttributes():
print()
print("name:", "{}:{}".format(attribute.GetNamespace(), attribute.GetBaseName()) if attribute.GetNamespace() else attribute.GetBaseName())
print("display name:", attribute.GetDisplayName())
# set an attribute
prim.GetAttribute("physxScene:timeStepsPerSecond").Set(120)
I can only see the other attributes, if I manually change an attribute once (for example, the number of time steps per second).
Is there a workaround for this? Otherwise, I would have to manually change the attribute once, after the scene is created.
To expand and explain the logic of the physics property widgets and why you see more in the UI than is sometimes accessible from the script: in our widgets we group the properties by logical components that consist of combinations of a prim and applied APIs and this should be transparent to the user (we deem it too low-level USD to show a per-schema view explicitly). Some of the schemas are thus considered an extension to others (like PhysxSchema.PhysxSceneAPI is to UsdPhysics.Scene), so when we see a Scene prim we show also the extension’s properties so that the users sees the whole range of available options even when the extension’s API is not applied at the moment. When the user edits one of the extension’s properties it will automatically apply the correct API (if not already applied).
(Note that there’s a sort of a debug view, which is the Raw widget, which is always shown as last in the property window and it includes only the actually authored properties.)
A bit low-level, but you can have a look at the extension_api_map dictionary in database.py of the physics property GUI extension omni.kit.property.physx to see all extensions we have defined by now. (This is not public API at the moment, so I do not guarantee the naming or the placement would stay the same moving forward)