Usage Examples#

Tag Management Operations on Omniverse Assets#

import omni.kit.commands
from omni.kit.property.tagging import AddTagCommand, RemoveTagCommand, UpdateTagCommand

# Common asset path for all operations
asset_path = "omniverse://localhost/Projects/MyAsset.usd"

# ----- Adding Tags -----
tag_to_add = "appearance.Car"

# Method 1: Execute the add command through the command system
omni.kit.commands.execute("AddTag", asset_path=asset_path, tag=tag_to_add)

# Method 2: Create and execute the add command directly with excluded tag option
add_cmd = AddTagCommand(asset_path=asset_path, tag=tag_to_add, excluded="appearance.Truck")
add_cmd.do()

# ----- Removing Tags -----
tag_to_remove = "appearance.Car"

# Remove a tag using the command system
omni.kit.commands.execute("RemoveTag", asset_path=asset_path, tag=tag_to_remove)

# ----- Updating Tags -----
old_tag = "appearance.Sedan"
new_tag = "appearance.SUV"

# Update a tag using direct command instantiation
update_cmd = UpdateTagCommand(asset_path=asset_path, old_tag=old_tag, new_tag=new_tag)
update_cmd.do()

Using Command Undo/Redo Functionality#

import omni.kit.commands
from omni.kit.property.tagging import AddTagCommand, UpdateTagCommand

# Working with command undo/redo for tag management
asset_path = "omniverse://localhost/Projects/MyAsset.usd"

# Add a tag and keep the command for later undo
add_cmd = AddTagCommand(asset_path=asset_path, tag="appearance.Car")
add_cmd.do()  # Execute the command to add the tag

# Later, undo the add tag operation
add_cmd.undo()  # Removes the tag we just added

# Update a tag with undo capability
update_cmd = UpdateTagCommand(
    asset_path=asset_path, 
    old_tag="color.Red", 
    new_tag="color.Blue"
)
update_cmd.do()  # Execute the command to update the tag

# Undo the update operation
update_cmd.undo()  # Changes the tag back from Blue to Red