Adding a context menu item to Scene tab context menu

I would like to make some plugin which would be accessed only by right click on scene tab…

 UI.add_context_menu_handler {|menu| ... }

seems to work only in the model area right click…
Is it possible to add_item to Scene tab context menu?
As well I was trying to at least add_item to Draw/Animations submenu but as both

anim ='View')
anim2 ='View/Animations')

Return two different objects the'View/Animations').add_item(cmd)

will always add this item in “View” never in Animations submenu
and mysteriously this


didn’t work… only when I write it in a single line. I mean it worked and returned Menu object but nothing changed in menus…
I have at home only 2017 make … couldnt try yet on newer…

This is not exposed to the Ruby API.

The submenu is “Animation” not “Animations”. Most native submenus are not exposed to the Ruby API. Only the context menu on the Edit main menu is exposed via #add_context_menu_handler.

It does not matter if the arguments are the same … ie, each time you call'View') the API will return a different Ruby object reference. This has been a long standing complaint.

The fact that a “View/Animation” argument returns a reference to the “View” menu I would consider a bug.

And again, the name of the native submenu is “Animation” singular.

The references to the menu objects on Windows are transitory. (Ie, they do not last beyond a file or a method scope and quickly get garbage collected.)

If you wanted to add a submenu to the “View” menu at the console you must do it all in one command."View").add_submenu("Animations").add_item("Spin Model") { TJDrgas::ModelSpinner.go() }

But then you will not be able to get another reference to that same submenu. (It’s an API quirk.)

Instead you need to do this in a method and add all your commands at the same time inside the method. And this is usually done within a file loaded at startup. (Properly namespaced of course.)

1 Like

Thanks @DanRathbun … So another bag discovered I… hh though rather helpful. It makes command more resistant so some misspelling.

I could literally swear that I wrote “Animation” and then added “s” cos I’ve seen it in sKetchup menu… strange things happen when You are trying to do something clever at 4 am…
I thought

I didn’t notice that difference working in the console… I thought garbage collector does its work after You close the program… not method…
Most helpful as always … thanks once more…

Ruby garbage collection occurs whenever the interpreter determines there are enough “dead” objects to justify the impact. It happens frequently to avoid having an enormous hit if a lot is done all at once.

1 Like

I wouldn’t recommend adding anything to the View or Animation menu. It’s not the place a user will go looking for a command of an extension they’ve installed. While I can see the benefit of a scene context menu, for now I think Extensions > {extension name} is by far the best option.

1 Like

thats where its going. This is one for adding a set of scenes with specific names… someone asked me if I know a plugin which could load predefined scenes so they can be used for his layout template… I suggested a sKetchhup template but am doing it cos I had this ambition to do something more about plugins and something easy is good place to go… hh …
This is why I was thinking to add an extra context menu item on scene tab or View/Animation next to ‘Add Scene’ … but since thats not possible… goes as usual.