Hello all!
I am currently writing a code to collect objects (walls,columns etc.) and I would like to be able to project their geometry into dynamo.
From what I saw, the option method is needed but I don’t really understand it - any suggestions?
import clr
import sys
import System
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
#import Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
#import transactionManager and DocumentManager (RevitServices is specific to Dynamo)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
from System.Collections.Generic import List
outGeoDS = []
#collect all Walls and
cat_list = [BuiltInCategory.OST_Walls, BuiltInCategory.OST_StructuralFraming]
typed_list = List[BuiltInCategory](cat_list)
filtercat = ElementMulticategoryFilter(typed_list)
fecWall_Struct = FilteredElementCollector(doc).WherePasses(filtercat).WhereElementIsNotElementType().ToElements()
#create an instance of Geometry Option
opt = Options()
#set some properties of this instace
opt.ComputeReferences = False
opt.DetailLevel = ViewDetailLevel.Medium
opt.IncludeNonVisibleObjects = True
#get geometry of each element with this option
for e in fecWall_Struct:
geo_set = e.get_Geometry(opt)
for geo in geo_set:
if isinstance(geo, Solid):
#convert to Dynamo Geometry
geoDS_set = geo.ToProtoType()
if geoDS_set is not None:
outGeoDS.append(geoDS_set)
#if it's a familyInstance
elif isinstance(geo, GeometryInstance):
for geoI in geo.GetInstanceGeometry():
if isinstance(geoI, Solid):
#convert to Dynamo Geometry
geoDS_set = geoI.ToProtoType()
if geoDS_set is not None:
outGeoDS.append(geoDS_set)
#release DB Geometry resources
geoI.Dispose()
else: pass
#release DB Geometry resources
geo.Dispose()
#release DB Geometry resources
geo_set.Dispose()
OUT = outGeoDS
.
#list of Import
#....
#...
outGeoDS = []
#collect all Walls and
cat_list = [BuiltInCategory.OST_Walls, BuiltInCategory.OST_StructuralFraming]
typed_list = List[BuiltInCategory](cat_list)
filtercat = ElementMulticategoryFilter(typed_list)
fecWall_Struct = FilteredElementCollector(doc).WherePasses(filtercat).WhereElementIsNotElementType().ToElements()
#get geometry of each element with this option
for e in fecWall_Struct:
refElem = Reference(e)
geo_set = e.GetGeometryObjectFromReference(refElem)
for geo in geo_set:
if isinstance(geo, Solid):
#convert to Dynamo Geometry
geoDS_set = geo.ToProtoType()
if geoDS_set is not None:
outGeoDS.append(geoDS_set)
#if it's a familyInstance
elif isinstance(geo, GeometryInstance):
for geoI in geo.GetInstanceGeometry():
if isinstance(geoI, Solid):
#convert to Dynamo Geometry
geoDS_set = geoI.ToProtoType()
if geoDS_set is not None:
outGeoDS.append(geoDS_set)
#release DB Geometry resources
geoI.Dispose()
else: pass
#release DB Geometry resources
geo.Dispose()
#release DB Geometry resources
geo_set.Dispose()
OUT = outGeoDS
Any chance that you direct me to which classes and methods to look at through the Revit API? That would help me get more familiar with it.
Not a biggie if not.
Thanks
In your first example wrote the line of code geo_set = e.get_Geometry(opt) - implying that the Wall Element has a method of get_Geometry() which I cannot find, at least not in the Wall Class - did I not understand it correctly or is it a method from a different class?
Now lets say that you extracted the geometry - now you apply the ToProtoType() method in order to make it dynamo owned (or the equivalent to Unwrapping)? Would it not show the geometry if not put through the ToPrototype() method?
the get_ prefix refers to a getter accessor (Property).
A property getter function is generated when a property takes an argument (.NET implementation)
Alternatively you can write this (same result) geo_set = e.Geometry[opt]