public override void Execute() { var viewType = (AnalysisViewType)Enum.Parse(typeof(AnalysisViewType), ViewType.ToString()); switch (viewType) { case AnalysisViewType.Idle: View = new AnalysisWindow(this); View.ShowDialog(); break; case AnalysisViewType.Close: View.Close(); break; case AnalysisViewType.DisplayGeometry: View.Close(); if (!VLHookHelper.DelegateKeyBoardHook(() => { Model.TargetId = UIDocument.Selection.PickObject(ObjectType.Element, "请选择对象").ElementId; })) { Model.TargetId = null; ViewType = (int)AnalysisViewType.Idle; } if (VLTransactionHelper.DelegateTransaction(Document, "DisplayGeometry", () => { if (Model.TargetId == null) { return(false); } if (string.IsNullOrEmpty(RootPath)) { MessageHelper.TaskDialogShow("根路径不能为空"); return(false); } Model.Document = Document; Model.RootPath = RootPath; Model.DisplayName = ViewType.ToString(); Model.DisplayGeometry(); AnalysisContext.SaveCollection(Document); return(true); })) { ViewType = (int)AnalysisViewType.DisplayGeometry; } else { ViewType = (int)AnalysisViewType.Idle; } Execute(); break; default: throw new NotImplementedException("功能未实现"); } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { var uiApp = commandData.Application; var app = commandData.Application.Application; var uiDoc = commandData.Application.ActiveUIDocument; var doc = commandData.Application.ActiveUIDocument.Document; List <ElementId> elementIds = new List <ElementId>(); VLHookHelper.DelegateMouseHook(() => { elementIds = uiDoc.Selection.PickObjects(ObjectType.Element, new VLClassesFilter(false, typeof(Pipe), typeof(Duct), typeof(CableTray), typeof(Conduit) ), "选择要添加的构件").Select(c => c.ElementId).ToList(); }); if (elementIds == null || elementIds.Count() < 2) { return(Result.Failed); } var selectedElements = elementIds.Select(c => doc.GetElement(c)).ToList(); AvoidElementManager manager = new AvoidElementManager(uiApp); manager.AddElements(selectedElements); VLTransactionHelper.DelegateTransaction(doc, "调研_单点避让", () => { manager.CheckConflict(); manager.AutoAvoid(doc); return(true); }); VLTransactionHelper.DelegateTransaction(doc, "调研_单点避让", () => { var result = string.Join(",", manager.ConnectionNodes.Select(c => c.MEPCurve1.Id + "->" + c.MEPCurve2.Id)); var service = new MEPCurveConnectControlService(uiApp); foreach (var ConnectionNode in manager.ConnectionNodes) { try { service.NewTwoFitting(ConnectionNode.MEPCurve1, ConnectionNode.MEPCurve2, null); doc.Regenerate(); } catch (System.Exception ex) { VLLogHelper.Error(string.Format("Node1:{0},Node2:{1},Error:{2}", ConnectionNode.MEPCurve1.Id, ConnectionNode.MEPCurve2.Id, ex.Message)); var error = ex.ToString(); } } return(true); }); return(Result.Succeeded); }
public override void Execute() { var viewType = (CMViewType)Enum.Parse(typeof(CMViewType), ViewType.ToString()); switch (viewType) { case CMViewType.Idle: View = new CMWindow(this); View.ShowDialog(); break; case CMViewType.Close: View.Close(); //SaveSetting(); break; case CMViewType.Closing: //SaveSetting(); break; case CMViewType.PickSinglePipe_Pipe: View.Close(); if (!VLHookHelper.DelegateKeyBoardHook(() => { //业务逻辑处理 //选择符合类型的过滤 var targetType = Model.GetFilter(); Model.TargetIds = new List <ElementId>() { UIDocument.Selection.PickObject(ObjectType.Element, targetType, "请选择管道标注点").ElementId }; if (Model.TargetIds.Count > 0) { ViewType = (int)CMViewType.PickSinglePipe_Location; } })) { ViewType = (int)CMViewType.Idle; } Execute(); break; case CMViewType.PickSinglePipe_Location: if (!VLHookHelper.DelegateKeyBoardHook(() => { ////业务逻辑处理 //var target = Document.GetElement(Model.TargetIds.First()); //var targetLocation = target.Location as LocationCurve; //var p0 = targetLocation.Curve.GetEndPoint(0); //var p1 = targetLocation.Curve.GetEndPoint(1); //var pStart = new XYZ((p0.X + p1.X) / 2, (p0.Y + p1.Y) / 2, (p0.Z + p1.Z) / 2); //var pEnd = new VLPointPicker().PickPointWithLinePreview(UIApplication, pStart); //if (pEnd == null) // ViewType = CMViewType.Idle; //else // ViewType = CMViewType.GenerateSinglePipe; })) { ViewType = (int)CMViewType.Idle; } Execute(); break; case CMViewType.GenerateSinglePipe: if (TransactionUtils.DelegateTransaction(Document, "GenerateSinglePipe", (Func <bool>)(() => { var element = Document.GetElement(Model.TargetIds.First()); var Collection = CMContext.GetCollection(Document); //避免重复生成 由于一个对象可能在不同的视图中进行标注设置 所以还是需要重复生成的 var existedModels = Collection.Data.Where(c => c.TargetIds.Intersect(Model.TargetIds, new ElementIdComparer()) != null); if (existedModels != null) { foreach (var existedModel in existedModels) { Collection.Data.Remove(existedModel); CMContext.Creator.Clear(Document, existedModel); } } CMContext.Creator.Generate(Document, Model, element); Collection.Data.Add(Model); Collection.Save(Document); return(true); }))) { ViewType = (int)CMViewType.PickSinglePipe_Pipe; } else { ViewType = (int)CMViewType.Idle; } Execute(); break; default: throw new NotImplementedException("功能未实现"); } }
public override void Execute() { PBPAModelCollection collection; var viewType = (PBPAViewType)Enum.Parse(typeof(PBPAViewType), ViewType.ToString()); switch (viewType) { case PBPAViewType.Idle: View = new PBPAWindow(this); View.ShowDialog(); break; case PBPAViewType.Close: View.Close(); SaveSetting(); break; case PBPAViewType.Closing: SaveSetting(); break; case PBPAViewType.RegenerateAllFor_L: VLTransactionHelper.DelegateTransaction(Document, "RegenerateAllFor_L", (Func <bool>)(() => { collection = PBPAContext.GetCollection(Document); for (int i = collection.Data.Count - 1; i >= 0; i--) { var model = collection.Data[i]; model.Document = Document; model.IsRegenerate = true; var element = Document.GetElement(model.TargetId); element.GetParameters(PBPAContext.SharedParameterPL).FirstOrDefault().Set(model.GetFull_L(element)); if (!PBPAContext.Creator.Regenerate(model)) { collection.Data.Remove(model); } } collection.Save(Document); return(true); })); ViewType = (int)PBPAViewType.Idle; break; case PBPAViewType.PickSingle_Target: UpdateSetting(); MemoHelper.UpdateDifference(Document, Setting, false); Model.Document = Document; Model.ViewId = Document.ActiveView.Id; View.Close(); if (!VLHookHelper.DelegateKeyBoardHook(() => { //业务逻辑处理 //选择符合类型的过滤 UpdateModelTargetType(); var targetType = Model.GetFilter(); var obj = UIDocument.Selection.PickObject(ObjectType.Element, targetType, "请选择标注点"); if (obj != null) { Model.TargetId = obj.ElementId; Model.TargetType = Model.IsPunch(Document.GetElement(obj.ElementId)) ? PBPATargetType.Punch : PBPATargetType.BranchPipe; ViewType = (int)PBPAViewType.PickSingle_End; Model.BodyStartPoint = obj.GlobalPoint; } })) { ViewType = (int)PBPAViewType.Idle; } //获取族内参数信息 if (!GetFamilySymbolInfo(Model.TargetId)) { ShowMessage("加载族信息失败"); ViewType = (int)PBPAViewType.Idle; Execute(); return; } Model.CurrentFontWidthSize = PBPAContext.FontManagement.CurrentFontWidthSize; Execute(); break; case PBPAViewType.PickSingle_End: //业务逻辑处理 if (!VLHookHelper.DelegateKeyBoardHook(() => { //var locationCurve = (target.Location as LocationCurve).Curve as Line; //XYZ vVector, pVector; //VLLocationHelper.GetVectors(locationCurve, CoordinateType.XY, out vVector, out pVector); #region 平面+立面支持 //CoordinateType coordinateType; //coordinateType = VLLocationHelper.GetCoordinateType(Document); //Model.CoordinateType = coordinateType; //var hVector = coordinateType.GetParallelVector(); //hVector = VLLocationHelper.GetVectorByQuadrant(hVector, QuadrantType.OneAndFour, coordinateType); //var vVector = VLLocationHelper.GetVerticalVector(hVector); //vVector = VLLocationHelper.GetVectorByQuadrant(vVector, QuadrantType.OneAndFour, coordinateType); #endregion VLCoordinateType coordinateType = VLCoordinateType.XY; Model.UpdateVector(coordinateType); var target = Document.GetElement(Model.TargetId); Model.UpdateLineWidth(target); var startPoint = Model.BodyStartPoint.ToWindowsPoint(coordinateType); var offSet = (Model.LineWidth * Model.ParallelVector).ToWindowsPoint(); //var endPoint = (Model.BodyStartPoint + Model.LineWidth * 1.02 * Model.ParallelVector).ToWindowsPoint(coordinateType); var pEnd = new VLPointPicker().PickPointWithPreview(UIApplication, coordinateType, (view) => { var mousePosition = System.Windows.Forms.Control.MousePosition; var midDrawP = new System.Windows.Point(mousePosition.X - view.Left, mousePosition.Y - view.Top); //中间选择点 var midPoint = view.ConvertToRevitPointFromDrawPoint(midDrawP); var startDrawP = view.ConvertToDrawPointFromRevitPoint(startPoint); //起点 var M_S = midPoint - Model.BodyStartPoint; if (Model.AnnotationType == PBPAAnnotationType.OneLine || Model.ParallelVector.CrossProductByCoordinateType(M_S, VLCoordinateType.XY) > 0) { var endPoint = startPoint.Plus(offSet); var endP = view.ConvertToDrawPointFromRevitPoint(endPoint); //终点 if (Math.Abs(startDrawP.X - midDrawP.X) < 2 && Math.Abs(startDrawP.Y - midDrawP.Y) < 2) { return; } var mid_s = midDrawP - startDrawP; mid_s.Normalize(); var midSDrawP = midDrawP - mid_s * view.co_s; var height = midDrawP - startDrawP; var endDrawP = endP + height; var mid_e = midDrawP - endDrawP; mid_e.Normalize(); var midEDrawP = midDrawP - mid_e * view.co_e; if (double.IsNaN(midEDrawP.X)) { return; } var canvas = view.canvas; canvas.Children.RemoveRange(0, canvas.Children.Count); var line = new System.Windows.Shapes.Line() { X1 = startDrawP.X, Y1 = startDrawP.Y, X2 = midSDrawP.X, Y2 = midSDrawP.Y, Stroke = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(136, 136, 136)), StrokeThickness = 1 }; var line2 = new System.Windows.Shapes.Line() { X1 = midEDrawP.X, Y1 = midEDrawP.Y, X2 = endDrawP.X, Y2 = endDrawP.Y, Stroke = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(136, 136, 136)), StrokeThickness = 1 }; System.Windows.Media.RenderOptions.SetBitmapScalingMode(line, System.Windows.Media.BitmapScalingMode.LowQuality); System.Windows.Media.RenderOptions.SetBitmapScalingMode(line2, System.Windows.Media.BitmapScalingMode.LowQuality); canvas.Children.Add(line); canvas.Children.Add(line2); Model.IsReversed = false; } else { var endPoint = startPoint.Minus(offSet); var endP = view.ConvertToDrawPointFromRevitPoint(endPoint); //终点 if (Math.Abs(startDrawP.X - midDrawP.X) < 2 && Math.Abs(startDrawP.Y - midDrawP.Y) < 2) { return; } var mid_s = midDrawP - startDrawP; mid_s.Normalize(); var midSDrawP = midDrawP - mid_s * view.co_s; var height = midDrawP - startDrawP; var endDrawP = endP + height; var mid_e = midDrawP - endDrawP; mid_e.Normalize(); var midEDrawP = midDrawP - mid_e * view.co_e; if (double.IsNaN(midEDrawP.X)) { return; } var canvas = view.canvas; canvas.Children.RemoveRange(0, canvas.Children.Count); var line = new System.Windows.Shapes.Line() { X1 = startDrawP.X, Y1 = startDrawP.Y, X2 = midSDrawP.X, Y2 = midSDrawP.Y, Stroke = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(136, 136, 136)), StrokeThickness = 1 }; var line2 = new System.Windows.Shapes.Line() { X1 = midEDrawP.X, Y1 = midEDrawP.Y, X2 = endDrawP.X, Y2 = endDrawP.Y, Stroke = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(136, 136, 136)), StrokeThickness = 1 }; System.Windows.Media.RenderOptions.SetBitmapScalingMode(line, System.Windows.Media.BitmapScalingMode.LowQuality); System.Windows.Media.RenderOptions.SetBitmapScalingMode(line2, System.Windows.Media.BitmapScalingMode.LowQuality); canvas.Children.Add(line); canvas.Children.Add(line2); Model.IsReversed = true; } }); if (pEnd == null) { ViewType = (int)PBPAViewType.Idle; } else { Model.BodyEndPoint = pEnd.ToSame(Model.BodyStartPoint, coordinateType); ViewType = (int)PBPAViewType.GenerateSingle; } })) { ViewType = (int)PBPAViewType.Idle; } Execute(); break; case PBPAViewType.GenerateSingle: //生成处理 if (VLTransactionHelper.DelegateTransaction(Document, "GenerateSingle", (Func <bool>)(() => { #region 生成处理 collection = PBPAContext.GetCollection(Document); var existedModels = collection.Data.Where(c => Model.TargetId == c.TargetId).ToList(); //避免重复生成 if (existedModels != null) { for (int i = existedModels.Count() - 1; i >= 0; i--) { existedModels[i].Document = Document; collection.Data.Remove(existedModels[i]); existedModels[i].Clear(); } } if (!PBPAContext.Creator.Generate(Model)) { return(false); } collection.Data.Add(Model); collection.Save(Document); #endregion #region 共享参数设置 var element = Document.GetElement(Model.TargetId); element.GetParameters(PBPAContext.SharedParameterPL).FirstOrDefault().Set(Model.GetFull_L(element)); #endregion return(true); }))) { ViewType = (int)PBPAViewType.PickSingle_Target; } else { ViewType = (int)PBPAViewType.Idle; } Execute(); break; case PBPAViewType.GenerateAll: default: throw new NotImplementedException("功能未实现"); } }