Code for Familyinstance.SetRotaate

what is the python code for the below node
image

Hi @shibujoseukken,

You can use the ElementTransformUtils class which has a RotateElement() method as shown here…

https://www.revitapidocs.com/2020/3968f4e8-759c-f975-6c1f-7de42be633ed.htm

Here is some example code as a base which you can expand upon…

##### Imports #####

import clr

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

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

import math

##### Definitions #####

def tolist(obj1):
	if hasattr(obj1,"__iter__"): return obj1
	else: return [obj1]

##### Inputs #####

elems = tolist(UnwrapElement(IN[0]))
angle = tolist(UnwrapElement(IN[1]))[0]

##### Output #####

outList = []

##### Main Script #####

# Open a Transaction as we are modifying the current context Document...
TransactionManager.Instance.EnsureInTransaction(doc)
for e in elems:
	try:
		# We are using the ElementTransformUtils class here which has a RotateElement static method. This takes a Document, ElementId, Axis of rotation as a Revit Line and the angle in radians.
		# First we will create the Axis of rotation by creating an bound Revit Line from the Elements Location and the Line will be vertical so rotation is in the global XY plane...
		rAxis = Line.CreateBound(e.Location.Point, XYZ(e.Location.Point.X,e.Location.Point.Y,e.Location.Point.Z+1))
		# We then do the rotation. The method returns Void (returns nothing)...
		ElementTransformUtils.RotateElement(doc,e.Id,rAxis, math.radians(angle))
		# Report if this was successful...
		outList.append("Success")
	# Catch and report Exception...
	except Exception,ex:
		outList.append(ex.message)
# We are done so close the Transaction...
TransactionManager.Instance.TransactionTaskDone()

# Return results to Dynamo Workspace...
OUT = outList

Cheers,
Dan

1 Like