Can not adjust material parametrs by python

Hello!

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’
omni.kit.commands.execute(‘AddMaterialCommand’,
stage=stage,
path=path,
density=1000,
staticFriction=0.0,
dynamicFriction=0.0,
restitution=0.0)

    omni.kit.commands.execute('ChangeProperty',
                              prop_path=Sdf.Path('/World/ZeroFrictionMaterial.physxMaterial:frictionCombineMode'),
                              value='min',
                              prev=None)

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 ```
omni.kit.commands.execute(‘ChangeProperty’…?

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"))
prim.CreateFrictionCombineModeAttr(PhysxSchema.Tokens.min)

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)
pma.CreateFrictionCombineModeAttr(PhysxSchema.Tokens.min)

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

prim.GetFrictionCombineModeAttr()

returns none

Thanks, it solved the issue.

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