Skip to content

Instantly share code, notes, and snippets.

@lukpazera
Last active June 9, 2018 15:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lukpazera/10016255 to your computer and use it in GitHub Desktop.
Save lukpazera/10016255 to your computer and use it in GitHub Desktop.
Very simple script that renames selected items by adding a string prefix to each item's current name.
# 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