RV Python quickstart

RV now ships with Python in addition to Mu for scripting and extending the application cross platform. Python is a full peer to Mu as far as RV is concerned. The command API is almost identical between the two.

In order to extend RV using Python you will be making a "mode" as part of an rvpkg package—this is identical to the way it’s done in Mu and this is the method that we use internally to add new functions to RV's interface. Creation of a modes and packages is documented in the reference manual. Please read the relevant sections to understand how it’s done. Here is a very simple mode written in Python which is part of $RV_HOME/rvpkgs/pyhello-1.0.rvpkg. You can add and install $RV_HOME/rvpkgs/pyhello-1.0.rvpkg to see it working.

import rv.rvtypes
import rv.commands

class PyHello(rv.rvtypes.MinorMode):
  "A simple example that shows how to make shift-Z start/stop playback"

  def togglePlayback(self, event):
    if rv.commands.isPlaying():
      rv.commands.stop()
    else:
      rv.commands.play()

  def __init__(self):
    rv.rvtypes.MinorMode.__init__(self)
    self.init("pyhello",
              [("key-down--Z", self.togglePlayback, "Z key")],
              None)

def createMode():
  "Required to initialize the module. RV will call this function to create your mode."
  return PyHello()

Documentation:

Please read the *reference manual* which is available on-line here.

or from RV's Help->RV Reference Manual menu items.

The command API is nearly identical to Mu. There are a few modules which are important to know about: rv.rvtypes, rv.commands, rv.extra_commands, and rv.rvui. These implement the base Python interface to RV.

We currently do not have separate documentation for RV's command API in Python (e.g., via Pydoc), but you can use the existing Mu Command API Browser available under RV's Help menu. The commands and extra_commands modules are basically identical between the two languages. We hope to have a Pydoc solution in the future.

If you are not familiar with Python please visit python.org to find relevant documentation, books, and tutorials. We cannot answer support questions about Python the language but we are happy to help with questions regarding RV's Python integration and Python command API.

Note: Edited to use import instead of "from".
Follow

10 Comments

  • 0
    Avatar
    Olivier Ozoux

    Awesome! can't wait to test this. Can you correct the example to remove the from module import * statements? because you have two of them, we can't tell which modules the different items are coming from. Would prefer a from rv import commands followed by declarations using the full commands.play() form. (and it's more pythonic ;-) )

  • 0
    Avatar
    Jim Hourihan

    Ok, changed it to be more Pythonic. Thanks.

      -Jim

  • 0
    Avatar
    Scott Ballard

    It seems that the latest version of RV 6.2.2 doesn't come with the pyhello package to use as an example. Very frustrating.

  • 0
    Avatar
    Jon Morley

    Hi Scott,

    I added the package to the original post above.

    Thanks,

    Jon

  • 0
    Avatar
    Kartik Hariharan

    Hey,

    I am on RV 7 and I am unable to import rv.commands. which python interpreter do I use and where should I find rv.commands?

    Regards,
    Kartik

  • 0
    Avatar
    Jon Morley

    Hi Kartik,

    The rv module is only available from packages being run by an interactive RV process. You cannot load them outside of RV. Are you trying to do that by chance or are you having trouble getting your package working?

    Thanks,
    Jon

  • 0
    Avatar
    Kartik Hariharan

    Hi Jon,

    I was just running the py-interp.exe from rv's bin folder. I have a feeling that is not how it should be done. How would I run the interavtice RV process?

    Thanks!
    Kartik

  • 0
    Avatar
    Kartik Hariharan

    Ok I just stumbled upon this:

    https://support.shotgunsoftware.com/hc/en-us/community/posts/209498208-workflow-for-scripting-

    And that clarifies a lot. I was expecting a workflow like scripting in Maya, with an interactive console/mayapy to interactively test scripts.

    So my understanding now is, write your script, place it in the folder/create rv package, load it up in RV and watch it go.

    Let me know if I have understood it correctly. It would also be useful to know if there is a way to interactively script in a console attached to an RV process. Please do let me know.

    Thank you.
    Kartik

  • 1
    Avatar
    Jon Morley

    Hi Kartik,

    If you are using RV version 7 or higher and Shotgun credentials to authenticate RV, the Shotgun Review package has a ToolKit driven Python Console for RV. You can use that.

    Also included with every release of RV is a companion application called rvshell that, as a proof of concept sample, allows you to send remote commands to an RV instance over the network protocol. This can be used to send pyexec, pyeval, and mueval events to a running RV. Please read more about that here:

    http://tweaksoftware.com/static/documentation/rv/current/html/rv_reference.html#Chapter_13_Network_Communication_Example_Code_Using_rvshell

    Thanks,
    Jon

  • 0
    Avatar
    Kartik Hariharan

    Thanks, Jon!

Please sign in to leave a comment.