Create and update toolbar buttons through RhinoPython or Macro

Hi everyone,

I’ve been developing a bunch of python scripts for my research project. Since I am constantly adding/renaming scripts from the list, I used a git folder to sync the project with my fellows. The folder path is then added to the python search path. I also created a startup script to go through the list every time and let the user select which tool (ie. script) to run, so that they don’t need to reinstall the toolbox frequently.

And now, we’ve reached a point that we have quite a long list to use. Even though we’ve categorized them, it still takes long to find each one. Therefore, we want to use a python script to automatically create icons/buttons to a toolbar, so that the toolbar can get updates as we removing or adding new scripts to the folder.

I am not software developer by trade and I don’t want to rewrite all the scripts in other languages. I am also aware of the Rhino plugin with python, but it simply doesn’t fit our workflow. It seems that there is not much I can do with Rhino.UI.Toolbar. Any suggestion to the workflow or sample codes are greatly appreciated!

Best regards,
Vincent

P.S: I am thinking about writing the .rui file directly. The .rui is an xml file at its core. Is there any documentation I can refer to? Many thanks!

Maybe a searchable eto form would help you achieve your goal?

Have a look at this topic:

@lando.schumpich Awesome! Great to see that someone had the same idea. Will definitely implement it for our project. But a toolbar is still desired, since there are commands we use quite frequently and a toolbar will save many clicks. :grinning:

I don’t think the tools for creating toolbar buttons and adding them to an existing toolbar are currently exposed anywhere accessible like RhinoCommon.

One thing you might be able to do is have the admin responsible for keeping the scripts etc. up to date manage your custom toolbar file, which can sit on a server somewhere on your network. Individual workstations can load this toolbar file when Rhino is opened. As this toolbar is freshly loaded each time Rhino starts, it should always be up to date - at the worst, someone would need to manually reload it if changes are made during a session.

As Rhino is set up to automatically overwrite toolbar files when it closes, you do not want that, so the toolbar file on the server should also be made read-only.

I have more than 100 scripts that I access occasionally, dozens that I use frequently, for me toolbars are too unwieldy for this, so I work uniquely with aliases now. Aliases are much easier to maintain, as all it takes is importing a text file. The command alias list is exposed in RhinoCommon, so I think automatic updates should be possible via a script.

2 Likes

Hi @Helvetosaur . I didn’t know that the CommandAliasList existed. It is a good solution indeed. I use a unique alias prefix for all the scripts. Now I can remove and add all of them via a script. It is a lot easier. Thank you!

Finally I was able to automatically create a toolbar via a script. The script is able to write a rui file directly. You will need to do the followings:

  1. create 24bit png file with the same name as your script. (script will be skipped if no png file found)
  2. use PIL to combine png files into one
  3. use base64 to convert the merged image into strings
  4. use xml.etree.ElementTree or other libs to write a rui file
  5. note: you will need System.Guid.NewGuid() (ironpython) or uuid.uuid4() (plain python) to create GUID for each element. I haven’t try the later, but ideally you can do all the above outside Rhino with plain python. (since it is difficult to install PIL for ironpython)

It is quite a tedious process. But it works fine for now…

1 Like