WISH: Capture output of Rhino.RhinoApp.RunScript() to string

Named Selections were introduced in R7, and there seems to be no progress with providing programmatic access through RS or RC. This was promised for R8, but now might make it (with a bit of luck) into R9.

For any feature that can be called via the Rhino command line (rs.Command() or Rhino.RhinoApp.RunScript()), would it be possible to capture the output of the Rhino command to a string?

The rationale is that I’m a big fan of Named Selections, and need to at least know the names of the Named Selections that the user has defined:

-_NamedSelections > List

The requested feature would not only enable me to do this whilst awaiting proper RS/RC access, but would also provide access to any/all features that have a cmd line interface (i.e. all native Rhino commands, as well as all commands provided by plug-ins)

How the string is dealt with, how it is parsed and whether or not the cmd line output makes sense would obviously be up to the programmer capturing the output.

Thank you for considering this.

Axel

Hi @axa,

Perhaps this?

https://developer.rhino3d.com/api/rhinocommon/rhino.rhinoapp/capturedcommandwindowstrings

– Dale

Hi @dale ,

yes, this is exactly what I was looking for. Thanks for pointing this out. Here is a Python function, in case anyone else is trying to do this:

def listNamedSelections():
    Rhino.RhinoApp.CommandWindowCaptureEnabled = True
    Rhino.RhinoApp.CapturedCommandWindowStrings(clearBuffer=True)

    cmd = ‘-_NamedSelections _List’
    success = Rhino.RhinoApp.RunScript(cmd, echo=False)
    strs = Rhino.RhinoApp.CapturedCommandWindowStrings(clearBuffer=True)
    Rhino.RhinoApp.CommandWindowCaptureEnabled = False

    named_selections = [i.rstrip() for i in strs]

    return named_selections

Thanks again

Axel

2 Likes