I get geometry of polyline of panel boundaries with this designscript but I do not achieve to use in ironpython in Dynamo:
t1 = t2;
polyCurve1 = CurtainPanel.Boundaries(t1);
polyCurve11 = polyCurve1;
curve1 = PolyCurve.Curves(polyCurve11);
I imported this trying to use in ironpython:
clr.AddReference('DSCoreNodes')
import DSCore
from DSCore import *
I created this script but there are curtain panels with no result so 100% elements must have a result, do I need to consider the families of curtain panels are wrong or corrupt?:
import clr
clr.AddReference('RevitAPI')
clr.AddReference('RevitServices')
clr.AddReference('ProtoGeometry')
from Autodesk.Revit.DB import *
from Autodesk.DesignScript.Geometry import Point
from RevitServices.Persistence import DocumentManager
# Define the function to retrieve location geometry
def GetLocationGeometry(item, transform=None):
"""
Retrieves the location geometry of an element.
Handles points, curves, loops, and bounding box centroids as fallback.
Applies a transformation if provided.
"""
try:
# Points and text notes
if hasattr(item, "Coord"):
point = Point.ByCoordinates(item.Coord.X, item.Coord.Y, item.Coord.Z)
return point.Transform(transform) if transform else point
# Base points and reference points
if hasattr(item, "Position"):
point = Point.ByCoordinates(item.Position.X, item.Position.Y, item.Position.Z)
return point.Transform(transform) if transform else point
# Independent tags
if hasattr(item, "TagHeadPosition") and hasattr(item, "IsMaterialTag"):
point = Point.ByCoordinates(item.TagHeadPosition.X, item.TagHeadPosition.Y, item.TagHeadPosition.Z)
return point.Transform(transform) if transform else point
# Views
if hasattr(item, "ViewType") and hasattr(item, "Origin"):
if item.Origin:
point = Point.ByCoordinates(item.Origin.X, item.Origin.Y, item.Origin.Z)
return point.Transform(transform) if transform else point
# General elements with location
if hasattr(item, "Location"):
loc = item.Location
if loc:
# Line-based elements (e.g., walls)
if isinstance(loc, LocationCurve):
curve = loc.Curve
midpoint = curve.Evaluate(0.5, True)
point = Point.ByCoordinates(midpoint.X, midpoint.Y, midpoint.Z)
return point.Transform(transform) if transform else point
# Point-based elements (e.g., most loadable families)
elif isinstance(loc, LocationPoint):
point = Point.ByCoordinates(loc.Point.X, loc.Point.Y, loc.Point.Z)
return point.Transform(transform) if transform else point
# Fallback to bounding box centroid
bbox = item.get_BoundingBox(None)
if bbox:
centroid_x = (bbox.Min.X + bbox.Max.X) / 2
centroid_y = (bbox.Min.Y + bbox.Max.Y) / 2
centroid_z = (bbox.Min.Z + bbox.Max.Z) / 2
point = Point.ByCoordinates(centroid_x, centroid_y, centroid_z)
return point.Transform(transform) if transform else point
except Exception as ex:
# Return an error message as a string for debugging
return "Error processing element: " + str(item.Id) if hasattr(item, 'Id') else "Unknown element"
# If no geometry found, return None
return None
# Main Script
doc = DocumentManager.Instance.CurrentDBDocument
# Input: Flattened list of Revit elements
elements = UnwrapElement(IN[0])
# Process elements and retrieve geometries
location_geometries = []
debug_messages = []
for e in elements:
loc_geo = GetLocationGeometry(e)
if loc_geo:
location_geometries.append(loc_geo)
debug_messages.append("Successfully processed element: " + str(e.Id))
else:
location_geometries.append(None)
debug_messages.append("Failed to process element: " + str(e.Id) if hasattr(e, 'Id') else "Unknown element")
# Output location geometries and debug messages
OUT = location_geometries, debug_messages