Dynamo 2.19, Python 3, Revit 2024
I have issue with this code when i run it , the outputs gives correct # of dictionaries but with null values, if any one can help figure the issue please advice.
Code:
# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# The inputs to this node will be a list of polycurves.
polycurves = IN[0]
# Create lists for the outputs.
insertionPoints = []
directionsX = [] # Length in X direction
directionsY = [] # Length in Y direction
rotationAngles = []
# Loop through each polycurve.
for polycurve in polycurves:
# Get the bounding box of the polycurve.
boundingBox = polycurve.BoundingBox
# Get the center point of the bounding box.
insertionPoint = boundingBox.CenterPoint
# Calculate the vector representing the width (X direction).
# Find the two points on the X edges with the maximum and minimum Y values.
maxXminY = polycurve.FindPointsAt(lambda p: p.X == boundingBox.MaxPoint.X and p.Y == boundingBox.MinPoint.Y)[0]
minXmaxY = polycurve.FindPointsAt(lambda p: p.X == boundingBox.MinPoint.X and p.Y == boundingBox.MaxPoint.Y)[0]
directionX = maxXminY - minXmaxY
# Calculate the vector representing the height (Y direction).
# Find the two points on the Y edges with the maximum and minimum X values.
maxYminX = polycurve.FindPointsAt(lambda p: p.Y == boundingBox.MaxPoint.Y and p.X == boundingBox.MinPoint.X)[0]
minYmaxX = polycurve.FindPointsAt(lambda p: p.Y == boundingBox.MinPoint.Y and p.X == boundingBox.MaxPoint.X)[0]
directionY = maxYminX - minYmaxX
# Get the length of the directions (width and height).
lengthX = directionX.GetLength()
lengthY = directionY.GetLength()
# Calculate the rotation angle (assuming clockwise rotation):
# Use the arctangent function to find the angle between the positive X-axis and directionX.
rotationAngle = math.atan2(directionX.Y, directionX.X) # Radians, adjust for degrees if needed
# Convert to degrees if necessary: rotationAngle = math.degrees(rotationAngle)
# Add the values to the output lists.
insertionPoints.append(insertionPoint)
directionsX.append(directionX)
directionsY.append(directionY)
rotationAngles.append(rotationAngle)
# Set the output of the node to the lists of values.
OUT = insertionPoints, directionsX, directionsY, rotationAngles
==================================================================
Custom node visualization: