How to call sessionFromVersionIDs from python?

How to call sessionFromVersionIDs from python ?

rvpush -tag foo py-exec 'sessionFromVersionIDs(11111)'

I tried looking rv.commands but couldnt find it,
I need it for keeping the session when rv is opened from shotgun.
like this I can pass version id which will keep the integration.

2 Likes

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

5 Likes

by the way , going by help py-exec and py-eval have same explanation, is there any difference ? I ran multiple tests infact py-exec does work but not py-eval.

since my intentions are to launch existing rv instance keeping the version id from the shotgun .

when I launch from shotgun, the rvlink:// protocol
I tried it like this:
rvpush -tag foo py-exec 'import pymu; pymu.MuSymbol("shotgun_mode.sessionFromVersionIDs")([123456])'

which worked if rvpush instance is already open, but if the first intance opened by above I get this error:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: Bad argument (0) to function shotgun_mode.sessionFromVersionIDs: expecting dynamic array
1 Like

Strange, I’m doing the same thing and it is working, however to reiterate, using py-exec and py-eval are no longer recommended. Have you tried the package approach yet?

So you have server URL already set , not sure if that makes any difference ?
I tried with setting the URL first.
But I got this error.
Could not find Mu symbol 'shotgun.theMode().setServerURLValue'
didn’t spent much time on this, but will surely try the package approach next week.

1 Like

Do make sure that shotgun_integration is enabled in your package manager. That’s often the cause if symbols of known items can’t be found.

Does this also happen when you run it from a -sendEvent? One of the benefits of sendEvent is execution order.

2 Likes

yes its enabled I double checked today, still I get the error. but I think by the time MuSymbal command executes shotgun_intgration package is not loaded.
and I think there is no way to set the order of rvpackage

Indeed, let me know how using a package with -sendEvent works, as all packages should be finished loading by the time this runs.

rv -sendEvent shotgun-load-versions '[11111,]'

It is just launching rv, then nothing happens ! I tried shotgun-load-versions searching for if this really correct

do you prepend external- on your plugin’s handling? When -sendEvent runs, it prepends external- to the event that you pass.

no I didn’t.

I pasted what I ran as is in my last reply.

No, I mean, what is the package that you wrote handling? Is it handling external-shotgun-load-versions, if not, it should be or the event will go unhandled and, as you are seeing, do nothing.

This package is a minimal example of how to use sendEvent:

I tried this, I do not get any error, but the self.loadversions is not getting called.
I also initialised self.init

self.init(MODE_NAME, None, None, [])
.
.
.
.
self.init("PythonShotgun", globalBindings, localBindings, menu)
1 Like

Are you replacing MODE_NAME with the actual mode’s name?

1 Like

its the name of the plugin shotgunmode

1 Like

Are you OK attaching your full package? If not, feel free to open a support ticket at support@shotgunsoftware.com

-Kessler

1 Like

I will do it on monday , I think this is a problem making it work on CentOS platform, this probably works on Mac as I am seeing the out of mac run has debug print from the callback function.

2 Likes