Rotate Family in Revit

Hi there,

I want to rotate some diffuser family instances in Revit. I am able to rotate it using the OOTB FamilyInstance.SetRotation node, but it does not allow me to specify the rotation axis.

The Rotate Family node from archilab displays the below warning.

Also, is there a way to rotate system families (Duct, Pipes) etc?

Python code of Rotate Family

#Copyright(c) 2015, Konrad Sobon
# @arch_laboratory, http://archi-lab.net

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

from System.Collections.Generic import *

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

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

# Import geometry conversion extension methods
clr.ImportExtensions(Revit.GeometryConversion)

#The inputs to this node will be stored as a list in the IN variable.
dataEnteringNode = IN

def toRvtId(_id):
	if isinstance(_id, int) or isinstance(_id, str):
		id = ElementId(int(_id))
		return id
	elif isinstance(_id, ElementId):
		return _id

lmntIds, axises, angles = [], [], []
for i, j in zip(IN[0], IN[1]):
	lmntIds.append(toRvtId(UnwrapElement(i)))
	axises.append(j.ToRevitType())
angles = IN[2]

# "Start" the transaction
TransactionManager.Instance.EnsureInTransaction(doc)

elements = []
for axis_, angle_, lmntId_ in zip(axises, angles, lmntIds):
	Autodesk.Revit.DB.ElementTransformUtils.RotateElement(doc, lmntId_, axis_, angle_)
	elements.append(doc.GetElement(lmntId_))

# "End" the transaction
TransactionManager.Instance.TransactionTaskDone()

#Assign your output to the OUT variable
OUT = elements

Hello
IN[0] and IN[1] must be list type. Insert 2 nodes List.Create before the Python Node (one for IN[0] and one for IN[1])

Both inputs 1 and 2 are list type. Same warning.

Angles too. You forgot it, I guess.

Now facing this warning.

Traceback (most recent call last):
  File "<string>", line 54, in <module>
TypeError: expected Line, got XYZ

At Code Part

TransactionManager.Instance.EnsureInTransaction(doc)

elements = []
for axis_, angle_, lmntId_ in zip(axises, angles, lmntIds):
	Autodesk.Revit.DB.ElementTransformUtils.RotateElement(doc, lmntId_, axis_, angle_)
	elements.append(doc.GetElement(lmntId_))

Did you use rot_axis = line_axis.ToRevitType() ?

In your code I see you try to convert a string to Revit type.

Where do I need to use this?

I’m just trying to rotate a family about a specified axis.

For your case you can use FamilyInstance.SetRotation. It will rotate around Z.

Actually I wanted to rotate about a different axis, x or y, or maybe around a vector?

import clr

# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk

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

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

# Import geometry conversion extension methods
clr.ImportExtensions(Revit.GeometryConversion)

# Import Element wrapper extension methods
clr.ImportExtensions(Revit.Elements)

doc= DocumentManager.Instance.CurrentDBDocument

clr.AddReference("System")
from System.Collections.Generic import *
clr.AddReference("ProtoGeometry")
from Autodesk.DesignScript.Geometry import *
elements = UnwrapElement(IN[0])
angle= IN[1]
line_axis=IN[2].ToRevitType()

rot_axis=line_axis
	
TransactionManager.Instance.EnsureInTransaction(doc)
for elem in elements:

	ElementTransformUtils.RotateElement(doc, elem.Id, rot_axis, angle)
TransactionManager.Instance.TransactionTaskDone()

OUT  = "Success!"

You should select model elements and as axis a line.
and don’t forget to change radian to angle.

Thanks, but is this how I supposed to use it?

Element.Geometry of DetailCurve and then try it and there is a node for converting Degrees to Radian try it :slight_smile:

Still the same warning.

Without List.Create of angle. I did not loop over it.

Same warning. :smiley:

import clr

# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk

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

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

# Import geometry conversion extension methods
clr.ImportExtensions(Revit.GeometryConversion)

# Import Element wrapper extension methods
clr.ImportExtensions(Revit.Elements)

doc= DocumentManager.Instance.CurrentDBDocument

clr.AddReference("System")
from System.Collections.Generic import *
clr.AddReference("ProtoGeometry")
from Autodesk.DesignScript.Geometry import *
elements = UnwrapElement(IN[0])
angle= IN[1]
line_axis=IN[2].ToRevitType()
if isinstance(elements,list):
	elements = elements
else:
	elements  = [elements]
rot_axis=line_axis
	
TransactionManager.Instance.EnsureInTransaction(doc)
for elem in elements:

	ElementTransformUtils.RotateElement(doc, elem.Id, rot_axis, angle)
TransactionManager.Instance.TransactionTaskDone()

OUT  = "Success!"

It is all about looping :slight_smile:

It’s not going away.

Please remove List.Create of Math.Degrees.TorRadians

Tried. But it’s not working.

hello
an example with Model Line Selection as axis

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

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

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application


clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.GeometryConversion)

toDoList = lambda x : x if hasattr(x, '__iter__') else [x]
elems = toDoList(UnwrapElement(IN[0]))
angleRad = IN[1]
lineProtoTypAxis = IN[2]
outElement = []

TransactionManager.Instance.EnsureInTransaction(doc)
for elem in elems:
	line = Line.CreateUnbound(lineProtoTypAxis.StartPoint.ToXyz(), lineProtoTypAxis.EndPoint.ToXyz())
	ElementTransformUtils.RotateElement(doc, elem.Id, line, angleRad)	
	outElement.append(elem)	
TransactionManager.Instance.TransactionTaskDone()
OUT = outElement

the base of axis is on FamilyInstance?

2 Likes