"it" is not your usual python interpreter so there are some things to know about adding scripts.
When a custom command is loaded via a .ini file you would typically put and file called it.ini in a folder alongside the python file containing your code. The it.ini file would look like this:
LoadExtension python acmd.py # It's a good idea to log the presence of the extension so we know # what we have on our RMS_SCRIPT_PATHS LogMsg NOTICE "Registered acmd extension"
import it def getCatalog(name): ''' return a catalog by name, if not found then create a new one. ''' model = it.app.GetModel() for cat in model.GetCatalogs(): if cat.GetLabel() == name: return cat cat = it.app.NewCatalog(name) return cat
LoadExtension python loader.py # It's a good idea to log the presence of the extension so we know # what we have on our RMS_SCRIPT_PATHS LogMsg NOTICE "Registered loader extension"
Now in this new file we set things up in python so we can load acmd.py as a module. In reload.py we have:
import sys import os # # this file is exec'd so python's __file__ is not accurate, we want to add the current # dir to python's import path. Fortunately "it" passes us the correct file name: moduledir = os.path.dirname(os.path.abspath(__it_extension_file__)) sys.path.append(moduledir) # import modules. Note we could loop over all .py files found in moduledir if # wanted to do something clever import acmd it.app.Notice("imported acmd")