-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathselSrfbyArea.py
More file actions
33 lines (31 loc) · 1.08 KB
/
selSrfbyArea.py
File metadata and controls
33 lines (31 loc) · 1.08 KB
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
import Rhino
#Get a reference to the document
doc = Rhino.RhinoDoc.ActiveDoc
#Get all the objects in the document
objects = doc.Objects
#Get all the selected objects
selectedObjects = [o for o in doc.Objects.GetSelectedObjects(False,False)]
#try to get the first selected item, if it fails print a message to the command line
try:
firstSelected = selectedObjects[0]
objects.UnselectAll()
except:
print "Select an object and re-run command"
#get the area of the first selected item
try:
targetArea = Rhino.Geometry.AreaMassProperties.Compute(firstSelected.Geometry).Area
except:
"Unable to measure object area"
#set up a list to hold all the items we want to select
toSelect = []
#for every item in the rhino document, try to get its area and compare it to the target area
for rhObj in objects:
try:
area = Rhino.Geometry.AreaMassProperties.Compute(rhObj.Geometry).Area
if abs(targetArea - area ) < 0.01:
toSelect.append(rhObj)
except:
pass
#for each item in the "to select" list, select it
for item in toSelect:
objects.Select(item.Id)