I’m working on a Dynamo script where I need to rotate one element in Revit based on the orientation of another element. I’ve managed to extract geometry and directions, but I’m unsure how to calculate the angle and apply the rotation properly.
Specifically, I’d like to:
Find the angle between the two elements.
Rotate the first element to align with the reference element.
Is there a built-in node for this, or do I need to use a package like Clockwork or Rhythm? If anyone has a step-by-step solution or example workflow, I’d greatly appreciate it!
If the two elements being compared are families and are aligned to the default family references (i.e. “Center Left/Right” or “Center Front/Back”), you can get those references and the corresponding planes from the references. Link below has the code and example for getting the references and planes. Use Plane.Normal to get the vectors of the planes and use the Vector.AngleAboutAxis node to compare return the angle between them. FYI, use the View.Direction for the rotation axis. From that point use the Element.SetRotation as you already have.
I’ve extracted the reference planes and used Plane.Normal to get the vectors for both the element and the reference.
I calculated the angle between the vectors using Vector.AngleAboutAxis, with View.Direction as the rotation axis.
I used the Element.SetRotation node to apply the rotation, but the element is not aligning correctly with the reference plane as expected.
I suspect I might be making a mistake in one of the steps, or perhaps the issue lies in how the axis or angle is defined. Could you please provide more details or clarify the following?
How should I confirm the correct reference planes are being used?
Is there a specific setup or example for Element.SetRotation to work properly?
Any tips on debugging whether the calculated angle and rotation axis are correct?
I’d really appreciate additional guidance or a small working example.
Try using the out of the box FamilyInstance.FacingOrientation node instead of fighting the planes.
From there the vector of the family that you want to rotate should be the Vector input, the vector of the family you want to rotate to is the other vector, and the normal is typically the Z axis.
Extracted the FacingOrientation vector of the family I want to rotate.
Extracted the FacingOrientation vector of the reference family.
Used the Vector.AngleAboutAxis node to calculate the angle between the two vectors, with the normal set to the Z-axis (Vector.ZAxis).
Applied the calculated angle using Element.SetRotation.
Unfortunately, the element still does not align correctly with the reference family. It seems the rotation is applied, but the orientation remains slightly off.
Could this issue be related to the family geometry or its default references? If there are additional considerations (like the family’s insertion point or orientation in the project environment), I would appreciate further clarification or an example of how to resolve this.