Create solid from revit to dynamo

hello there, im trying to calculate the size of a revit family instance. My approach was to first get the geometry into dynamo to research further what the size is (length/ width) I cannot depend on parameters because we have a lot of different types of families where the parameters are different. so my best gues was to get the solid from the instance.

i tried to do this, but got the following error. Does this mean that the component im trying to extract has too much detail? could anyone help me further?

Trying to get solid in dynamo…

from:

It could be the complexity of the component. There have been several threads posted in the forum of making a solid where variations of code was provided. Try searching and see if see if any of those codes will make a solid out of your element.

Hi Staylor, Thanks for the reply. I did. but most of the codes/ graphs talk about translating geometry to revit, not the other way around. Im also eager to know if there are any threads that looks like this situation.

@olivar.wasely Try Element.GeometryFast from Synthesize package. There may be some troubles with speed and consistency, if you have objects made of several solids. It doesn’t work with linked objects also. Try with one object in file, answer here. I’ve almost solved all of issues, i’ll finish this for you, if you need it.
Can you share the revit file?

Hi @Vladimir , that would be great!

Here is the revit file with one revit family instance.
NLRS_25.1_ME_FB_Kabelklem_gen_QIR-uitwisseling voor test.rvt (6.4 MB)

I tried to use the element.geometry fast. but it didnt work well (see below).


image

There are post about converting Revit geometry to a dynamo solid for getting the centroid and other various reasons, the subject line may not be clearly defined, so it takes some in depth searching.

Is this what you are wanting?

3 Likes

Cool! Could you share the Pyhon code, please?

I know I got this code from a thread, but can’t remember the thread or who created the code. Kudos to the creator.

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

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

def convert_geometry_instance(geo, elementlist):
	for g in geo:
		if str(g.GetType()) == 'Autodesk.Revit.DB.GeometryInstance':
			elementlist = convert_geometry_instance(g.GetInstanceGeometry(), elementlist)
		else:
			try: 
				if g.Volume != 0:
					elementlist.append(g)
			except:
				pass
	return elementlist

doc = DocumentManager.Instance.CurrentDBDocument

items = UnwrapElement(IN[0]) if isinstance(IN[0],list) else [UnwrapElement(IN[0])]

revitlist = list()
dynlist = list()
catlist = list()


TransactionManager.Instance.EnsureInTransaction(doc)

i = 0
for item in items:
	geo_options = Options()
	revitGeo = item.Geometry[geo_options]
	try:		
		revit_geos = convert_geometry_instance(revitGeo, list())
		revitlist.append(revit_geos)
		dyn_geos = list()
		cats = list()
		for geo in revit_geos:
			try:
				dyn_geos.append(geo.ToProtoType())
			except:
				dyn_geos.append(None)
			try:
				graphstyle = doc.GetElement(geo.GraphicsStyleId)
				if graphstyle != None:
					cats.append(Revit.Elements.Category.ById(graphstyle.GraphicsStyleCategory.Id.IntegerValue))
				else:
					cats.append(None)
			except:
				cats.append(None)
		dynlist.append(dyn_geos)
		catlist.append(cats)		
	except:
		revitlist.append(list())
		dynlist.append(list())
		catlist.append(list())
	i += 1

TransactionManager.Instance.TransactionTaskDone()

OUT = dynlist

EDIT
Be aware that this code may not work for some elements that have a lot more complexity with multiple void cut-outs, etc. That’s why I recommend searching the forum for additional methods.

Could you please export this object to SAT just from Revit? I have not access to Revit 2022. I’ll check it in 2021.

Hi @olivar.wasely i have just test you file it seems work fine with ootb both in 23 and 24 at least in my test…strange

Hi @Vladimir
NLRS_25-1_ME_FB_Kabelklem_gen_QIR-3DView-{3D}.sat (2.2 MB)

Hi @staylor , thank you very much for the detailed answer!

i tried it but it gave me an error.

image

test solids.dyn (10.7 KB)

@sovitek , this is very weird! maybe dynamo was ‘having a bad day’?? it seems to work at my side now as well!

2 Likes

hhehe yes sometimes dynamo have a off day :wink: but great it works now

1 Like

Thanks all for the discussion, but still there are cases in which we can’t extract solids out of the element. One common example that I face a lot in our project is getting the solids out of floor elements, and the famous error is as below:

*Warning: Element.get_Solids operation failed. *
Value cannot be null.
Parameter name: revitCurve
It seems that when we have lots of points on a floor element, solid extraction fails

@Amir.Moeini.Sh , exactly. And also for CAD imported in Families: it does not work also. the geometry can not be recocnised if it’s not Revit Native…

There are a number of methods you can try to get a solid.
I have even used this method before

Staylor, thanks for the reply and the suggested method. But I think the logic behind is the same as what Element.Solid node does. So the result would not be different.

1 Like