-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgh_import.py
More file actions
executable file
·29 lines (25 loc) · 986 Bytes
/
gh_import.py
File metadata and controls
executable file
·29 lines (25 loc) · 986 Bytes
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
import Rhino
# for accesssing GH classes
import clr
clr.AddReference("Grasshopper")
from Grasshopper.Kernel.Data import GH_Path
from Grasshopper import DataTree
# read geometry out of 3dm files and filter by layernames
if DoImport and FilePaths and LayerNames:
layerTree = DataTree[Rhino.Geometry.GeometryBase]() # make a DataTree
for filepath in FilePaths:
model = Rhino.FileIO.File3dm.Read(filepath)
if not model: continue
for i, layer in enumerate(LayerNames):
path = GH_Path(i)
geometry = []
objs = model.Objects.FindByLayer(layer)
for obj in objs:
geom = obj.Geometry
geom.EnsurePrivateCopy()
geometry.append(geom)
layerTree.AddRange(geometry, path)
# models can take up a considerable amount of
# memory that we don't need, so get rid of it
# after copying the geometry we want out of it
model.Dispose()