Isaac Sim Version
5.0.0
Operating System
Ubuntu 24.04
GPU Information
Topic Description
Detailed Description
I tried to delete the default ground plane of an isaacsim asset with following code. I tried two apis: stage.RemovePrim, prims_utils.delete_prim. None of them worked. But the prim could be successfully deleted form graphical interface.
import isaacsim.core.utils.prims as prims_utils
import isaacsim.core.utils.stage as stage_utils
ware_house = stage_utils.add_reference_to_stage(
"/warehouse.usd",
"/World/warehouse",
)
# self.stage.RemovePrim(Sdf.Path("/World/warehouse/GroundPlane"))
# self.stage.RemovePrim("/World/warehouse/GroundPlane")
prims_utils.delete_prim("/World/warehouse/GroundPlane")
@Carl_0127 you can use the following snippet to delete prim in Isaac Sim via kit command:
import omni.kit.commands
omni.kit.commands.execute("IsaacSimDestroyPrim",prim_path="/World/Xform")
that said, i believe your code should’ve worked. did you get any console warning along the line of “Cannot remove ancestral prim” when executing your snippet?
I don’t know what went wrong. This api doesn’t work for me either. And there is no warining about “Cannot remove ancestral prim”.
if you were to open the warehouse.usd directly (rather than being added to stage as a reference/payload) and try to delete the same plane via any of the snippets here, does the same behavior persist?
I just found there is a warining about “Cannot remove ancestral prim”.
Cannot remove ancestral prim /World/warehouse/GroundPlane
if that’s the case, the same warning should also appear in the GUI if you were to delete it manually; so i am curious how it’s allowing you to delete it.
the “cannot remove ancestral prim” warning stems from the fact that you aren’t supposed to delete the structure of a USD that’s being referenced to stage either as a reference or payload. in order for you to do so, you’d need to open up the said USD (in this case, warehouse.usd) and make that change.
however, one of many alternatives to work around it without having to open any references/payloads directly to make edits, is to deactivate it. this will effectively turn the prim off as it exist in your stage while preserving the hierarchy structure of the warehouse.usd:
import omni, omni.usd, omni.kit.commands
# deactivate prim from stage. set active flag as False to deactive; True to activate
omni.kit.commands.execute('ToggleActivePrims',
stage_or_context=omni.usd.get_context().get_stage(),
prim_paths=[Sdf.Path('/World/warehouse/GroundPlane')],
active=False)
you can also accomplish this in GUI via the Stage panel:
Thanks for the help. Deactivate it is a good idea. And I found if I open the usd directly, the ground prim can be successfully deleted. But the hierarchy structure no longer exists.
ware_house = stage_utils.open_stage("warehouse.usd")
could you elaborate on the hierarchy structure you are trying to keep?
assuming we have two USDs. one is warehouse.usd; another is a main.usd. in your original post, warehouse.usd is a child of main.usd because you are referencing it into main.usd (viaadd_reference_to_stage). the hierarchy will be defined as the defaultPrim of main.usd (World) as the parent of warehouse.usd. this will prevent you from altering warehouse.usd directly (this is why we get the warning regarding ancestral prims).
on the other hand, when you opened the warehouse.usd as is, you were able to delete the ground plane because we are editing the warehouse.usd directly and not as a reference/payload. so depending on what you are trying to accomplish in the end, there are a few options to delete a prim from a reference/payload while preserving the hierarchy:
- open the reference/payload USD (warehouse.usd) directly and delete the prim and save the file. by saving the file, all instances of warehouse.usd that are being referenced in other USDs, such as main.usd, will reflect the change the next time you open up main.usd.
- deactivate the prim as warehouse.usd is being referenced in other USDs. this is going to allow you to turn prims off without touching the warehouse.usd directly (the GroundPlane prim will still be in warehouse.usd). this will also preserve the hierarchy of main.usd. this will also allow you to reference the warehouse.usd multiple times into main.usd while giving you the flexibility to deactivate/activate certain prims within each warehouse.usd reference. this, i believe, should improve performance as you are simply loading the reference once instead of however many times you have it referenced into main.usd.
- the option we haven’t discussed is saving main.usd with warehouse.usd referenced in as flattened USD. this is going to break the referencing but should also preserve the hierarchy. the benefit is after flattening, it’ll be as if warehouse is copy into main.usd; this will give you the ability to do whatever you want with contents of the warehouse but loses the reference structure. in other words, if you were to open up warehouse.usd again and add/remove new meshes, the flattened USD will not reflect the same changes (opposite of option 1). another downside, is the file will be the size of warehouse.usd plus whatever you have in main.usd.
hope this makes sense?
Hi @Carl_0127,
As @Simplychenable explained, this is expected USD composition behavior. When you add warehouse.usd to your stage via add_reference_to_stage, the prims inside it are ancestral — they’re defined in the referenced layer, not your current
editing layer. USD doesn’t allow deleting prims that originate from a referenced file.
Solutions:
- Deactivate the prim (preferred — non-destructive):
from pxr import Usd
stage = omni.usd.get_context().get_stage ()
prim = stage.GetPrimAtPath("/World/warehouse/GroundPlane")
prim.SetActive(False)
This hides it from rendering and physics without modifying the source USD.
2. Use an over to make it invisible (also non-destructive):
from pxr import UsdGeom
imageable = UsdGeom.Imageable(prim)
imageable.MakeInvisible()
- Edit the source file directly if you want to permanently remove it from warehouse.usd.
This is a fundamental concept in OpenUSD — referenced/payloaded content is read-only in the referencing stage. Deactivation is the standard pattern for hiding unwanted prims from referenced assets.