Toggle toolbar visibility without knowing its parent "collection"

Right now, to toggle a toolbar’s visibility, we need to know to which “collection” it belongs:

! _-Toolbar _Toolbar "CollectionName" _Toggle "ToolbarName" _Yes !

It would be really nice to be able to have the option to have the “current” toolbar collection as an option:

! _-Toolbar _Toolbar Collection=Current _Toggle "ToolbarName" _Yes !

or perhaps that it looks in all the available collections and opens the first one it finds with a matching name…

! _-Toolbar _Toolbar _Toggle "ToolbarName" _Yes !

The reason I want this is that if the main collection name changes, the macros based on the original name will fail.

Trying to simulate the second option with the following python/rhinoscriptsyntax currently errors out - there is a bug in toolbar.py (will put details in another post)

OK, figured out the error, need to assign True for the optional third argument in IsToolbar(). My bad.

import rhinoscriptsyntax as rs

def ToggleToolbarVisibility(tb_name):
    for tb_coll in rs.ToolbarCollectionNames():
        if rs.IsToolbar(tb_coll,tb_name,True):  #<--Fixed by adding third argument
            if rs.IsToolbarVisible(tb_coll,tb_name):
                rs.HideToolbar(tb_coll,tb_name)
            else:
                rs.ShowToolbar(tb_coll,tb_name)
            break
ToggleToolbarVisibility("ToolbarName")

–Mitch

1 Like

Hi Mitch - for the first option, what do you mean by ‘current’?

-Pascal

The one that’s highlighted here…

But that reminds me the one that actually gets highlighted is also a mystery sometimes, maybe we should have a “current” checkmark or something…?

It obviously becomes easier if you only have one ws file open…

– Mitch

Hi Mitch - the problem, I think, is that there is no file that is any more current than any other - as far as I know. If you have four files open, they are all open, I don’t think there is any priority as far as Rhino is concerned. I have this feeling I am missing or forgetting something …

-Pascal

Hey Pascal,

OK, well, if there isn’t a “current” ws file and the highlight has no real function, then I still would like the second option to work - as per my script - opens the first file it finds by that name in all the open collections.

Thanks, --Mitch

Hi Mitch - the highlight in the Options page is so Rhino knows what file you care about if you use File > Save As or Edit > New Group, etc. Does that make sense with what you’re asking about?

-Pascal