Hi Florian, I think i can help with the first issue.
1.
To access variables that are defined in the scope of your script plugin, you've got to inject some variables/attributes to modules.
In the script plugin:
import sys
import os
pluginPath = os.path.dirname(__file__)
if not pluginPath in sys.path:
sys.path.append(pluginPath)
# assumption: your module is called 'mymodulename'
# prerequisite: 'mymodulename' is located next to the script plugin python file
# prerequisite: 'mymodulename' is a hidden directory or a hidden python file
import mymodulename
class MyPluginClass():
pass
myPluginClass = MyPluginClass()
mymodulename.myPluginClass = myPluginClass
In Vred (e.g. terminal or variant set scripts)
import mymodulename
print(mymodulename.myPluginClass)
# terminal output: <VREDModule56.MyPluginClass object at 0x00000175B2455E50>
Keep in mind that the life-cycle of these attributes have to be considered since they might live longer than the VRED scene contents that they refer to. You can connect to vrMessageService or vrFileIOService signals to tidy up, reset or recreate your objects.
Also, any modules that you import are only imported once during the lifespan of a VRED runtime. Consequently, don't rely on just an import statement and global statements in the modules, but instead implement start and cleanup functions for your modules and call them from VRED (hotkeys, Qt GUI, singals, VarSets, ...).
2.
Unfortunately I'm struggling to change the plugin icon as well. Before the Qt UI update from PySide2 to PySide6 I was able to change the icon just like that:
appIconFilePath = os.path.join(os.path.dirname(__file__), "icon.base64.txt")
with open(appIconFilePath, "r") as appiconfile:
appIcon = appiconfile.read()
# set QtWidget's objectName for easier debugging (empty string by default)
VREDPLUGINWIDGET.setObjectName(f"{appName}")
# manipulate parent elements
dockWidget = VREDPLUGINWIDGET.parent()
mainWindow = dockWidget.parent()
# set name in VRED main menu entry underneath 'Scripts'
dockWidget.setWindowTitle(f"{appName} - version [{appVersion}]")
# add icon from base 64 string that contains the logo
pixmap = QPixmap()
pixmap.loadFromData(QByteArray.fromBase64(str.encode(appIcon)))
dockTitleBarWidgetFrameLabelIcon = QIcon(pixmap)
# dockTitleBarWidgetFrameLabelIcon.setMask(pixmap.mask())
dockWidget.setWindowIcon(dockTitleBarWidgetFrameLabelIcon)
That solution does not work anymore!
I thought I knew a lot about how to manipulate VRED's Qt interfaces, but I didn't come up with a solution. Sadly, not even a hacky solution worked.
Kind regards
Clemens