How to put a shape under an XFormPrim

I’ve searched the documentation quite a bit and can’t figure out how to programmatically add a shape to an XFormPrim.

I’m trying this:

    blah = XFormPrim(

But I’m getting a C++ type error. Any ideas?

In the big picture I’m just trying to nest shapes under each other so that I can use local coordinates and so that related groupings of prims can move as one unit.

Haven’t tested this yet but I’m guessing that the parent/child relationship is automatically determined by the prim_path nesting – so that for example /World/xform/cuboid would automatically appear in the stage as a child of /World/xform.

Hi @dan.sandberg - To add a shape to an XFormPrim, you can create a new shape prim as a child of the XFormPrim. Here’s an example of how you can do this:

from pxr import Usd, UsdGeom

# Assume stage is an existing Usd.Stage
xform = UsdGeom.Xform.Define(stage, '/World/new_primx')

# Create a new cube as a child of the XForm
cube = UsdGeom.Cube.Define(stage, '/World/new_primx/cube')
In this example, a new XFormPrim is created at the path '/World/new_primx'. Then, a new CubePrim is created as a child of the XFormPrim at the path '/World/new_primx/cube'. The CubePrim will move together with the XFormPrim, and its coordinates will be local to the XFormPrim.

The error you’re seeing is likely because you’re trying to add a payload to the XFormPrim. Payloads are a way to reference external USD files, not to add child prims. To add child prims, you should use the Define method as shown in the example above.

If you want to group related prims so they can move as one unit, you can create an XFormPrim for each group and add the related prims as children of the XFormPrim. Then, when you move the XFormPrim, all of its child prims will move with it.

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