API usage of "get_Geometry" command to retrieve element geometry

Hi everyone,
A bit of a noob question, but I realy have to figure this one out:
When I get the geometry of an element, I have to use the “get_Geometry(options)” syntax. (The same goes for bounding boxes). Why is that? What is the rule of thumb for applying the “get_” command and what does the “options” parameter mean?
Also, why the geometry solids are being output as a single object list?

Thanks!

You can read about Geometry Options here.
But in one sentence: “the options class customizes the type of output you receive”.

2 Likes

Thanks!
Any idea about the other issues with retrieving geometry?

hi @ilia.s, below is a sample usage of get_Geometry method. It is collecting Solid geometry and extracting Faces data from Room elements.

# dynamo version - 1.3.4

import clr
clr.AddReference("RevitAPI");
clr.AddReference("RevitNodes")

import Autodesk, Revit;
clr.ImportExtensions(Revit.Elements);
clr.ImportExtensions(Revit.GeometryConversion);
from Autodesk.Revit.DB import *

rooms = UnwrapElement(IN[0]);
result =[];


for room in rooms:
	# geo of room
	geo = room.get_Geometry(Options())
	# get enum
	enum = geo.GetEnumerator()
	# skip one
	next = enum.MoveNext()
	# current geo
	solid = enum.Current
	# get faces
	faces = solid.Faces
	count = 0;
	sub = []
	# each face
	for face in faces:
		count +=1;
		# omit first two (top,btn)
		if count>2:
			# face to dyn obj
			sub.append(face.ToProtoType()[0])
			# curves
			#sub.append(face.GetEdgesAsCurveLoops()[0])
	result.append(sub)
OUT = result

room-surfaces

3 Likes

Similarly, you can use the Geometry property like this:

geo = room.Geometry[Options()]

I’m not sure why you can use both the method and the property…

1 Like

Thanks!

Thank you!
Could you please elaborate on the usage of enums? What exactly do hey extract?

hi, @ilia.s, get_Geometry return value is a (kind of) list but it is unsubscriptable which means you can’t use indexing syntax like geo[0] to access list’s items.

But you can use loop or list concatenation or GetEnumerator to access this return value. So, here i used Enumerator and access the list’s item Solid object.

More info about Enumerator: https://docs.microsoft.com/en-us/dotnet/api/system.collections.ienumerable.getenumerator?view=netframework-4.8

3 Likes

Awesome! Thanks.

Hello,
I tried your code, I’m learning, the Element.Solids node returns the same solid but in dynamo entity

If you have a generic list composed of several solids as in the example, is the solution adopted here “good”?

import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

Col=UnwrapElement(IN[0])
#geo of family
geo=Col.get_Geometry(Options())
#get enum
enum=geo.GetEnumerator()
#skip two
next0=enum.MoveNext()
next1=enum.MoveNext()

geo_sol1=enum.Current

#skip one
next2=enum.MoveNext()

geo_sol2=enum.Current

vol_1=geo_sol1.Volume*0.3048**3
vol_2=geo_sol2.Volume*0.3048**3

geo_dynamo=geo_sol1.ToProtoType()
OUT = Col,geo,type(geo),type(enum),geo_sol1,geo_sol2,vol_1,vol_2,geo_dynamo

thanks
Cordially
christian.stan

1 Like