Hello , i tried a little script to rotate pipe fittings around their reference axis , so i took fitting’s connectors positions as base , created an axis from the reference point in the same direction as the connectors’s line .
My problem is when i rotate many times, after one or two rotations, the connectors switch ( connector 1 position come connector 2 position and vice et versa) , and the direction of the line become in the opposite direction (so that change the sense of rotation) .
Can i find a second point (like the reference point) so that the direction of the rotation’s axis stay always the same , or maybe an other idea ?
import clr
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
doc = DocumentManager.Instance.CurrentDBDocument
clr.AddReference("System")
from System.Collections.Generic import *
elements = UnwrapElement(IN[0])
angle = IN[1]
p=[]
for e in elements :
#getting position of connectors
points=[]
try :
connectors=e.MEPModel.ConnectorManager.Connectors
except :
try:
connectors = e.ConnectorManager.Connectors
except :
p.append(None)
for conn in connectors:
points.append(conn.Origin.ToPoint())
#reference point of the fitting
ref_location = e.Location.Point
#create line between connecors
ligne=Line.CreateBound(XYZ(points[0].X,points[0].Y,points[0].Z),XYZ(points[1].X,points[1].Y,points[1].Z))
#direction of the line between connectors
direction=ligne.Direction
#creating a line from the reference point and parralel to the connectors line
longueur=ligne.Direction.GetLength()
rot_axis = Line.CreateBound(ref_location,ref_location+5*direction)
#rotating elements
TransactionManager.Instance.EnsureInTransaction(doc)
ElementTransformUtils.RotateElement(doc, e.Id , rot_axis , angle)
TransactionManager.Instance.TransactionTaskDone()
OUT= 0