-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathSmart.py
More file actions
51 lines (41 loc) · 1.7 KB
/
Smart.py
File metadata and controls
51 lines (41 loc) · 1.7 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
'''A module for wrapping geometry with UserString and Attribute Dictionaries'''
import Rhino
class SmartFeature(object):
def __init__(self, rhinoObjectOrTuple):
self._parseConstructor(rhinoObjectOrTuple)
def _parseConstructor(self, rhinoObjectOrTuple):
# determine if it is a tuple
kind = type(rhinoObjectOrTuple)
if kind == tuple or kind == list:
# build from geom, user string pair
pair = rhinoObjectOrTuple
self.geom = self._filterGeometry(pair[0]) # geometry
self.attributes = pair[1] # properties (as dictionary)
else: # assume RhinoObject
rhObj = rhinoObjectOrTuple
self.geom = self._filterGeom(rhObj.Geometry)
self.attributes = {}
numAtts = rhObj.Attributes.UserStringCount
rawAtts = rhObj.Attributes.GetUserStrings()
keys = rawAtts.AllKeys
for key in keys:
self.attributes[key] = rhObj.Attributes.GetUserString(key)
def _filterGeom(self, geometry):
if type(geometry) == Rhino.Geometry.Point:
return geometry.Location
else:
return geometry
def objAttributes(self, objectAttributes):
for key in self.attributes:
objectAttributes.SetUserString(key, self.attributes[key])
return objectAttributes
def RhinoObjectsToSmartFeatures(RhinoObjectList):
return [SmartFeature(obj) for obj in RhinoObjectList]
def replaceGeometries(smartFeatures, geometries):
out = []
for i in range(len(smartFeatures)):
feature = smartFeatures[i]
geometry = geometries[i]
feature.geom = geometry
out.append(feature)
return out