Created
January 30, 2019 00:22
-
-
Save pgolay/4259d7f84d85aa7baca9803e9be838f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import rhinoscriptsyntax as rs | |
import scriptcontext as sc | |
import Rhino | |
def SetArcLength(): | |
def arc_filter( rhino_object, geometry, component_index): | |
return geometry.IsArc() | |
looped = False | |
while True: | |
length = 1 | |
if sc.sticky.has_key('ARC_EX_LENGTH'): | |
length = sc.sticky['ARC_EX_LENGTH'] | |
go = Rhino.Input.Custom.GetObject() | |
strMessage = "Pick the end of the arc to move." | |
if looped: strMessage = "Pick the end of the arc to move. Press enter to finish." | |
go.SetCommandPrompt(strMessage) | |
go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve | |
go.SetCustomGeometryFilter(arc_filter) | |
opLen = Rhino.Input.Custom.OptionDouble(length) | |
go.AddOptionDouble("Length", opLen) | |
go.AcceptNumber(True, False) | |
go.EnablePreSelect(False, True) | |
rc = go.Get() | |
if go.CommandResult() != Rhino.Commands.Result.Success: | |
return go.CommandResult() | |
if rc == Rhino.Input.GetResult.Option: | |
length = opLen.CurrentValue | |
sc.sticky['ARC_EX_LENGTH'] = length | |
continue | |
if rc == Rhino.Input.GetResult.Number: | |
length = go.Number() | |
sc.sticky['ARC_EX_LENGTH'] = length | |
continue | |
if rc == Rhino.Input.GetResult.Object: | |
objref = go.Object(0) | |
geo = objref.Geometry() | |
selPt = objref.SelectionPoint() | |
p_rc, par = geo.ClosestPoint(selPt) | |
flip = False | |
if p_rc: | |
if par>= geo.Domain.Mid: | |
flip = True | |
print geo.Reverse() | |
a_rc, arc = geo.TryGetArc() | |
crntSweep = arc.AngleDomain | |
radius = arc.Radius | |
x = abs(length)/radius | |
if flip: | |
if length > 0: | |
sweep = Rhino.Geometry.Interval(-x, 0) | |
else: | |
sweep = Rhino.Geometry.Interval( crntSweep.Max , crntSweep.Max+x) | |
flip = False | |
else: | |
if length > 0: | |
sweep = Rhino.Geometry.Interval(crntSweep.Max-x, crntSweep.Max) | |
else: | |
sweep = Rhino.Geometry.Interval(crntSweep.Max, crntSweep.Max+x) | |
flip =True | |
arc.AngleDomain = sweep | |
if flip: | |
arc.Reverse() | |
arcCrv = Rhino.Geometry.ArcCurve(arc) | |
sc.doc.Objects.Replace(objref, arcCrv) | |
print "Arc length set to " + str(round(length, 3)) | |
looped = True | |
sc.doc.Views.Redraw() | |
continue | |
if __name__ == '__main__':SetArcLength() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment