-
Notifications
You must be signed in to change notification settings - Fork 335
/
Copy pathSampleGetArc.py
71 lines (54 loc) · 2.24 KB
/
SampleGetArc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
################################################################################
# SampleGetArc.py
# Copyright (c) 2017 Robert McNeel & Associates.
# See License.md in the root of this repository for details.
################################################################################
import Rhino
import scriptcontext as sc
# Rhino.Input.Custom.GetObject derived class that limits picking to arcs.
class SampleGetArcCurveObject(Rhino.Input.Custom.GetObject):
# GetObject.CustomGeometryFilter override
def CustomGeometryFilter(self, rh_object, geometry, component_index):
if not geometry:
return False
if not isinstance(geometry, Rhino.Geometry.Curve):
return False
arc = self.GetArcDefinition(geometry)
if arc is None:
return False
return True
# Retrieves the arc definition from a curve
def GetArcDefinition(self, curve):
if curve is None:
return None
# Is arc curve?
if isinstance(curve, Rhino.Geometry.ArcCurve):
if not curve.IsCompleteCircle:
return curve.Arc
# Is NURBS curve with arc form?
if isinstance(curve, Rhino.Geometry.NurbsCurve):
rc, arc = curve.TryGetArc()
if not arc is None and not arc.IsCircle:
return arc
return None
# Sample that tests the GetArcCurveObject class
def SampleGetArc():
go = SampleGetArcCurveObject()
go.SetCommandPrompt('Select arc')
go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve
go.Get()
if go.CommandResult() <> Rhino.Commands.Result.Success:
return go.CommandResult()
curve = go.Object(0).Curve()
if curve is None:
return Rhino.Commands.Result.Failure
arc = go.GetArcDefinition(curve)
if not arc is None:
sc.doc.Objects.AddArc(arc)
sc.doc.Views.Redraw()
return Rhino.Commands.Result.Success
# Check to see if this file is being executed as the "main" python
# script instead of being used as a module by some other python script
# This allows us to use the module which ever way we want.
if __name__ == "__main__":
SampleGetArc()