Creating and destroying prims during runtime in Isaac Sim


Is there a way to instantiate and destroy prims during runtime in Isaac Sim?

I want to create boxes (initialized with random rotations) and have them fall into a conveyor.

Similarly, is there a way to destroy them (for example, upon exiting the FOV of the camera)?

Thank you

Hi @felipe.cunha1 - Yes, you can create and destroy prims during runtime in Isaac Sim.

To create a prim, you can use the create_prim function from the omni.usd module. Here is an example of how to create a cube:

from omni.usd import Usd, UsdGeom

stage = Usd.Stage.CreateNew('path/to/your.usda')
prim = stage.DefinePrim('/Cube', 'Xform')
cube = UsdGeom.Cube.Define(stage, '/Cube/cube')

In this example, a new stage is created, a new Xform prim is defined at the path ‘/Cube’, and then a cube is defined as a child of that Xform.

To delete a prim, you can use the RemovePrim function. Here is an example:


In this example, the prim at the path ‘/Cube’ is removed from the stage.

To create boxes with random rotations, you can use the UsdGeom.XformCommonAPI to set the rotation of the Xform prim. Here is an example:

from omni.usd import UsdGeom
import random

xformAPI = UsdGeom.XformCommonAPI(prim)
rotation = (random.uniform(0, 360), random.uniform(0, 360), random.uniform(0, 360))
xformAPI.SetRotate(rotation, UsdGeom.XformCommonAPI.RotationOrderXYZ)

In this example, a UsdGeom.XformCommonAPI is created for the prim, and then its rotation is set to a random value.

To destroy prims based on whether they are in the field of view of the camera, you would need to implement a check that determines whether the prim is in the camera’s field of view. If it is not, you can then call RemovePrim to remove it. The specifics of this check would depend on the details of your camera and scene setup.

1 Like

@rthaker thank you so much for your answer. This is exactly what I needed to get going.

I have used stage = self.stage to create the prim into my current tree and it worked nicely.

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