Button command scripting documentation?

I don’t know the words for what to search for here, but where can I find documentation for what can go into a button?

Like _Enter and _Pause for example.

Plus, some people write a dash (-), or an exclamation mark (!) or an apostrophe (’) before commands and I’m guessing these do different things, but what?

I’m also curious to know, if you put for example SelCaptives in a button, is there some way to check if anything actually got selected?

Finally, if you put a lot of commands in a button, is there any way to group them so that an Undo works to undo everything in that button, instead of having to step through each part?

The doc can be found here…

Hey

These macros (that’s what they are usually called) simply allow you to set a sequence of Rhino commandline commands to a single button. These commands are executed as if they were typed in the command prompt.
All available (standard) rhino commands can be found here and the accompanying documentation here.

If anything is selected the command prompt usually tells you how many objects and of which type.

~robin

What I mean with this was more like, are branching macros possible?

But it seems you can embed a different type of script if you do RunScript as I saw in this thread.

No, conditionals and branching are only possible with scripts.

Hello,

Your options are Rhinoscript, python or c#

Python is generally considered easier to learn, more powerful than Rhinoscript, widely applicable in other situations :snake:

I started with the Rhino Python 101 and never looked back :smiley:

Undo will undo the whole button action at once

So, can you type Python script straight into a button, without referencing a .py file?

The documentation for that is probably vast, so do you know of a tutorial anywhere for doing simple things like checking what is currently selected, and then executing a command, for example?

Yes but it is much easier to type _EditPythonScript, write your file, save it and then put RunPythonScript + Filename in a button to run your script. The editor is limited but has some integrated help and autocomplete. You can copy your script into a button once you are happy with it, if you like.

Vast, well paced, readable. It is worth the effort to read it and things which seem like distractions from getting things done are actually there to help you learn the essentials more quickly.

No but here is a simple sample, for example:

import rhinoscriptsyntax as rs

my_objects = rs.SelectedObjects()
rs.UnselectAllObjects()

for object in my_objects:
    if rs.IsText(object):
        rs.SelectObject(object)
        rs.Command('_Delete')
    else:
        print("not text")
1 Like

Great, thank you!

And you enclose that in

'_NoEcho -_Runscript ( )

it seems (if you don’t want a .py file).

Yes, no problem, I have a bunch that run that way. Bit difficult to edit if you need to though.

should be _NoEcho -_RunPythonScript ( ) I think

Yes, to be very explicit:

_NoEcho ! -_RunPythonScript (
<whole script in here>
 )

The ! cancels any running command before running the script. The _NoEcho goes in front of the ! otherwise you will also see NoEcho printed to the command line every time.

2 Likes

Thank you both!