Message 1 of 10
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I’m trying to create a Python script that transfers all Project locations from a source model to a target model. The documented way for setting a new ProjectLocation’s position is using the SetProjectPosition() method, which works for unmirrored link locations.
However, a ProjectPosition only contains X, Y, Z, and angle - and not reflection, so it igrnores mirroring of some locations(for mirrored linking).
ProjectLocation does have a GetTransform() method but no SetTransform() method.
I’m trying to use ElementTransformUtils.MirrorElement(), but it seems to have no effect.
whats the best way to achieve this?
import clr
clr.AddReference('RevitAPI')
clr.AddReference('RevitServices')
from Autodesk.Revit.DB import *
from pyrevit import forms
uiapp = __revit__.Application
uidoc = __revit__.ActiveUIDocument
def getTargetLocation(sourceLocation):
for t in target_doc.ProjectLocations:
if t.Name == sourceLocation.Name:
return t
def PositionString(pp):
x="X(E/W): {}".format(UnitUtils.ConvertFromInternalUnits(pp.EastWest, UnitTypeId.Meters))
y="Y(N/S): {}".format(UnitUtils.ConvertFromInternalUnits(pp.NorthSouth, UnitTypeId.Meters))
angle="angle: {}".format(UnitUtils.ConvertFromInternalUnits(pp.Angle, UnitTypeId.Degrees))
elevation="Elevation: {}".format(UnitUtils.ConvertFromInternalUnits(pp.Elevation, UnitTypeId.Meters))
return "{}\n{}\n{}\n{}".format(x,y,angle,elevation)
def TransformString(t):
return "{}, {}, {}".format(t.BasisX.ToString(), t.BasisY.ToString(), t.BasisZ.ToString())
source_doc = uidoc.Document
target_doc = forms.select_open_docs(title='Select Destination Documents', multiple=False)
print(source_doc)
if not target_doc:
print("Error: Target document not found. Please ensure both documents are open.")
exit()
# Access the project location from the source model
source_project_location = source_doc.ActiveProjectLocation
project_locations = source_doc.ProjectLocations
for l in project_locations:
position=l.GetProjectPosition(XYZ(0, 0, 0))
print("\nName: {}".format(l.Name))
print(PositionString(position))
locationTransform=l.GetTransform()
print(TransformString(locationTransform))
existingTargetLocation=getTargetLocation(l)
if existingTargetLocation:
print("{} exists in model {}".format(existingTargetLocation.Name, target_doc.Title))
print(PositionString(existingTargetLocation.GetProjectPosition(XYZ(0,0,0))))
existingTargetLocationTransform=existingTargetLocation.GetTransform()
print(TransformString(existingTargetLocationTransform))
else:
print('creating location {} in model {}'.format(l.Name,target_doc.Title))
t = Transaction(target_doc, 'create location {}'.format(l.Name))
t.Start()
newTargetLocation = ProjectLocation.Create(target_doc, target_doc.SiteLocation.Id, l.Name)
#print new ProjectLocation position and transform
print(PositionString(newTargetLocation.GetProjectPosition(XYZ(0, 0, 0))))
print(TransformString(newTargetLocation.GetTransform()))
mirrorPlane=Plane.CreateByNormalAndOrigin(XYZ(1,0,0), XYZ(10,10,10))
#print new ProjectLocation position and transform after transforming
ElementTransformUtils.MirrorElement(target_doc, newTargetLocation.Id, mirrorPlane)
ElementTransformUtils.MoveElement(target_doc, newTargetLocation.Id, locationTransform.BasisX)
newTargetLocation.SetProjectPosition(XYZ(0, 0, 0), position)
t.Commit()
print("success")
print(PositionString(newTargetLocation.GetProjectPosition(XYZ(0, 0, 0))))
print(TransformString(newTargetLocation.GetTransform()))
print("-------------")
Solved! Go to Solution.