# How to call sessionFromVersionIDs from python?

**URL:** <https://community.shotgridsoftware.com/t/how-to-call-sessionfromversionids-from-python/8308>\
**Category:** RV\
**Tags:** python-api, rv\
**Created:** [April 22, 2020, 4:45pm UTC](https://community.shotgridsoftware.com/t/how-to-call-sessionfromversionids-from-python/8308 "2020-04-22T16:45:39Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![supercool](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/supercool/32/2360_2.png) [@supercool](https://community.shotgridsoftware.com/u/supercool)\
**Post date:** [April 22, 2020, 4:45pm UTC](https://community.shotgridsoftware.com/t/how-to-call-sessionfromversionids-from-python/8308/1 "2020-04-22T16:45:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Michael.Kessler](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/michael.kessler/32/183_2.png) [@Michael.Kessler](https://community.shotgridsoftware.com/u/Michael.Kessler)\
**Post date:** [April 22, 2020, 7:48pm UTC](https://community.shotgridsoftware.com/t/how-to-call-sessionfromversionids-from-python/8308/2 "2020-04-22T19:48:40Z")

</div>

`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:

```auto
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:

```auto
/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](https://community.shotgridsoftware.com/uploads/short-url/yYOoH9htzF0ZuBth1nvEMnWkptq.rvpkg) (943 Bytes)

The source for the main function is displayed below (pre-build name replacement)

```auto
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

---

<div class="post-metadata">

**Author:** ![supercool](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/supercool/32/2360_2.png) [@supercool](https://community.shotgridsoftware.com/u/supercool)\
**Post date:** [April 23, 2020, 9:38am UTC](https://community.shotgridsoftware.com/t/how-to-call-sessionfromversionids-from-python/8308/3 "2020-04-23T09:38:13Z")

</div>

> [@Michael.Kessler](#):
>
> Using the `py-exec` is discouraged at this point,

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

```

---

<div class="post-metadata">

**Author:** ![Michael.Kessler](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/michael.kessler/32/183_2.png) [@Michael.Kessler](https://community.shotgridsoftware.com/u/Michael.Kessler)\
**Post date:** [April 23, 2020, 7:21pm UTC](https://community.shotgridsoftware.com/t/how-to-call-sessionfromversionids-from-python/8308/4 "2020-04-23T19:21:36Z")

</div>

> [@supercool](#):
>
> which worked if rvpush instance is **already** open, but if the first intance opened by above I get this error:

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?

---

<div class="post-metadata">

**Author:** ![supercool](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/supercool/32/2360_2.png) [@supercool](https://community.shotgridsoftware.com/u/supercool)\
**Post date:** [April 24, 2020, 6:32pm UTC](https://community.shotgridsoftware.com/t/how-to-call-sessionfromversionids-from-python/8308/5 "2020-04-24T18:32:55Z")

</div>

> [@Michael.Kessler](#):
>
> Strange, I’m doing the same thing and it is working

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.

---

<div class="post-metadata">

**Author:** ![Michael.Kessler](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/michael.kessler/32/183_2.png) [@Michael.Kessler](https://community.shotgridsoftware.com/u/Michael.Kessler)\
**Post date:** [April 24, 2020, 7:31pm UTC](https://community.shotgridsoftware.com/t/how-to-call-sessionfromversionids-from-python/8308/6 "2020-04-24T19:31:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![supercool](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/supercool/32/2360_2.png) [@supercool](https://community.shotgridsoftware.com/u/supercool)\
**Post date:** [April 28, 2020, 4:20pm UTC](https://community.shotgridsoftware.com/t/how-to-call-sessionfromversionids-from-python/8308/7 "2020-04-28T16:20:51Z")

</div>

> [@Michael.Kessler](#):
>
> 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.

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

---

<div class="post-metadata">

**Author:** ![Michael.Kessler](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/michael.kessler/32/183_2.png) [@Michael.Kessler](https://community.shotgridsoftware.com/u/Michael.Kessler)\
**Post date:** [May 4, 2020, 5:10pm UTC](https://community.shotgridsoftware.com/t/how-to-call-sessionfromversionids-from-python/8308/8 "2020-05-04T17:10:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![supercool](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/supercool/32/2360_2.png) [@supercool](https://community.shotgridsoftware.com/u/supercool)\
**Post date:** [May 5, 2020, 2:38pm UTC](https://community.shotgridsoftware.com/t/how-to-call-sessionfromversionids-from-python/8308/9 "2020-05-05T14:38:03Z")

</div>

> [@Michael.Kessler](#):
>
> let me know how using a package with `-sendEvent` works,

`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

---

<div class="post-metadata">

**Author:** ![Michael.Kessler](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/michael.kessler/32/183_2.png) [@Michael.Kessler](https://community.shotgridsoftware.com/u/Michael.Kessler)\
**Post date:** [May 5, 2020, 3:52pm UTC](https://community.shotgridsoftware.com/t/how-to-call-sessionfromversionids-from-python/8308/10 "2020-05-05T15:52:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![supercool](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/supercool/32/2360_2.png) [@supercool](https://community.shotgridsoftware.com/u/supercool)\
**Post date:** [May 5, 2020, 3:53pm UTC](https://community.shotgridsoftware.com/t/how-to-call-sessionfromversionids-from-python/8308/11 "2020-05-05T15:53:35Z")

</div>

no I didn’t.

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

---

<div class="post-metadata">

**Author:** ![Michael.Kessler](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/michael.kessler/32/183_2.png) [@Michael.Kessler](https://community.shotgridsoftware.com/u/Michael.Kessler)\
**Post date:** [May 5, 2020, 4:05pm UTC](https://community.shotgridsoftware.com/t/how-to-call-sessionfromversionids-from-python/8308/12 "2020-05-05T16:05:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Michael.Kessler](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/michael.kessler/32/183_2.png) [@Michael.Kessler](https://community.shotgridsoftware.com/u/Michael.Kessler)\
**Post date:** [May 5, 2020, 4:18pm UTC](https://community.shotgridsoftware.com/t/how-to-call-sessionfromversionids-from-python/8308/13 "2020-05-05T16:18:25Z")

</div>

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

> [@ExternalWeb Package for RV](https://community.shotgridsoftware.com/t/externalweb-package-for-rv/3352):
>
> ExternalWeb Package - RV Developer Example Series In this example, we expose how to use external events to load a web page from within RV. This could be useful if you write a web-based RV integration into one of your studio’s web pages inside of RV, or use just the external event processing to pass custom information into your package from the commandline or rvlink. About this series: Over the years, I’ve made a number of packages for myself, developers looking get get around a…

---

<div class="post-metadata">

**Author:** ![supercool](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/supercool/32/2360_2.png) [@supercool](https://community.shotgridsoftware.com/u/supercool)\
**Post date:** [August 7, 2020, 5:58pm UTC](https://community.shotgridsoftware.com/t/how-to-call-sessionfromversionids-from-python/8308/14 "2020-08-07T17:58:26Z")

</div>

> [@Michael.Kessler](#):
>
> ```auto
> 
> [quote="Michael.Kessler, post:2, topic:8308"]
> To put this all as one functional example, here’s a minimal package that can be invoked. [Example_Package_PythonShotgun-1.0.rvpkg](/uploads/short-url/yYOoH9htzF0ZuBth1nvEMnWkptq.rvpkg) (943 Bytes)
> [/quote]
> 
> > Blockquote
> 
> ```

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)

```

---

<div class="post-metadata">

**Author:** ![Michael.Kessler](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/michael.kessler/32/183_2.png) [@Michael.Kessler](https://community.shotgridsoftware.com/u/Michael.Kessler)\
**Post date:** [August 7, 2020, 6:02pm UTC](https://community.shotgridsoftware.com/t/how-to-call-sessionfromversionids-from-python/8308/15 "2020-08-07T18:02:11Z")

</div>

Are you replacing MODE\_NAME with the actual mode’s name?

---

<div class="post-metadata">

**Author:** ![supercool](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/supercool/32/2360_2.png) [@supercool](https://community.shotgridsoftware.com/u/supercool)\
**Post date:** [August 7, 2020, 6:03pm UTC](https://community.shotgridsoftware.com/t/how-to-call-sessionfromversionids-from-python/8308/16 "2020-08-07T18:03:04Z")

</div>

its the name of the plugin ` shotgunmode`

---

<div class="post-metadata">

**Author:** ![Michael.Kessler](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/michael.kessler/32/183_2.png) [@Michael.Kessler](https://community.shotgridsoftware.com/u/Michael.Kessler)\
**Post date:** [August 7, 2020, 6:04pm UTC](https://community.shotgridsoftware.com/t/how-to-call-sessionfromversionids-from-python/8308/17 "2020-08-07T18:04:29Z")

</div>

Are you OK attaching your full package? If not, feel free to open a support ticket at [support@shotgunsoftware.com](mailto:support@shotgunsoftware.com)

-Kessler

---

<div class="post-metadata">

**Author:** ![supercool](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/supercool/32/2360_2.png) [@supercool](https://community.shotgridsoftware.com/u/supercool)\
**Post date:** [August 7, 2020, 6:31pm UTC](https://community.shotgridsoftware.com/t/how-to-call-sessionfromversionids-from-python/8308/18 "2020-08-07T18:31:14Z")

</div>

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.
