def around_itself(self): """Method used to rotate elements on themselves""" with rpw.db.Transaction("Rotate around itself", doc): for elid in self.selection: el_axis = xyz_axis(elid) for i in range(3): if self.angles[i] == 0: pass else: ElementTransformUtils.RotateElement( doc, elid, el_axis[i], self.angles[i])
def rotate_element(elem, degrees_to_rotate): #>>>>>>>>>> GET CENTER POINT bounding_box = elem.get_BoundingBox(doc.ActiveView) point = (bounding_box.Min + bounding_box.Max) / 2 #>>>>>>>>>> AXIS LINE axis_line = Line.CreateBound( point, point + XYZ.BasisZ) #fixme will not rotate 2D in secitons #>>>>>>>>>> ROTATE ElementTransformUtils.RotateElement(doc, elem.Id, axis_line, math.radians(degrees_to_rotate))
from pyrevit import revit, DB __context__ = 'selection' __doc__ = 'Randomly rotates selected elements.' # reference the current open revit model to work with: doc = __revit__.ActiveUIDocument.Document # get selected element selection = revit.get_selection() elements = selection.elements degrees_to_rotate = 45.0 # Convert the user input from degrees to radians. converted_value = float(degrees_to_rotate) * (math.pi / 180.0) # entering a transaction to modify the revit model database # start transaction tx = Transaction(doc, "check type against parameter value") tx.Start() for element in elements: origin = element.Location.Point line_z = Line.CreateBound(origin, XYZ(origin.X, origin.Y, origin.Z + 1)) ElementTransformUtils.RotateElement(doc, element.Id, line_z, random.uniform(0, (math.pi * 2))) # commit the changes to the revit model database # end transaction tx.Commit()