sessionFromVersionIDs
is a Mu extension (Part of the shotgun_integration
package), and not part of the core application so it isn’t automatically bound to Python.
Using the py-exec
is discouraged at this point, and has some limitations placed on it. The more preferable way is to author a package that either responds to command line flags or responds to an external event.
The sessionFromVersionIDs, however can be bound, just like a native bound Mu symbol to Python.
Using pymu.MuSymbol
you can bind the package function like so:
MuSymbol("shotgun_mode.sessionFromVersionIDs")
This returns a callable that will invoke the Mu code with appropriate (when possible) data translations. So you just need to pass it an array of ints in Python.
To call this from the command-line, you can use -sendEvent <eventName> <eventContents>
. An example of this might look like:
/Applications/RV.app/Contents/MacOS/RV -sendEvent shotgun-load-versions "[7332,7326]"
When that launches, an event called external-shotgun-load-versions
is called immedately after startup and given the event.contents of a string containing [7332,7326]
.
To put this all as one functional example, here’s a minimal package that can be invoked. Example_Package_PythonShotgun-1.0.rvpkg (943 Bytes)
The source for the main function is displayed below (pre-build name replacement)
from rv import commands, rvtypes
from pymu import MuSymbol
from rv.commands import NeutralMenuState
import json
class {PACKAGE_NAME}Mode(rvtypes.MinorMode):
def __init__(self):
rvtypes.MinorMode.__init__(self)
globalBindings = [("external-shotgun-load-versions", self.loadVersions, "Loads Shotgun Versions given IDs")]
localBindings = None
menu = None
self.sessionFromVersionIDs = MuSymbol("shotgun_mode.sessionFromVersionIDs")
self.init("{PACKAGE_NAME}", globalBindings, localBindings, menu)
def loadVersions(self, event):
print "DEBUG: Called loadVersions with payload: %s" % (event.contents())
versionIDs = json.loads(event.contents())
print versionIDs
self.sessionFromVersionIDs(versionIDs)
def createMode():
return {PACKAGE_NAME}Mode()
By doing it this way, you also open yourself up to a far more maintainable structure where you can do more logic on the back-end without having to do all the meta-programming on the command-line.
Cheers,
-Kessler