Rotate Assembly Instance in Project

I have been trying to find a way to rotate an assembly instance in the project to match the orientation of a selected model element. All of the posts I have seen seem to be dealing with rotating the assembly origin and therefore rotating the way the assembly appears in its own views. I am looking for a way to rotate the assembly instance in the project through dynamo. Any help would be greatly appreciated!

Hey,

So I think from what you’re describing you want to rotate the elements inside the assembly?

Here is a quick and dirty example… It would need a lot of work to be useful generally…

import clr

import System
from System import *

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import *

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

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

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

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

try:
   assembly_ref = uidoc.Selection.PickObject(ObjectType.Element, 'Please Pick an assembly containing 1 wall')
except OperationCanceledException:
   sys.exit()
   
assembly = doc.GetElement(assembly_ref.ElementId)

assembly_element_Id = assembly.GetMemberIds()
assembly_element = doc.GetElement(assembly_element_Id[0])
line = assembly_element.Location.Curve

axis = assembly.GetCenter()

angle = UnitUtils.Convert(IN[0], DisplayUnitType.DUT_DECIMAL_DEGREES, DisplayUnitType.DUT_RADIANS) #this has been updated in the API

transform = Transform.CreateRotation(axis, angle)

TransactionManager.Instance.EnsureInTransaction(doc)

new_Curve = line.CreateTransformed(transform)

assembly_element.Location.Curve = new_Curve

OUT = assembly

TransactionManager.Instance.TransactionTaskDone()    


Hi @JGabrielse,

Maybe the links below can also help you in the right direction.
Link 1
Link 2

@Mark.Ackerley Thank you for the script, I will test it out! I didn’t think about rotating all the members of the assembly instead. I am curious if this will cause Revit to make it a new assembly though. Which for what I am doing won’t matter but could be an issue for others who may be looking to do something similar.

@MJB-online I have looked at both of those posts several times before making this one. I even tried the scripts from Link 1. But as I said in this post, those seem to deal with rotating the assembly origin, without actually rotating the assembly in the project. I am looking to basically do the same as selecting the assembly, and using he rotate command in a project to reorient it like any other family instance (but through dynamo).

just use Element.GetRotation and Element.SetRotation from Genius Loci

2 Likes

Thank you @viktor_kuzev! That was the fastest way to get what I needed. Although the node didn’t exist in the version I installed for Revit 2019, so I had to install the package for a later version of Revit/Dynamo and copy the code to my own python node in 2019.