Created
January 30, 2019 00:23
-
-
Save pgolay/a8b4fdafcad021920671f17bf682056c 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 | |
import math | |
def SetArcRadians(): | |
pi = math.pi | |
def arc_filter( rhino_object, geometry, component_index): | |
return geometry.IsArc() | |
looped = False | |
while True: | |
angRad = 1 | |
if sc.sticky.has_key('ARC_EX_ANGLE_radians'): | |
angRad = sc.sticky['ARC_EX_ANGLE_radians'] | |
go = Rhino.Input.Custom.GetObject() | |
strMessage = "Pick the flip of the arc to move." | |
if looped: strMessage = "Pick the flip of the arc to move. Press enter to finish." | |
go.SetCommandPrompt(strMessage) | |
go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve | |
go.SetCustomGeometryFilter(arc_filter) | |
opAngRad = Rhino.Input.Custom.OptionDouble(angRad) | |
go.AddOptionDouble("AngleRadians", opAngRad) | |
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: | |
angRad = opAngRad.CurrentValue | |
if angRad > 2*pi or angRad == 0: continue | |
sc.sticky['ARC_EX_ANGLE_radians'] = angRad | |
continue | |
if rc == Rhino.Input.GetResult.Number: | |
angRad = go.Number() | |
if angRad > 2*pi or angRad == 0: continue | |
sc.sticky['ARC_EX_ANGLE_radians'] = angRad | |
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 | |
rads = abs(angRad) | |
if flip: | |
#print 'flip' | |
if angRad > 0: | |
sweep = Rhino.Geometry.Interval(crntSweep.Max - rads, crntSweep.Max) | |
else: | |
sweep = Rhino.Geometry.Interval( crntSweep.Max , crntSweep.Max + rads) | |
else: | |
#print 'start' | |
if angRad > 0: | |
sweep = Rhino.Geometry.Interval(crntSweep.Max - rads, crntSweep.Max ) | |
else: | |
sweep = Rhino.Geometry.Interval(crntSweep.Max, crntSweep.Max+ rads ) | |
flip = True | |
arc.AngleDomain = sweep | |
if flip: arc.Reverse() | |
if arc.IsValid: | |
arcCrv = Rhino.Geometry.ArcCurve(arc) | |
sc.doc.Objects.Replace(objref, arcCrv) | |
print "Arc angle set to " + str(round(angRad, 3)) | |
looped = True | |
sc.doc.Views.Redraw() | |
continue | |
if __name__ == '__main__':SetArcRadians() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment