Get Rotation of Instance Families in Python

Hello everyone,

I am developing a Python script in Dynamo/REVIT to obtain information about the rotation of instance families, as shown in the image below.

However, when running the code, the returned value is “NULL”. It is important to mention that this is not a selection issue, as I am indeed selecting an instance family.

Here is the code I developed:

import clr
clr.AddReference(‘RevitAPI’)
from Autodesk.Revit.DB import *

clr.AddReference(‘RevitServices’)
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument

def get_rotation(family_instance):
location_point = family_instance.Location
if isinstance(location_point, LocationPoint):
return location_point.Rotation
return None

family_instances = UnwrapElement(IN[0])

rotations =
for instance in family_instances:
rotation = get_rotation(instance)
rotations.append(rotation)

OUT = rotations

Can anyone help me with the code? Where am I going wrong?

Note: I am aware that there are Dynamo packages, such as the GENIUS LOCCI tools, that solve this problem, but I do not want to use them. I want to create my own code.

Thank you all in advance for your attention.

1 Like

@ADAP-Ass.Tre ,

intresting in your rotation there is the number pi that means either 0 or 360 degres (?)…

…just for better reading, your code pasted like this

import clr
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *

clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument

def get_rotation(family_instance):
    location_point = family_instance.Location
    if isinstance(location_point, LocationPoint):
        return location_point.Rotation
    else:
        return None


family_instances = UnwrapElement(IN[0])

rotations = []
for instance in family_instances:
    rotation = get_rotation(instance)
    rotations.append(rotation)

OUT = rotations

actually i skipped the part with isInstance, i collected in the code, so unwrapping is not necessary.

import clr

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

clr.AddReference('System')
from System.Collections.Generic import List

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

# 🎣 get elements 
elements = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_GenericModel).WhereElementIsNotElementType().ToElements()

# 📐 get rotation
elementRotations = [i.Location.Rotation for i in elements]

OUT = elements, elementRotations

by the way GeniusLocci is a Genius, because you can copy and modify his code for any porposes…

2 Likes

Hello @Draxl_Andreas Draxl_Andreas,

Thank you very much for responding to my post. Your help was crucial in solving my problem. I compared your code with mine and discovered the mistakes I made, especially with the library and the “uidoc,” among other lines. Your guidance was excellent.

I corrected the issues and adapted the code for CPython3. Here is my code:


import clr

clr.AddReference(‘RevitAPI’)
clr.AddReference(‘RevitAPIUI’)

from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *

import System
from System.Collections.Generic import List

from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

def unwrap_elements(elements):
return elements

elements = unwrap_elements(IN[0])

elementRotations =
for i in elements:
location_point = i.Location
if isinstance(location_point, LocationPoint):
elementRotations.append(location_point.Rotation)
else:
elementRotations.append(None)

OUT = elements, elementRotations

Once again, thank you for your help. We can successfully close this post now.

1 Like