Show geometry of collected walls

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?

Thanks!

1 Like

Hello @zvith
“Option” is a parameter to get geometry from an element (Revit API)
https://www.revitapidocs.com/2020/d8a55a5b-2a69-d5ab-3e1f-6cf1ee43c8ec.htm

https://www.revitapidocs.com/2020/aa41fc13-9f81-836c-4271-82568ba5d7e8.htm

1 Like

Any suggestion of how to write a code that will project the geometry in dynamo of elements collected (once collected)?

1 Like

there are some examples in Dynamo forum.
you can use the forum search engine

[link search](Search results for 'get_Geometry( tags:python)' - Dynamo

1 Like

I searched through the forum but didn’t find anything - that’s why I posted…

1 Like

Did you try Element.Geometry?

1 Like

@zvith

an example with Walls and Structurals Framing

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	

another example without geometry Options

.
#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
7 Likes

Thanks but I am trying to learn the API at the python level so that doesn’t help me much…

1 Like

Thanks alot it looks good!
I’ll try to go over it and figure it out.

1 Like

@zvith
in parallel with Revit API it is necessary to read this

1 Like

:+1:

1 Like

This is pure awesomness Cyril! :partying_face:

2 Likes

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

1 Like

Hello
you can find information in this guide, see page 200 and more

3 Likes

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?

1 Like

Hello

  • the get_ prefix refers to a getter accessor (Property).
    A property getter function is generated when a property takes an argument (.NET implementation)
    image
    Alternatively you can write this (same result)
    geo_set = e.Geometry[opt]

  • ToProtoType() method is “Dynamo Method”
    read this link Python 0.6.3 to 0.7.x Migration · DynamoDS/Dynamo Wiki · GitHub

1 Like

Thnx for the quick respond!

1 Like

Noticed this guide only now. Thanks!