Template script for Toggle RhinoCommands

Hi there,
I am totally new to Rhino (and new to scripting),
but I learned from googleing, that I cant use macros to toggle between to functions in Rhino…

For example, I would like to toggle “_PointsOn” and “_PointsOff” with a single Button/Key.
Or “Layer" and "-Layer _Visible=_No _Enter”

Actually I want to have many different Toggles, therefore I would like to write a template script where I simply paste the needed RhinoCommands.

Can this be done using rhinoscript/ python? Any suggestions?

Thanks jj

There are commands that ARE toggles, or have toggle command-line options, they can be macro’d easily enough. Trying to make your own toggles where they don’t exist could I suppose be done using Python to save the state between running the command, but it might be a bit tricky and I wouldn’t frankly recommend, for example, using a single button for points on/off, that doesn’t sound useful.

If you’re totally new to Rhino take the time to learn how it works out of the box before spending a bunch of time scripting (and learning how to script) to try to make it work differently.

In addition to Jim’s comment, you might want to take a look at Options->Rhino Options->Keyboard. It will show you the current keyboard shortcuts and associated Command Macro.
There are also Aliases that can be set as well. Options->Rhino Options->Aliases.

For example, keyboard shortcuts F10 and F11 are, (by default), set to ! _PointsOn and ! _PointsOff

You can set keyboard shortcuts/custom buttons/Aliases to run macros. Those macros may call rhino commands or script files. For example, to call a python script, it would look something like this:

!-RunPythonScript "D:\RhinoPyScripts\msgBox.py"

To reiterate Jim’s comment, you may find that the functionality you are looking for is already built in. Explore the various tabs/toolbars. The Layer toolbar has various tools for hiding/showing layers. Including OneLayerOff and OneLayerOn.

Here is some additional information on Macros:

Thanks for the answers so far,
but I really need a solution for the toggles- maybe using python…
I am new to rhino and its interface, but i am not new to 3d modelling-
I use Alias and Modo/Blender -and until now I use rhino only to run grasshopper.
Which is a waste, so I would like to use rhino more!
In Modo and Blender I can easily customise the interface and hotkeys and so on to mimic my Alias workflows- which helps a lot when jumping inbetween modelling packages-
I would like to do that as well in rhino!
I found this nice little script online

Which I really like and use, and I want to have more like it- prefered as a template that can quickly be customised…

Could that be done?

Sorry, this is the right link…

Assign this to a function key to toggle the Layer dialog visibility:

_NoEcho _-Layer _Visible _Toggle _Enter

For other commands which do not provide toggles, consider @JimCarruthers advice which is a good one. Note that _PointsOn does requires a selection while _PointsOff does not and works on all objects.


Thanks Clement!
This works exactly like I hoped :slight_smile:
But is a flexible Template solution really so hard achiev?
In theory it just a simple “or” command right?

For commands that have toggles, it’s easy, for those that don’t, no it’s not so easy, it has to keep track of the state of the command between uses so you need code to do that, and for some things that can get a bit complicated.

Again though, what are you actually hoping to toggle? Why are you wanting to toggle everything? A toggle for points on and off makes no sense in terms of how Rhino is used. They’re not actually generally a great idea to just use everywhere, UI-wise.