Assembly rotation problem

I searched all the related posts and we seem to be having a problem determining the rotation of assemblies. When i dug deeper I found the API is throwing an exception when polling the rotation. Are there any workarounds to this?

1 Like

You can use the AssemblyInstance’s GetTransform method and calculate its rotation using some of the built-in methods for the XYZ class. The code shown here outputs the plan rotation (i.e. rotation on the XY plane) of all assembly instances in the current document:

image

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
import math

doc = DocumentManager.Instance.CurrentDBDocument
assemblies = FilteredElementCollector(doc).OfClass(AssemblyInstance)

angles = []
for a in assemblies:
	transform = a.GetTransform()
	vec_x = transform.BasisX
	# Calculate angle of transform's BasisX against standard X axis.
	# BasisZ is the normal of the plane.
	angle = vec_x.AngleOnPlaneTo(XYZ.BasisX, XYZ.BasisZ)
	angles.append(math.degrees(angle))

OUT = angles
5 Likes

Thank you. I’ll give this a twirl.