/// Author: Danny Bentley /// Date : 09/23/2016 /// Objective : My Revit Library. Reusable Code. #region MOVING ELEMENTS IN REVIT public bool MoveUsingLocationCurve(Wall wall) { LocationCurve wallLine = wall.Location as LocationCurve; XYZ translationVec = new XYZ(10, 20, 0); return(wallLine.Move(translationVec)); }
// 移動牆的Function private bool moveWall(Wall wall, double translationX, double translationY) { // 抓取牆線 LocationCurve wallLine = wall.Location as LocationCurve; XYZ translationVector = new XYZ(translationX, translationY, 0); // 移動並回傳成功訊息 return(wallLine.Move(translationVector)); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; Selection sel = uidoc.Selection; View acview = uidoc.ActiveView; UIView acuiview = uidoc.ActiveUiview(); Transaction ts = new Transaction(doc, "******"); try { ts.Start(); //点选指定执行的元素, 本次按只能选择墙考虑 Reference pickedEleReference = sel.PickObject(ObjectType.Element); //通过引用取到选中的元素 Wall wall = doc.GetElement(pickedEleReference) as Wall; if (null != wall) { LocationCurve wallLine = wall.Location as LocationCurve; XYZ newPlace = new XYZ(100, 200, 0); wallLine.Move(newPlace); } ts.Commit(); } catch (Exception) { if (ts.GetStatus() == TransactionStatus.Started) { ts.RollBack(); } } return(Result.Succeeded); }
/// <summary> /// what can i do with revit api now? /// move wall by location /// </summary> /// <param name="commandData"></param> /// <param name="message"></param> /// <param name="elements"></param> /// <returns></returns> public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; Selection sel = uidoc.Selection; ElementId eleId = sel.PickObject(ObjectType.Element, doc.GetSelectionFilter(m => m is Wall)).ElementId; // doc.Invoke(m => { ElementTransformUtils.MoveElement(doc, eleId, new XYZ(1000d.MmToFeet(), 1000d.MmToFeet(), 0)); }, // "移动一片墙"); doc.Invoke(m => { LocationCurve wallLine = eleId.GetElement(doc).Location as LocationCurve; XYZ transVec = new XYZ(1000d.MmToFeet(), 1000d.MmToFeet(), 0); wallLine.Move(transVec);//墙上的窗户会跟着一起移动 }, "移动墙通过location"); return(Result.Succeeded); }
/// <summary> /// move one element, which may be a wall or a family instance /// </summary> /// <param name="doc"></param> /// <param name="elem"></param> /// <param name="translationVector"></param> /// <returns></returns> private string moveElement(Document doc, Element elem, XYZ translationVector) { StringBuilder sb = new StringBuilder(); //record the translation information //declare two Location objects, as they are multual exclusive, one of them will be null finally LocationPoint ptLocation = null; LocationCurve lineLocation = null; //the visible element will be either a wall or a familyinstance, these two condition are also mutual exclusive FamilyInstance fm = elem as FamilyInstance; if (fm != null) { ptLocation = fm.Location as LocationPoint; lineLocation = fm.Location as LocationCurve; } Wall wall = elem as Wall; if (wall != null) { lineLocation = wall.Location as LocationCurve; } if (ptLocation != null) { XYZ oldPlace = ptLocation.Point; //move an element, we provide two method, either of them works //ElementTransformUtils.MoveElement(doc, elem.Id, translationVector); ptLocation.Move(translationVector); //record the final coordinate XYZ newPlace = ptLocation.Point; //return the info as a string sb.AppendLine("the coordinate before translation:"); sb.AppendLine(oldPlace.ToString()); sb.AppendLine("the coordinate after translation:"); sb.AppendLine(newPlace.ToString()); } else //(lineLocation != null) { lineLocation.Move(translationVector); Line line = lineLocation.Curve as Line; XYZ oldPlace1 = line.GetEndPoint(0); XYZ oldPlace2 = line.GetEndPoint(1); //move an element, we provide two method, either of them works //ElementTransformUtils.MoveElement(doc, elem.Id, translationVector); lineLocation.Move(translationVector); //record the final coordinate XYZ newPlace1 = line.GetEndPoint(0); XYZ newPlace2 = line.GetEndPoint(1); //return the info as a string sb.AppendLine("the coordinate of start point before translation:"); sb.AppendLine(oldPlace1.ToString()); sb.AppendLine("the coordinate of start point before translation:"); sb.AppendLine(oldPlace2.ToString()); sb.AppendLine("the coordinate of end point before translation:"); sb.AppendLine(newPlace1.ToString()); sb.AppendLine("the coordinate of end point before translation:"); sb.AppendLine(newPlace2.ToString()); } return(sb.ToString()); }