Automatic 'Enter' after selection in macro?

I want to create a macro that will allows me to select an edge and have the length of the edge displayed automatically in the console.

I created something like this:

!-_Length
_Pause
_Enter

The problem it is that the macro it is expecting to pass myself an Enter at the end of the command and I want this last step to be automatic, without the need from my side to pass the Enter.

It is possible to pass automatically that Enter without my intervention at the end of the macro?

Hi Macuso -
The problem with this is that the Length command allows you to select multiple curves and that it doesn’t know when you are finished.
The only way to do this is by preselecting the curve(s), and then running that macro.
-wim

1 Like

I do use a lot this command and I would like to do it as fast as possible without the need to use both hands or too many clicks to do it.

To preselect the edge I do need to Ctrl+Shift with the left hand on the keyboard and a left mouse click which it is not ideally for me.

It is there any way to replace preselect (Ctrl+Shift) in a macro? This way I can use only a mouse click.

Would this script help any?

  • If one or more objects are preselected, reports total length of curves+edges
  • If no objects are preselected, allows selection of just one curve or edge, reports length of the curve/edge

It basically looks to see if any valid objects are preselected for Length and if so runs the normal length command. If nothing is preselected, it will allow you to select just one curve or edge and immediately will report the length.

GetLengthSpecial.py (1.0 KB)

"""
If one or more objects are preselected, reports total length of curves/edges
If no objects are preselected, allows selection of just one curve or edge,
reports length of the curve/edge.  Script by Mitch Heynick 27.11.22
"""

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

objs=rs.SelectedObjects()
if objs:
    rs.Command("_Length",False)
else:
    prec=sc.doc.ModelDistanceDisplayPrecision
    go = Rhino.Input.Custom.GetObject()
    go.SetCommandPrompt("Select curve or edge")
    go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve
    go.Get()
    if go.CommandResult() == Rhino.Commands.Result.Success:
        objref = go.Object(0)
        edge = objref.Edge()
        if edge:
            #picked object was an edge
            length=edge.GetLength()
        else:
            #picked object was a curve
            crv=rs.coercecurve(objref.ObjectId)
            length=crv.GetLength()
        print "Length = {} {}".format(round(length,prec),sc.doc.ModelUnitSystem)
1 Like

Works wonders. Thank you.