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?
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?
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.
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.
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
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.