How to Rotate an Element in Dynamo with Reference to Another Element?

Hi everyone,

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:

  1. Find the angle between the two elements.
  2. 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!

Thanks in advance for your help!

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.

1 Like

Thank you for the detailed explanation! I’ve tried implementing the steps as suggested, but I’m still facing issues. Specifically:

  1. I’ve extracted the reference planes and used Plane.Normal to get the vectors for both the element and the reference.
  2. I calculated the angle between the vectors using Vector.AngleAboutAxis, with View.Direction as the rotation axis.
  3. 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.

Thanks again for your help!

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.

2 Likes

Thank you for the suggestion! I tried using the FamilyInstance.FacingOrientation node as you described. Here’s what I did:

  1. Extracted the FacingOrientation vector of the family I want to rotate.
  2. Extracted the FacingOrientation vector of the reference family.
  3. Used the Vector.AngleAboutAxis node to calculate the angle between the two vectors, with the normal set to the Z-axis (Vector.ZAxis).
  4. 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.

Thank you again for your help!

Can you show a before/after and expand your data previews so I can see what the angles used are?

Thank you for your response! I’ll prepare a before/after example to clarify the issue.
Before:

After:

I am guessing that the elements are not in matching order based on the first angle indicating it needs to rotate ~0 degrees.

Check if the item being rotated is the same as the one you are rotating to.

1 Like

hi, here is what Mr.Jacob told you


before

after

Sincerely
christian.stan