0

I am trying to used the Revit Interactive Python Shell to rotate an object in Revit. I am hung up on how to designate the axis of rotation. I don't know how to create a line with the API and then designate an axis in ElementTransformUtils.RotateElement()

The third argument in RotateElement() is the axis. I am creating a line but I am not sure if I am designating its axis in the third argument of .RotateElement()

When I run this code nothing happens. This is even the case if I have a wall selected. Please let me know if anything needs clarification.

Thanks,

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

def pickobject():
    from Autodesk.Revit.UI.Selection import ObjectType
    __window__.Hide()
    picked = uidoc.Selection.PickObject(ObjectType.Element)
    __window__.Show()
    __window__.Topmost = True
    return picked

#set the active Revit application and document
app = __revit__.Application
doc = __revit__.ActiveUIDocument.Document

#define a transaction variable and describe the transaction
t = Transaction(doc, 'This is my new transaction')

#start a transaction in the Revit database
t.Start()

#perform some action here...

el = pickobject()    

p1 = XYZ(0,0,0)
p2 = XYZ(0,0,1)
myLine = Line.CreateBound(p1, p2)

ElementTransformUtils.RotateElement(doc, el.ElementId, myLine, math.pi / 2)

#commit the transaction to the Revit database
t.Commit()

#close the script window
__window__.Close()

It turns out I wasn't properly selecting an element or converting degrees to radians. After doing these things I was able to make my selected element rotate 90 degrees. The only problem I face now is choosing the origin at which the element rotates.

Christian Gentry
  • 811
  • 3
  • 10
  • 15

2 Answers2

1

I think what you're doing wrong is the angle. This needs to be in radians. In your example that would be π/2. See here

Jan Buijs
  • 98
  • 1
  • 6
  • Hello Jan, thank you for taking the time to look into this. I changed the angle to math.pi / 2. However, the wall still does not rotate. Does the Rotate Element method only work on basic geometry? – Christian Gentry Dec 10 '18 at 16:32
  • @ChristianGentry I see you got the rotation working, but are struggling with the rotation origin? You'll just have to change the X and Y coordinates of p1 and p2 in your code to the origin point if you want to change that. – Jan Buijs Dec 11 '18 at 08:00
1

Your Python script looks perfectly all right to me, once the 90 degrees have been replaced by 0.5 * pi radians. You can compare it with this similar snippet of working sample code used for a Creative Workaround to Rotate Elevation Marker in Chunks.

Jeremy Tammik
  • 7,333
  • 2
  • 12
  • 17
  • Thanks Jeremy! The reason it wasn't working was because I hadn't converted to radians and I also hadn't properly selected the element. Now my only issue is specifying the rotation origin. – Christian Gentry Dec 10 '18 at 17:38
  • Good to hear. The rotation axis defined by `myLine` defines the rotation origin and direction. – Jeremy Tammik Dec 11 '18 at 19:50