Sorry for digging this thread back up, but my question directly relates to it. My company is now getting into panels that have a steel frame attached. So now we are needing to take the density of the material into account in the center of gravity calc. Below is the code that I am using to get the solid of the list of elements and I need to a section that calcs the density. I am a novice when it comes to python for Dynamo, so would be grateful for any help or advice on what to do. Thanks in advance to any advice provided. I also apologize in advance as I don’t know how to adequately clip code from a node into the thread.
Load the Python Standard and DesignScript Libraries
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])
detail_lvl = ViewDetailLevel.Fine
inc_invis = False
view = None
inserts = True
remove_inserts = False
revitlist = list()
dynlist = list()
TransactionManager.Instance.EnsureInTransaction(doc)
i = 0
for item in items:
geo_options = Options()
geo_options.DetailLevel = detail_lvl
geo_options.IncludeNonVisibleObjects = inc_invis
revitGeo = item.Geometry[geo_options]
try:
revit_geos = convert_geometry_instance(revitGeo, list())
revitlist.append(revit_geos)
except:
revitlist.append(list())
i += 1
TransactionManager.Instance.TransactionTaskDone()
volz=
cent=
for sol in revitlist:
for so in sol:
volz.append(so.Volume)
cent.append(so.ComputeCentroid())
totvol=sum(volz)
xs=
ys=
zs=
for i in range(0,len(volz)):
vol=volz[i]
cen=cent[i]
xs.append(cen.Xvol/totvol)
ys.append(cen.Yvol/totvol)
zs.append(cen.Z*vol/totvol)
centroidpoint=Point.Create(XYZ(sum(xs),sum(ys),sum(zs))).ToProtoType()
OUT = (totvol,centroidpoint)