/// <summary> /// 设置模型原点 /// </summary> /// <param name="insertionPoint">如果是0表示项目基点,非零表示观测点。</param> /// <returns></returns> private Transform GetProjectLocationTransform(int insertionPoint) { Transform transform = Transform.Identity; using (IEnumerator <Element> enumerator = new FilteredElementCollector(document).OfClass(typeof(BasePoint)).GetEnumerator()) { while (enumerator.MoveNext()) { BasePoint basePoint = (BasePoint)enumerator.Current; if (basePoint.IsShared == (insertionPoint != 0)) { double num = 0.0; Parameter parameter = basePoint.get_Parameter(BuiltInParameter.BASEPOINT_ANGLETON_PARAM); if (parameter != null) { num = parameter.AsDouble(); } transform = GetTransformFromLocation(basePoint.get_Parameter(BuiltInParameter.BASEPOINT_EASTWEST_PARAM).AsDouble(), basePoint.get_Parameter(BuiltInParameter.BASEPOINT_NORTHSOUTH_PARAM).AsDouble(), basePoint.get_Parameter(BuiltInParameter.BASEPOINT_ELEVATION_PARAM).AsDouble(), -num); } } } ProjectPosition projectPosition = document.ActiveProjectLocation.GetProjectPosition(XYZ.Zero); Transform transformFromLocation = GetTransformFromLocation(projectPosition.EastWest, projectPosition.NorthSouth, projectPosition.Elevation, projectPosition.Angle); return(transform.Inverse * transformFromLocation); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { Application app = commandData.Application.Application; UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; // Get Project Base Point (PBP) and it's parameters. FilteredElementCollector collector = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_ProjectBasePoint); BasePoint element = (BasePoint)collector.ToElements().FirstOrDefault(); double angle = element.get_Parameter(BuiltInParameter.BASEPOINT_ANGLETON_PARAM).AsDouble(); double EW = element.get_Parameter(BuiltInParameter.BASEPOINT_EASTWEST_PARAM).AsDouble(); double NS = element.get_Parameter(BuiltInParameter.BASEPOINT_NORTHSOUTH_PARAM).AsDouble(); double elevation = element.get_Parameter(BuiltInParameter.BASEPOINT_ELEVATION_PARAM).AsDouble(); // Get the coordinates of the Project Base Point (PBP) in case it's moved unclipped. XYZ PBP = element.get_BoundingBox(null).Max; // Calculating the distances between internal origo and shared origo. EW and NS is measured in the directions given by the angle to true north. double x = EW * Math.Cos(angle) - NS * Math.Sin(angle) - PBP.X; double y = NS * Math.Cos(angle) + EW * Math.Sin(angle) - PBP.Y; double z = elevation - PBP.Z; XYZ SharedOrigo = new XYZ(-x, -y, -z); Line axis = Line.CreateUnbound(SharedOrigo, new XYZ(0, 0, 1)); Element selectedLink; try { selectedLink = doc.GetElement(uidoc.Selection.PickObject(ObjectType.Element, "Pick a link to move from Origin (internal) to Surveypoint.")); } catch(Autodesk.Revit.Exceptions.OperationCanceledException) { return Result.Cancelled; } if (selectedLink == null) return Result.Failed; using (Transaction t1 = new Transaction(doc, "Move link from internal origin to survey point")) { t1.Start(); selectedLink.Location.Move(SharedOrigo); selectedLink.Location.Rotate(axis, angle); t1.Commit(); } return Result.Succeeded; }