ScriptPlugin Questions: 1. Shared Namespace, 2. Plugin Icon

ScriptPlugin Questions: 1. Shared Namespace, 2. Plugin Icon

fbruchD4CS2
Contributor Contributor
1,568 Views
8 Replies
Message 1 of 9

ScriptPlugin Questions: 1. Shared Namespace, 2. Plugin Icon

fbruchD4CS2
Contributor
Contributor

Hi All, 

 

I have two questions regarding VRED ScriptPlugin development: 

 

  1. Is there a way to communicate between two separate ScriptPlugins / a ScriptPlugin and the main application? I'd like to develop a Plugin for dynamically mapping actions to a joystick, some of which are meant to be custom actions of another ScriptPlugin. For this, I need a way to store the mappable actions from the second Plugin in some global variable that I can access from the first Plugin, but it seems that the ScriptPlugins work in an enclosed namespace. 
  2. Is there a way to modify a ScriptPlugin's icon? I try to mimic the aesthetic's of VRED's modules as best as I can for coherence, and I couldn't figure out so far how to turn the M into an actual icon. Especially for pinning multiple ScriptPlugins to the bottom toolbar, it'd be great if they all had descriptive icons, instead of a bunch of Ms next to each other. Script Plugin Icon.png 

Thank you very much in advance! 

 

- Florian Bruch 

0 Likes
Accepted solutions (2)
1,569 Views
8 Replies
Replies (8)
Message 2 of 9

clemens_schlicker_audi
Enthusiast
Enthusiast
Accepted solution

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

0 Likes
Message 3 of 9

sinje_thiedemann
Autodesk
Autodesk
Accepted solution

Hi, in VRED 2025 you can set the window icon in the constructor of the script plugin, see the attached example file.

 

self.parent.setWindowTitle("My custom SimpleExample title")
self.parent.setWindowIcon(icon)

 

There is an internal mechanism that will forward this to the dock widget.

Message 4 of 9

fbruchD4CS2
Contributor
Contributor

Hi Clemens, 

 

This is fantastic, thank you so much! Your solution for my first question is exactly what I was hoping and looking for. Having hidden folders and python files within the ScriptPlugins folder is also a very helpful tip and something I hadn't thought of, which will also help me a lot with my plugin development. Thank you for the heads up about using start and cleanup functions as well, I'll make sure to look into that. 

 

 

Kind regards, 

Florian 

Message 5 of 9

fbruchD4CS2
Contributor
Contributor

Hi Sinje, 

 

I was still developing in VRED 2024, I can confirm that your solution works for VRED 2025! Just one thing though, changing the Window Title seems to interfere with the functionality of pinning the module to the bottom toolbar. I can only pin the Simple Example to the toolbar if I comment out the line where the window title is changed. Still, your answer helped me a lot, thank you!

 

Kind regards, 

Florian 

0 Likes
Message 6 of 9

ir
Advocate
Advocate

Hello Sinje, 

 

The solution you suggest with "self.parent.setWindowTitle" only seams to update at launch-time of VRED - correct?

I.e., there is still no way of setting the plugin window title at run-time of VRED (which was possible before Release of 2024)?

I did discuss this request with Marcus back then and he promised to log the request. Any progress on this? 

Our use case: We load a database in to our plugin and then the user should see the loaded database file name in the plug-in window title just like the vpb file name shown in the main window title. This worked perfectly fine with VRED 2023.

 

Thanks. Ingolf 

Message 7 of 9

sinje_thiedemann
Autodesk
Autodesk

Hi @fbruchD4CS2

for 2024.2 I found this snippet (untested):

moduleWidget = self.parent.parentWidget().parentWidget().parentWidget()
moduleWidget.setWindowTitle("My custom SimpleExample title")

 

Pin to quick access bar: That worked for me in 2025.1, though the name displayed below the icon is not customizable. Ah, I see the "pin" toggle button next in the menu action in the Scripts menu does not work, I used the menu on the module icon:

sinje_thiedemann_0-1741006305131.png

 

Hi @ir 

The self.parent.setWindowTitle in 2025 was the solution that was implemented after your request. But I can confirm that it only works reliably at launch-time.  I created a ticket to fully support changing it dynamically. I found the title can be changed after VRED has started but this also somehow sets the icon to a VRED logo; and after using Reload Script Plugins the setWindowTitle has no effect any more.

 

0 Likes
Message 8 of 9

ir
Advocate
Advocate

Hello Sinje,

Thanks so much for creating a ticket to fully support changing the window title dynamically! Would be fantastic if you could share the solution here when implemented. Take care!

Ingolf 

0 Likes
Message 9 of 9

altarfinch
Explorer
Explorer

Hi, thanks for the solutions, it's very helpful.


Did any of you found a way to add the widget to quick access bar from script ?
Or to dock it in a native way ?

It's possible to do it in a hacky way using Qt but then it's not really recognized by VRED (the look is weird and do not react so well)

Paul

EDIT: I found out we can save the workspace so I think it's the intended way
Now the final thing missing to have it behave like an official module of VRED would be to have the icon going orange when the tab is open, any clue ?

0 Likes