Example #1
0
        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;
            var view  = doc.ActiveView;

            if (view.ViewType != ViewType.FloorPlan &&
                view.ViewType != ViewType.Elevation)
            {
                PmSoft.Common.Controls.PMMessageBox.Show("需选择二维视图或者图纸");
                return(Result.Cancelled);
            }
            //TODO0817 增加功能面板启动时获取字体高度
            VLTransactionHelper.DelegateTransaction(doc, "获取字体高度", () =>
            {
                PAContext.LoadFamilySymbols(doc);
                return(true);
            });
            PAContext.LoadTextHeight(doc);

            PipeAnnotationForm form = new PipeAnnotationForm(new PipeAnnotationCmd(uiApp));

            System.Windows.Forms.DialogResult result = System.Windows.Forms.DialogResult.Retry;
            while ((result = form.ShowDialog()) == System.Windows.Forms.DialogResult.Retry)
            {
                switch (form.ActionType)
                {
                case ActionType.SelectSinglePipe:
                    var selectedId = uiDoc.Selection.PickObject(ObjectType.Element, new PipeFramingFilter()).ElementId;
                    form.SelectedElementIds.Clear();
                    form.SelectedElementIds.Add(selectedId);
                    form.FinishSelection();
                    break;

                case ActionType.SelectMultiplePipe:
                    var selectedIds = uiDoc.Selection.PickObjects(ObjectType.Element, new PipeFramingFilter()).Select(c => c.ElementId);
                    form.SelectedElementIds.Clear();
                    form.SelectedElementIds.AddRange(selectedIds);
                    form.FinishSelection();
                    break;

                default:
                    break;
                }
            }
            return(Result.Succeeded);
        }