- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi All,
I am trying to rotate the assembly origin for several days now, although it might seem to be an easy task it is not for me.
The problem is when I run the code, it rotates the assembly origin but it also moves the origin! which is not desired. I just want to rotate the origin around its own axis so that the origin does not move.
Here is the code: (the assembly includes a wall, I find the location of the wall and try to rotate the assembly origin based on this point and the axis which crosses this point and is towards Z direction, please note that I pick the element based on its face.)
import Autodesk.Revit.DB as DB
from Autodesk.Revit.DB import*
from Autodesk.Revit.Exceptions import*
import math as m
import sys
uidoc = __revit__.ActiveUIDocument
doc = __revit__.ActiveUIDocument.Document
ref = uidoc.Selection.PickObject(ObjectType.Face, 'Please Pick NearFace')
wall = doc.GetElement(ref)
face = wall.GetGeometryObjectFromReference(ref)
assembly_id = wall.AssemblyInstanceId
assembly = doc.GetElement(assembly_id)
line = wall.Location.Curve #Defining the line to find the mid point of the wall so I rotate based on this point
mid_point = (line.GetEndPoint(1) + line.GetEndPoint(0))/2
axis = line.CreateBound(mid_point, XYZ(mid_point.X, mid_point.Y, 1)) #Axis of rotation
assembly_origin = assembly.GetTransform() #Getting the assembly_origin
rotation = assembly_origin.CreateRotationAtPoint(axis, m.radians(90), mid_point)
t = Transaction(doc, 'ROTATION')
t.Start()
assembly.SetTransform(rotation)
t.Commit()
result:
I have tried other ways but all result in the same thing. I also read that I have to rotate it based on its local coordination but I don't know how!
Any help would be much appreciated.
Thanks
Solved! Go to Solution.