Instantiating and referring to a mesh or prim in another file

Hi,
I have a usd scene that I got from sketchfab and that contains a single power pole object.

I also have a digital twin of some parts of a city.
I need to use the power pole on different spots of the city.
So far I have separated the power pole prim and stored it in another usda file.

How can I refer to that prim which is in a different file on my pc via script editor?

Hi @Ai-Da. Great question! You probably want to use References for this. Here’s more info about that: USD Terms and Concepts — Universal Scene Description 22.08 documentation
Here’s an example snippet:

usd_context = omni.usd.get_context()

omni.kit.commands.execute(
    "CreateReferenceCommand",
    usd_context=usd_context,
    path_to="/World/where/to/put/it",
    asset_path=r"C:\Users\bob\Documents\power_pole.usd",
    instanceable=False,
)

This might be helpful: each time you perform an action in Code/Create, etc, for example moving a mesh in the viewport, you can get the corresponding code that was used in the Commands window, which is docked at the bottom right area.

In that window, just select the newly created command and click “Generate script to clipboard from: Selected commands” button. You’ll then get in the clipboard commands similar to the “CreateReferenceCommand” above.

For example, after manually moving a cube in the viewport you’d get this command listed:

omni.kit.commands.execute('TransformPrimSRT',
	path=Sdf.Path('/World/Cube'),
	new_translation=Gf.Vec3d(181.432373046875, 98.69508361816406, 79.56932347634911),
	new_rotation_euler=Gf.Vec3d(0.0, 0.0, 0.0),
	new_rotation_order=Gf.Vec3i(0, 1, 2),
	new_scale=Gf.Vec3d(1.0, 1.0, 1.0),
	old_translation=Gf.Vec3d(181.432373046875, 98.69508361816406, -9.894403457641602),
	old_rotation_euler=Gf.Vec3d(0.0, 0.0, 0.0),
	old_rotation_order=Gf.Vec3i(0, 1, 2),
	old_scale=Gf.Vec3d(1.0, 1.0, 1.0))

To move a mesh to a spot position, most of these parameters are unneeded, you just need “new_translation=”.

Also, at the top of the Commands window you can click “Search commands” to look for the possible parameters for each command.

1 Like

Thanks @jordio! I agree that’s a good start for @Ai-Da. Ai-Da, you’ll also need to be aware that we don’t currently support geospatial coordinates, so you’ll need to be aware of that limitation as you plan out your city twin.

1 Like

@mati-nvidia
Thanks for your help with the references.
Next thing, I need to iterate between several pinned spots on a model and replace the pins with one of those power poles. The pins are all located under a mutual prim.
Here is how it should look like:

while (there exists a pin prim under the mutual prim):
(get the transform attributes of the pin)
(create a power pole prim)
(relocate the power pole with the acquired transform attributes)
(make the original pin hidden)
(go to the next pin)

Can you please help me with those codes too?

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