Can not adjust material parametrs by python


I would like to change the parameter of physics materials from python using kit.comands. However, the code does not work and there is no error output. The simulation is launched by KitHelper(). The code example is given below. It is should be noted that code works in python Editor.
stage = self.omni_kit.get_stage()
path = ‘/World/ZeroFrictionMaterial’


Could you please explain what you mean by ‘code works in python Editor’?

I mean that it works in Window–>Script Editor

@MikePhysX Is it possible to adjust frictionCombineMode using other methods instead of ```

bug_materials.mkv (6.6 MB)
I have recorded the short video in which you can see that script changes the property of material if this property was changed manually once, otherwise, the command does not work. Please give me the feedback on how to avoid that issue.

1 Like

I do not have a work-around for that problem. I will submit this to the engineering team for review and fix.

Thank you!

The alternative method to setting the property is using something like:

import omni
from pxr import Sdf, UsdPhysics, PhysxSchema
stage = omni.usd.get_context().get_stage()
prim = PhysxSchema.PhysxMaterialAPI(stage.GetPrimAtPath("/World/PhysicsMaterial"))

Unfortunately I think there is a bug in the ui which will not update properly unless you manually change something. If you set the value using the above code it should be correct when queried however.

Will follow up with the omniverse team to see if this can be resolved.

Thanks for the answer.
I have tried this approach and get an error:

In addition, I have tried to get the attribute value:

stage = omni.usd.get_context().get_stage()
prim = PhysxSchema.PhysxMaterialAPI(stage.GetPrimAtPath("/ZeroFrictionMaterial"))
att = prim.GetFrictionCombineModeAttr()

And got:
Value of attribute == None

Here is a slightly better answer that fixes the UI not updating issue, the PhysxMaterialAPI needs to be applied first before the rest will update in the ui.

import omni
from pxr import Sdf, UsdPhysics, PhysxSchema
stage = omni.usd.get_context().get_stage()
prim = stage.GetPrimAtPath("/World/PhysicsMaterial")
pma = PhysxSchema.PhysxMaterialAPI.Apply(prim)

Note that the attribute has to be created first before you can access it which is why


returns none

Thanks, it solved the issue.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.