Hello,
Have a nice day.
Could you please advise me on this issue? I would like to select all of the floor elements in the Revit file at once, but this script permits only one element for a running process. How to modified for this script and python code?
My Revit version is 2022,
Dynamo core 2.10.1.3976, and
Dynamo Revit 2.10.1.4002
Thank you very much.
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
import math
floors = UnwrapElement(IN[0])
angle = []
for f in floors:
angle.append(math.degrees(f.SpanDirectionAngle))
OUT = angle
Hello,
Thank you so much for your help @Draxl_Andreas.
I tried your dynamo script, it works well in some Revit files. But on my project file, there is another warning issue “Warning: One or more geometries have failed to convert due to this error: trim_with_edge_loops requires all curves to touch surface”.
So, I got a python code for this issue. But I can’t solve my problem at all.
Python Code is here;
import clr
import System
import sys
clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *
import Autodesk.DesignScript.Geometry as DS
clr.AddReference(‘RevitAPI’)
from Autodesk.Revit.DB import *
clr.AddReference(“RevitServices”)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
def get_AllSolid(lst_elem, inc = 0):
# sub functon
def populate_lstGeo(g):
if isinstance(g, Solid) and g.Volume > 0:
solids.append(g)
elif isinstance(g, GeometryInstance):
geoInst.append(g)
else:pass
#
# main functon
global opt
solids =
geoInst =
lst_elem = lst_elem if hasattr(lst_elem, “iter”) else [lst_elem]
if len(lst_elem) > 0 and inc < 2000:
for elem in lst_elem:
if isinstance(elem, GeometryInstance):
for j in elem.GetInstanceGeometry():
populate_lstGeo(j)
else:
geoSet = elem.get_Geometry(opt)
for i in geoSet:
populate_lstGeo(i)
return solids + get_AllSolid(geoInst, inc + 1)
else:
return
elem = UnwrapElement(IN[0])
opt = Options()
solids = get_AllSolid(elem)
ds_Solids =
for s in solids:
try:
ds_Solid = s.ToProtoType()
ds_Solids.append(ds_Solid)
except Exception as ex:
if “trim_with_edge_loops” in str(ex):
# failed conversion DB.Solid to Prototype → try get make solid with ByJoinedSurfaces
ds_face =
for f in s.Faces:
try:
ds_face.extend(f.ToProtoType())
except:
# failed conversion DB.Face to Prototype → try get make Surface with PolyCurves.Patch
ds_edges = [c.ToProtoType() for curveloop in f.GetEdgesAsCurveLoops() for c in curveloop]
ds_poly_edges = PolyCurve.ByJoinedCurves(ds_edges)
ds_face.append(ds_poly_edges.Patch())
ds_Solid = DS.Solid.ByJoinedSurfaces(ds_face)
ds_Solids.append(ds_Solid)
else:
raise Exception(ex)
#Python Code is here;
import clr
import System
import sys
clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *
import Autodesk.DesignScript.Geometry as DS
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 get_AllSolid(lst_elem, inc = 0):
# sub functon
def populate_lstGeo(g):
if isinstance(g, Solid) and g.Volume > 0:
solids.append(g)
elif isinstance(g, GeometryInstance):
geoInst.append(g)
else:pass
#
# main functon
global opt
solids =
geoInst =
lst_elem = lst_elem if hasattr(lst_elem, “iter”) else [lst_elem]
if len(lst_elem) > 0 and inc < 2000:
for elem in lst_elem:
if isinstance(elem, GeometryInstance):
for j in elem.GetInstanceGeometry():
populate_lstGeo(j)
else:
geoSet = elem.get_Geometry(opt)
for i in geoSet:
populate_lstGeo(i)
return solids + get_AllSolid(geoInst, inc + 1)
else:
return
elem = UnwrapElement(IN[0])
opt = Options()
solids = get_AllSolid(elem)
ds_Solids =
for s in solids:
try:
ds_Solid = s.ToProtoType()
ds_Solids.append(ds_Solid)
except Exception as ex:
if “trim_with_edge_loops” in str(ex):
# failed conversion DB.Solid to Prototype → try get make solid with ByJoinedSurfaces
ds_face = for f in s.Faces:
try:
ds_face.extend(f.ToProtoType())
except:
# failed conversion DB.Face to Prototype → try get make Surface with PolyCurves.Patch
ds_edges = [c.ToProtoType() for curveloop in f.GetEdgesAsCurveLoops() for c in curveloop]
ds_poly_edges = PolyCurve.ByJoinedCurves(ds_edges)
ds_face.append(ds_poly_edges.Patch())
ds_Solid = DS.Solid.ByJoinedSurfaces(ds_face)
ds_Solids.append(ds_Solid)
else:
raise Exception(ex)
OUT = ds_Solids
Dear @Draxl_Andreas;
I mentioned above "Warning: One or more geometries have failed to convert due to this error: trim_with_edge_loops requires all curves to touch surface”., could you please check…
Thank you so much for your help…
Just try to sort out “bad” floors and look into their profiles. Maybe some loops, or double curves are the problem? Anyway, feel free to share that floors, we’ll help!
Hello @Vladimir;
Have a nice day.
I convert the dimension unit from meter to feet in the project file that you mentioned in the above post to solve my problem. But another problem is I only have little knowledge of python coding and dynamo. In the above post, the coding is used for beam unit changes, my approach is for floors. So, I edited the coding beam for floor. And I cannot solve my problem also. Could you please check the dynamo script and coding for me? I very much appreciate any help.