Create Custom RV Plugins + REZ Package
Create the RV Plugin
To create a custom RV plugin, you need to create two file:
- A python file that contains the plugin code (e.g.
myplugin.py
) - A manifest file that describes the plugin (named
PACKAGE
without extension)
Python file
I have follow (this tutorial)[https://community.shotgridsoftware.com/t/how-do-i-write-my-first-package-in-rv/96]
But i was facing to two errors:
- Named module error
- Python2 print error
So here is that i have edit and it works:
from rv import commands, rvtypes
from rv.commands import NeutralMenuState
class Example_Package_MyStuffMode(rvtypes.MinorMode):
def __init__(self):
rvtypes.MinorMode.__init__(self)
globalBindings = None #[("Event-Name", self.eventCallback, "DescriptionOfBinding")]
localBindings = None
menu = [
("Example", [
("Run Example", self.runExample, None, lambda: NeutralMenuState),
])
]
self.init("Example_Package_MyStuff", globalBindings, localBindings, menu)
def runExample(self, event):
print("DEBUG: Example Ran.")
def createMode():
return Example_Package_MyStuffMode()
Paste this code in a file named MyStuffMode.py
Then create a file named PACKAGE
without extension and paste this code:
package: MyStuff
author: Alexa Zalipyatskikh
organization: Autodesk
contact: support@shotgunsoftware.com
version: 1.0
requires: ''
rv: 7.3.1
modes:
- file: MyStuffMode
load: immediate
description: |
<p>Description of package here.</p>
Bundle the package
To create a RV package from this two file it's very simple, you just have to zip them in a file named MyStuff-<version>.rvpkg
and you have it !
You really need to respect the name structure of <name>-version.rvpkg
otherwise RV will not be able to load it.
Manually load it
To load our fresh new package, you just have to open RV and go to RV
=> preferences
=> packages
=> add packages
and select your package. Don't forget to check installed
and load
checkboxes.
Then restart RV and you should see your new menu in the Example
menu.
To enable it on startup
To enable our package on startup, we need to add it in the rvinstall
file, beside our .rvpkg file.
*MyStuffMode-2.0.rvpkg
Behavior
When you load a package, RV will copy the content of the package in the RV_SUPPORT_PATH
folder. So When a package is loaded rv will copy the .py file in the RV_SUPPORT_PATH/Python
folder. If a file already exists with the same name, he will raise a conflict error when you load the package. But if you load a package once, then edit or replace the .py file, RV will not copy the new file, and will keep the old one. But if after that you unload and reload the package, RV will erase the edited .py file and copy will copy the one from the .rvpkg.
Bundle all this stuff in a REZ package !
So now we have a RV package, but we want to be able to install it dynamically using REZ.
Environment variable
We will only use one environment variable to store the path to our RV package.
env.RV_SUPPORT_PATH.append('{root}')
.
This will be the root of rv pacakge stuff, and we will use it to store our .rvpkg and to unpack it. It's the 'working dir' of our package.
Generate package tree with RV
run rez env rv ourcustomrvpackage -- rv
And we can close it when it's open.
This will initialize and conform our package path to a RV package repository.
If you return to our rez package, we can see now we have lot of new files and folders.
And we don't need to keep our .rvpkg and PACKAGE file anymore. We should have something like this:
📦0.0.0
┣ 📂ConfigFiles
┣ 📂ImageFormats
┣ 📂lib
┣ 📂libquicktime
┣ 📂MovieFormats
┣ 📂Mu
┣ 📂Nodes
┣ 📂OIIO
┣ 📂Packages
┃ ┣ 📜MyStuffMode-2.0.rvpkg
┃ ┗ 📜rvinstall # Used to automatically enable our plugin on startup
┣ 📂Profiles
┣ 📂Python
┃ ┗ 📜MyStuffMode.py # this will be erased when manually disable and repalce on enable rv plugin
┣ 📂SupportFiles
┗ 📜package.py
If we have already launched, loaded our plugin and closed RV, we can directly edit and run our code from the Python
folder, and rerun our rez command.
But this work only if we have already loaded our plugin once, because RV will not copy the .py file if it already exists. This should not be used directly in production, but it's very useful for development.
RVisntall
I have created and empty file and this work, but i don't know if it's the right way to do it, because usually this file contains the list of current package loaded in RV.
In our case it's just a list of one package, but i don't know if it's a problem or not.
You should have something like this. rvinstall
file:
*MyStuffMode-2.0.rvpkg
But in my case it's just an empty file.
Final command
So now if we run rez env rv ourcustomrvpackage -- rv
we should have our package loaded in RV. And if we want to load an empty RV, we can run rez env rv -- rv
and we will have a fresh RV without our package loaded.