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
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.
"""
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)