Skip to content

Instantly share code, notes, and snippets.

@nicelifeBS
Forked from lukpazera/item_add_name_prefix.py
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicelifeBS/05fd9ca69d9b1d6508b0 to your computer and use it in GitHub Desktop.
Save nicelifeBS/05fd9ca69d9b1d6508b0 to your computer and use it in GitHub Desktop.
# python
""" Short snippet demonstrating how you can edit scene item's name using MODO 701 Python API.
"""
import lx
import lxu.select
PREFIX = 'prefix_'
# lxu.select module contains a few useful classes for dealing with selections.
# ItemSelection() allows for getting cuurent item selection.
# The returned list contains a set of lx.object.Item() interfaces
# that give access to MODO scene items.
selected_items = lxu.select.ItemSelection().current()
for item in selected_items:
# We're explicitly casting each item from the list to lx.object.Item().
# This is not really needed because item is lx.object.Item() already but
# if you're using editor with autocompletion like Komodo it'll allow your IDE
# to present you with a list of available methods for item.
# Also easier to remember what type of object item is.
item = lx.object.Item(item)
# lx.object.Item() contains a set of methods to operate on scene items.
# UniqueName() method returns an item's name as you see it in MODO UI.
item_name = item.UniqueName()
if item_name.startswith(PREFIX):
continue
item_name = PREFIX + item_name
# SetName() simply sets item's name to a string passed as argument.
item.SetName(item_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment