public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { var uiapp = commandData.Application; var uidoc = uiapp.ActiveUIDocument; var doc = uidoc.Document; var acview = doc.ActiveView; var sel = uidoc.Selection; _doc = doc; doc.Application.DocumentChanged += OnDocumentChanged; ResultShow resultshowwin = ResultShow.Instance; resultshowwin.helper().Owner = RevitWindowHelper.GetRevitHandle(); ResultShow.Instance.Show(); uiapp.PostCommand(RevitCommandId.LookupPostableCommandId(PostableCommand.ModelLine)); return(Result.Succeeded); }
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; var toolwin = MepcurveRank.Instance; toolwin.helper().Owner = RevitWindowHelper.GetRevitHandle(); toolwin.Show(); //显示窗体 当点击窗体的 一键分布的时候 向revit窗体发送esc按键 结束 while循环 var elelist = new List <ElementId>(); while (true) { try { var eleref = sel.PickObject(ObjectType.Element, doc.GetSelectionFilter(m => m is MEPCurve)); elelist.Add(eleref.ElementId); } catch (Exception e) { break; } } var dis = default(double); var parseresult = double.TryParse(toolwin.horizontalDis.Text, out dis); if (!parseresult) { MessageBox.Show("间距设置错误"); return(Result.Cancelled); } //以第一根管不动 其他管 紧跟第一根管排列 var meplist = elelist.Select(m => m.GetElement(doc) as MEPCurve).ToList(); var stablemep = meplist.First(); Transaction ts = new Transaction(doc, "***********"); try { ts.Start(); for (int i = 0; i < meplist.Count; i++) { if (i == 0) { continue; } var temdis = dis.MetricToFeet() * i; var originaldir = -getprojectdir(meplist[i], stablemep); var originaldis = getHorizontalDis(meplist[i], stablemep); var moveVec = (temdis - originaldis) * originaldir; ElementTransformUtils.MoveElement(doc, meplist[i].Id, moveVec); } ts.Commit(); } catch (Exception e) { MessageBox.Show(e.ToString()); if (ts.GetStatus() == TransactionStatus.Started) { ts.RollBack(); } //throw; } return(Result.Succeeded); }