Delete Item
# The following is an example of deleting items.
import ufe
import lookdevx as lx
if not shadingContainer:
raise Exception('This example requires a shading container i.e., a MaterialX document or a USD '
'material. Check the other examples to see how to create one.')
# Create some nodes.
runTimeId = shadingContainer.runTimeId()
item1 = ufe.NodeDef.definition(runTimeId, 'ND_add_float').createNode(shadingContainer, ufe.PathComponent('add'))
item2 = ufe.NodeDef.definition(runTimeId, 'ND_add_float').createNode(shadingContainer, ufe.PathComponent('add'))
# Items can be deleted using the `ufe.SceneItemOps` interface.
item1Ops = ufe.SceneItemOps.sceneItemOps(item1)
item1Ops.deleteItem()
print(f'Deleted "{ufe.PathString.string(item1.path())}".')
# Alternatively, the LookdevX API has a function to delete items as well.
lx.deleteItem(item2)
print(f'Deleted "{ufe.PathString.string(item2.path())}".')