If I sound frustrated in this post, it's because I am.
In my short, sad, and frustrating history attempting to maintain a working VRED integration for my customers, I've been sideswiped several times by the VRED product changing direction and frameworks for adding in a UI element. I need a menu item, set of push buttons, some sort of way for my customers to be able to submit jobs to a 3rd-party render queue.
I've followed Autodesk's recommendations each time, and can't keep up with the changes. First it was "submit from an external HTML interface" (think that was 2015). Then it is "create a top-level menu", which worked for a while, except when the UI framework changes from (I think it was) PyQt4 to PySide to PyQt5, sometimes between SP revisions.
In 2017 I was advised to go the "script plugin" route, which adds menu items to VRED's native "Scripts" top-level menu. All well and good. This approach worked for almost a year, which I think in a record. It even worked in VRED 2018 (v10.0.0.8809) without a hitch.
Now I find that in between 2018 (v10.0.0.8809) and 2018.2 (v10.1.0.8962), there's been a switch from PyQT to PySide2. Even that I could deal with.
But it seems that VRED won't allow me to write a plugin script that will work with both 2018 and 2018.2. I can't wrap the call to import PythonQt in a try...except..., VRED seems to pre-parse the script file and refuse to load it if the reference to PythonQt is not commented out, even when it's wrapped in a try/except block.
The following
try: from PythonQt import QtCore, QtGui except Exception: # normally I'd trap "ImportError", but tried this broad case as a test from PySide2 import QtCore, QtGui
results in the error message in the VRED terminal:
Couldn't load plugin 'C:/Users/Administrator/Documents/Autodesk/VRED-10.1/ScriptPlugins/Qube/Qube.py', it seems to use PythonQt this is not supported anymore!
If I comment it out like so:
#try: # from PythonQt import QtCore, QtGui #except Exception: # from PySide2 import QtCore, QtGui from PySide2 import QtCore, QtGu
my plugin loads without error, and the plugin UI launches correctly when the Script menu item is activated.
How can I go about writing plugin scripts that are more version-agnostic? It's problematic having a different version of the plugin for every minor and patch release of VRED, rather than a single plugin that can deal with the various permutations and combinations via try/except statements
Solved! Go to Solution.
Solved by michael_nikelsky. Go to Solution.
I understand your frustration, I didn´t like the switch from pySide to PythonQt either. Sadly when we had to update to Qt5 for various other reasons, pySide2 was nowhere near usable so we had to find another solution which was pythonQt at that time.
However, turned out that pythonQt is quite unstable and it is not properly maintained and since pySide2 will be the standard for the future since it is now hosted by Qt directly and it is under active development we now moved back (in fact we switched back in VRED 2018 already), so hopefully we can avoid changes like these in the future.
However, not being a python expert, I mostly write C++ code, using try-except does not sound like a clean solution anyways. I would recommend to try something like this (haven´t tested it for a script plugin though!):
if float(getVredVersion()) < 10.0: print "pythonQt" from PythonQt import QtCore, QtGui else: print "pyside" from PySide2 import QtCore, QtGui
Moving forward, with 2018.2 we added the option to set a version depending environment variable for script plugins, so when you set VRED2018_2_SCRIPT_PLUGINS you can define a list of pathes for plugins that will only be loaded for that specific version. This way you can have specialized plugins for specific versions.
Kind regards
Michael
Thanks for the response, and the insight into the UI framework turnover.
I tried your suggestion of testing the VRED version to conditionally load either PythonQT or PySide2, but it also fails in the same manner as the try/except approach, and I'm assuming for the same reasons, resulting in the error:
Couldn't load plugin 'C:/Users/Administrator/Documents/Autodesk/VRED-10.1/ScriptPlugins/Qube/Qube.py', it seems to use PythonQt this is not supported anymore!
Use of a try/except statement is the conventional "pythonic" way to handle cases like thi;, it's very odd (and highly unfortunate) that the VRED startup routine tries to 'outsmart' the script, possibly by a simple string search for 'PythonQt'. Can you shed any light on why VRED behaves this way? If I change the reference to PythonQt inside the try/except to anything else, the script loads without error, and my floating window is launched correctly, so the try/except block works as intended:
try: from foobar import QtCore, QtGui except Exception: from PySide2 import QtCore, QtGu
I also can't take advantage of the environment variable due to my use case: my customers use our job submission/monitoring/control UI to install the VRED script plugin, and requiring them to set environment variables has been very unpopular in the past, while procedurally setting the env_vars for them is prohibited by policy with some of our customers.
Currently our UI just copies the plugin script to the correct user-centric plugin location based on a version chosen with a set of spinCtrls. I'll have to "template" the script and write out different versions based on the values returned by the spinCtrl. Not a huge deal, but this really shouldn't be necessary if VRED would simply allow the script plugin authors to trap their own error conditions.
So a devious, underhanded, sneaky, and positively brilliant colleague recommended hiding the 'PythonQt' string in the script by splitting it up and then concatenating it back together in an exec or eval.
So, believe it or not, this does indeed work:
try: eval("from %s%s import QtCore, QtGui' % ('Python', 'Qt')") except Exception: from PySide2 import QtCore, QtGui
but this fails:
try: eval("from %s import QtCore, QtGui' % 'PythonQt'") except Exception: from PySide2 import QtCore, QtGui
Which leads me to believe that VRED is doing a regex match on the script prior to loading it and refusing if a match is found, even if the script would actually load.
Bad VRED. No cookies for you.
Ok, I have opened a ticket for this, I don´t see any use of this either. What happens is that there is in fact a search for lines containing import and pythonQt and import and PySide2 and if both are present the plugin will fail to load.
Can't find what you're looking for? Ask the community or share your knowledge.