Ejemplo n.º 1
0
        /// <summary> 从两个选项中选择一个 </summary>
        /// <param name="docMdf"></param>
        /// <returns>true 表示按顶点缩放(默认值),false 表示按长度缩放</returns>
        private static bool SetNewText(DocumentModifier docMdf, out string newText, out bool changeSingle)
        {
            changeSingle = true;
            newText      = "";
            var op = new PromptStringOptions(message: "\n设置要放置的防护方式字符[多个(M)]:"); // 默认值写在前面

            op.AllowSpaces = false;

            var res = docMdf.acEditor.GetString(op);

            if (res.Status == PromptStatus.OK)
            {
                if (res.StringResult.Equals("m", StringComparison.CurrentCultureIgnoreCase))
                {
                    changeSingle = false;
                    newText      = SetNewText(docMdf);
                }
                else
                {
                    changeSingle = true;
                    newText      = res.StringResult;
                }
                if (newText == null)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        public ExternalCommandResult Execute(SelectionSet impliedSelection, ref string errorMessage,
                                             ref IList <ObjectId> elementSet)
        {
            var dat = new DllActivator_eZcad();

            dat.ActivateReferences();

            using (var docMdf = new DocumentModifier(true))
            {
                try
                {
                    DoSomething(docMdf, impliedSelection);
                    //
                    docMdf.acTransaction.Commit();
                    return(ExternalCommandResult.Succeeded);
                }
                catch (Exception ex)
                {
                    docMdf.acTransaction.Abort(); // Abort the transaction and rollback to the previous state
                    errorMessage = ex.Message + "\r\n\r\n" + ex.StackTrace;
                    return(ExternalCommandResult.Failed);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary> 从 AutoCAD 界面中选择横断面轴线 </summary>
        public static SubgradeSection GetSection(DocumentModifier docMdf, out bool cont)
        {
            cont = true;
            SubgradeSection sec = null;
            var             op  = new PromptEntityOptions("\n选择要提取的横断面轴线");

            op.SetRejectMessage("\n选择要提取的横断面轴线");
            op.AddAllowedClass(typeof(Line), true);

            var res = docMdf.acEditor.GetEntity(op);

            if (res.Status == PromptStatus.OK)
            {
                var line = res.ObjectId.GetObject(OpenMode.ForRead) as Line;
                if (line != null && line.Layer == Options_LayerNames.LayerName_CenterAxis)
                {
                    var si = SectionInfo.FromCenterLine(line);
                    if (si != null && si.FullyCalculated)
                    {
                        sec = new SubgradeSection(docMdf, line, si);
                    }
                    else
                    {
                        MessageBox.Show($"选择的道路中心线对象所对应的横断面未进行构造," +
                                        $"\r\n请先调用“{SectionsConstructor.CommandName}”命令,以构造整个项目的横断面系统。",
                                        "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        cont = false;
                    }
                }
            }
            else if (res.Status == PromptStatus.Cancel)
            {
                cont = false;
            }
            return(sec);
        }
Ejemplo n.º 4
0
        private bool SetBlockRefAttibute(DocumentModifier docMdf, string attTag, int tagNum)
        {
            var bkr = PickBlockRef(docMdf);

            if (bkr != null)
            {
                foreach (ObjectId attId in bkr.AttributeCollection)
                {
                    var att = docMdf.acTransaction.GetObject(attId, OpenMode.ForRead) as AttributeReference;
                    if (att != null && att.Tag == attTag)
                    {
                        att.UpgradeOpen();
                        att.TextString = tagNum.ToString();
                        att.DowngradeOpen();

                        // 将修改后的结果在界面中显示
                        att.Draw();
                        // docMdf.acEditor.UpdateScreen();
                        return(true);
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 5
0
        public static List <Line> GetCentralizedDimLine(DocumentModifier docMdf)
        {
            // Create our options object
            var op = new PromptSelectionOptions();

            // Set our prompts to include our keywords
            string kws = op.Keywords.GetDisplayString(true);

            op.MessageForAdding  = "\n选择集中标注线" + kws; // 当用户在命令行中输入A(或Add)时,命令行出现的提示字符。
            op.MessageForRemoval = op.MessageForAdding;
            // 当用户在命令行中输入Re(或Remove)时,命令行出现的提示字符。

            // Implement a callback for when keywords are entered
            var filterTypes = new TypedValue[]
            {
                new TypedValue((int)DxfCode.Start, "LINE"),
                new TypedValue((int)DxfCode.LayerName, "集中标注线")
            };
            var lines = new List <Line>();
            // Finally run the selection and show any results
            var res = docMdf.acEditor.GetSelection(op, new SelectionFilter(filterTypes));

            if (res.Status == PromptStatus.OK)
            {
                var ids = res.Value.GetObjectIds();
                foreach (var id in ids)
                {
                    var o = id.GetObject(OpenMode.ForRead) as Line;
                    if (o != null)
                    {
                        lines.Add(o);
                    }
                }
            }
            return(lines);
        }
Ejemplo n.º 6
0
        private BlockReference PickBlockRef(DocumentModifier docMdf)
        {
            // 点选
            var peO = new PromptEntityOptions("\n 选择一个块 ");

            peO.SetRejectMessage("\n 请选择一个包含有属性的块参照对象\n");
            peO.AddAllowedClass(typeof(BlockReference), false);

            // 请求在图形区域选择对象
            var res = docMdf.acEditor.GetEntity(peO);

            BlockReference curve = null;

            // 如果提示状态OK,表示对象已选
            if (res.Status == PromptStatus.OK)
            {
                curve = docMdf.acTransaction.GetObject(res.ObjectId, OpenMode.ForRead) as BlockReference;
            }
            else
            {
                return(null);
            }
            return(curve);
        }
Ejemplo n.º 7
0
        public void GetRoadStation(DocumentModifier docMdf, SelectionSet impliedSelection)
        {
            _docMdf = docMdf;
            Curve baseCurve = null;

            if (impliedSelection != null)
            {
                foreach (var id in impliedSelection.GetObjectIds())
                {
                    baseCurve = docMdf.acTransaction.GetObject(id, OpenMode.ForRead) as Curve;
                    if (baseCurve != null)
                    {
                        break;
                    }
                }
            }
            if (baseCurve == null)
            {
                baseCurve = PickOneCurve(docMdf);
            }
            if (baseCurve == null)
            {
                return;
            }

            // 在界面中选择一个点,并生成对应位置处曲线的垂线
            Point3d?pt = PickPoint(docMdf.acEditor, baseCurve);

            while (pt != null)
            {
                //
                WriteStation(docMdf.acEditor, baseCurve, pt.Value);
                //
                pt = PickPoint(docMdf.acEditor, baseCurve);
            }
        }
Ejemplo n.º 8
0
        /// <summary> 点击界面中的点以生成对应的标高 </summary>
        private ExternalCmdResult PlaceElevation(DocumentModifier docMdf, SelectionSet impliedSelection)
        {
            // 以只读方式打开块表   Open the Block table for read
            var acBlkTbl =
                docMdf.acTransaction.GetObject(docMdf.acDataBase.BlockTableId, OpenMode.ForRead) as BlockTable;

            // 以写方式打开模型空间块表记录   Open the Block table record Model space for write
            var acBlkTblRec =
                docMdf.acTransaction.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as
                BlockTableRecord;

            var pt = GetElevationPoint(docMdf);

            while (pt != null)
            {
                var ele = pt.Value.Y / 1000;
                var txt = new DBText
                {
                    TextString  = ele.ToString("000.000"),
                    Position    = pt.Value,
                    Height      = 1000,
                    WidthFactor = 0.7
                };
                // txt.SetDatabaseDefaults();

                // 添加新对象到块表记录和事务中   Add the new object to the block table record and the transaction
                acBlkTblRec.AppendEntity(txt);
                docMdf.acTransaction.AddNewlyCreatedDBObject(txt, true);

                txt.Draw();

                pt = GetElevationPoint(docMdf);
            }

            return(ExternalCmdResult.Commit);
        }
Ejemplo n.º 9
0
        /// <summary> 在新选择集中过滤出与当前选择集不相交的对象 </summary>
        private ExternalCmdResult AlignDim(DocumentModifier docMdf, SelectionSet impliedSelection)
        {
            var c = PickOneCurve(docMdf);

            if (c == null)
            {
                return(ExternalCmdResult.Cancel);
            }
            c.Highlight();
            //
            var dims = SelectDims(docMdf);

            c.Unhighlight();
            if (dims == null || dims.Length == 0)
            {
                return(ExternalCmdResult.Cancel);
            }
            //
            foreach (var dimId in dims)
            {
                var dim = docMdf.acTransaction.GetObject(dimId, OpenMode.ForRead);
                if ((dim is RotatedDimension))
                {
                    dim.UpgradeOpen();
                    AlignDimsToLine(docMdf, dim as RotatedDimension, c);
                    dim.DowngradeOpen();
                }
                else if (dim is AlignedDimension)
                {
                    dim.UpgradeOpen();
                    AlignDimsToLine(docMdf, dim as AlignedDimension, c);
                    dim.DowngradeOpen();
                }
            }
            return(ExternalCmdResult.Commit);
        }
Ejemplo n.º 10
0
 public void EraseSlope()
 {
     DocumentModifier.ExecuteCommand(EraseSlope);
 }
Ejemplo n.º 11
0
 public void SlopeWalk()
 {
     DocumentModifier.ExecuteCommand(SlopeWalk);
 }
Ejemplo n.º 12
0
 public void TextRegex()
 {
     DocumentModifier.ExecuteCommand(EditEntityAnnotation);
 }
Ejemplo n.º 13
0
 public void ConvertDBTextsToMText()
 {
     DocumentModifier.ExecuteCommand(ConvertDBTextsToMText);
 }
Ejemplo n.º 14
0
        // 开始具体的调试操作
        private ExternalCmdResult CreateViewport(DocumentModifier docMdf, SelectionSet impliedSelection)
        {
            _docMdf = docMdf;

            //// var vp1 = AddinManagerDebuger.PickObject<Entity>(docMdf.acEditor);
            //var hd = Utils.ConvertToHandle("AA07");
            //var vp2 = hd.GetObjectId(docMdf.acDataBase).GetObject(OpenMode.ForRead) as Viewport;
            //vp2.UpgradeOpen();
            //var lot = LayoutManager.Current.GetLayoutId("NewLayout4011").GetObject(OpenMode.ForRead) as Layout;
            //vp2.RotateViewport(_docMdf, lot, new Point2d(0, 0), 30.0 / 180 * Math.PI);

            //return ExternalCmdResult.Commit;
            // 从模型空间中获取视口裁剪框
            var     pl_Model      = SelectUtils.PickEntity <Curve>(docMdf.acEditor);
            Point3d bottomLeftPt  = default(Point3d);
            Point3d bottomRightPt = default(Point3d);
            double  bottomLength  = 0;
            var     succ          = GraphicalElementsSelector.GetPoint(docMdf.acEditor, "选择图纸的左下角点", out bottomLeftPt);

            if (!succ)
            {
                return(ExternalCmdResult.Cancel);
            }
            succ = GraphicalElementsSelector.GetPoint(docMdf.acEditor, "选择图纸的右下角点", out bottomRightPt);
            if (!succ)
            {
                return(ExternalCmdResult.Cancel);
            }
            succ = GraphicalElementsSelector.GetDouble(docMdf.acEditor, "图纸宽度(布局空间的单位)", out bottomLength,
                                                       defaultValue: 420, allowNegative: false);
            if (!succ)
            {
                return(ExternalCmdResult.Cancel);
            }

            var modelUcs = docMdf.acEditor.GetCurrentView().Ucs;

            // 打开布局
            var               lm = LayoutManager.Current;
            Layout            layout;
            ObjectId          layoutId;
            Form_LayoutLister f = new Form_LayoutLister(docMdf);

            f.ShowDialog();
            if (f.CreateNewLayout)
            {
                //
                MessageBox.Show("请先自行创建带图框的布局");
                return(ExternalCmdResult.Cancel);

                /*
                 * var layoutName = "NewLayout" + DateTime.Now.Minute + DateTime.Now.Second;
                 * layoutId = lm.GetLayoutId(layoutName);
                 * if (!layoutId.IsValid)
                 * {
                 *  // 重启事务
                 *  docMdf.RestartTransaction(commitCancel: false);
                 *  //
                 *  layoutId = LayoutUtil.CreateLayout(layoutName);
                 *  layout = layoutId.GetObject(OpenMode.ForRead) as Layout;
                 *  //
                 *  LayoutUtil.SetPlotSettings(layout, "A3", "monochrome.ctb", "交通院道路室 121");
                 * }
                 * else
                 * {
                 *  layout = LayoutManager.Current.GetLayoutId(name: layoutName).GetObject(OpenMode.ForRead) as Layout;
                 * }
                 */
            }
            else if (f.Layout != null)
            {
                layout = f.Layout;
            }
            else
            {
                return(ExternalCmdResult.Cancel);
            }

            // docMdf.RestartTransaction(true);
            // 切换布局
            // lm.SetCurrentLayoutId(layout.Id); // AutoCAD 2016
            lm.CurrentLayout = layout.LayoutName;

            // 创建视口
            CreateViewport(docMdf, modelUcs, layout, pl_Model, bottomLeftPt, bottomRightPt, bottomLength);

            // 切换回模型空间
            // Autodesk.AutoCAD.ApplicationServices.Core.Application.SetSystemVariable("TILEMODE", 1);
            // LayoutUtil.SwitchLayout();
            return(ExternalCmdResult.Commit);
        }
Ejemplo n.º 15
0
        /// <summary> 沿着道路纵向绘制边坡线 </summary>
        public ExternalCmdResult LongitudinalSection(DocumentModifier docMdf, SelectionSet impliedSelection)
        {
            _docMdf = docMdf;
            SQUtils.SubgradeEnvironmentConfiguration(docMdf);
            var allSections = SQUtils.GetAllSections(docMdf, sort: true);

            if (allSections == null || allSections.Length <= 2)
            {
                return(ExternalCmdResult.Cancel);
            }
            if (allSections.Length > 1)
            {
                //
                var allStations = allSections.Select(r => r.XData.Station).ToArray();
                var minStation  = allStations.First();

                //
                // 每一个桩号所对应的某一侧的挡墙顶与挡墙底相对于道路中线的高度,如果某桩号中没有挡墙,则其值为 null
                var leftRetainingWalls  = new Dictionary <double, double[]>();
                var rightRetainingWalls = new Dictionary <double, double[]>();
                var leftSlps            = ConstructLeftSlope(allSections, true, out leftRetainingWalls);
                var rightSlps           = ConstructLeftSlope(allSections, false, out rightRetainingWalls);

                // 选择绘图的基点
                Point3d p3;
                var     succ = GetBasePt(_docMdf, out p3);
                if (!succ)
                {
                    return(ExternalCmdResult.Cancel);
                }

                var basePt2D = new Point2d(p3.X, p3.Y);
                //
                double rx = 0.25;
                double ry = 2;
                //
                var ss = EditStateIdentifier.GetCurrentEditState(_docMdf);
                ss.CurrentBTR.UpgradeOpen();
                var layer_Slope   = SymbolTableUtils.GetOrCreateLayer(_docMdf.acTransaction, _docMdf.acDataBase, SQConstants.LayerName_LongitudinalSlopes);
                var originalLayer = docMdf.acDataBase.Clayer;
                docMdf.acDataBase.Clayer = layer_Slope.Id;

                // 绘制中轴线
                var roadCenterPl = CreatePolyline(allStations, new double[allStations.Length], basePt2D, minStation, rx,
                                                  ry);
                ss.CurrentBTR.AppendEntity(roadCenterPl);
                _docMdf.acTransaction.AddNewlyCreatedDBObject(roadCenterPl, true);
                // 绘制桩号
                var txts = CreateDbTexts(allStations, new double[allStations.Length], basePt2D, minStation, rx, ry);
                foreach (var txt in txts)
                {
                    ss.CurrentBTR.AppendEntity(txt);
                    _docMdf.acTransaction.AddNewlyCreatedDBObject(txt, true);
                }
                // 绘制左边坡线
                var leftPl = CreatePolyline(leftSlps.Keys.ToArray(), leftSlps.Values.ToArray(), basePt2D, minStation, rx,
                                            ry);
                leftPl.LineWeight = LineWeight.LineWeight013;
                leftPl.Color      = Color.FromColor(System.Drawing.Color.Green);
                ss.CurrentBTR.AppendEntity(leftPl);
                _docMdf.acTransaction.AddNewlyCreatedDBObject(leftPl, true);
                // 绘制右边坡线
                var rightPl = CreatePolyline(rightSlps.Keys.ToArray(), rightSlps.Values.ToArray(), basePt2D, minStation,
                                             rx, ry);
                rightPl.LineWeight = LineWeight.LineWeight013;
                rightPl.Color      = Color.FromColor(System.Drawing.Color.Red);
                ss.CurrentBTR.AppendEntity(rightPl);
                _docMdf.acTransaction.AddNewlyCreatedDBObject(rightPl, true);

                // 绘制左边挡墙
                var leftRetainingWallRanges = GetRetainingWallRanges(leftRetainingWalls);
                foreach (var rwr in leftRetainingWallRanges)
                {
                    var pl = CreatePolyline(ArrayConstructor.GetColumn(rwr, 0), ArrayConstructor.GetColumn(rwr, 1),
                                            basePt2D, minStation, rx, ry);
                    pl.Closed     = true;
                    pl.Color      = Color.FromColor(System.Drawing.Color.LightGreen);
                    pl.LineWeight = LineWeight.LineWeight050;
                    ss.CurrentBTR.AppendEntity(pl);
                    _docMdf.acTransaction.AddNewlyCreatedDBObject(pl, true);
                }
                // 绘制右边挡墙
                var rightRetainingWallRanges = GetRetainingWallRanges(rightRetainingWalls);
                foreach (var rwr in rightRetainingWallRanges)
                {
                    var pl = CreatePolyline(ArrayConstructor.GetColumn(rwr, 0), ArrayConstructor.GetColumn(rwr, 1),
                                            basePt2D, minStation, rx, ry);
                    pl.Closed     = true;
                    pl.Color      = Color.FromColor(System.Drawing.Color.DeepPink);
                    pl.LineWeight = LineWeight.LineWeight050;
                    ss.CurrentBTR.AppendEntity(pl);
                    _docMdf.acTransaction.AddNewlyCreatedDBObject(pl, true);
                }
                //
                docMdf.acDataBase.Clayer = originalLayer;
                ss.CurrentBTR.DowngradeOpen();
            }
            return(ExternalCmdResult.Commit);
        }
Ejemplo n.º 16
0
 public void ShowClassName()
 {
     DocumentModifier.ExecuteCommand(ShowClassName);
 }
Ejemplo n.º 17
0
 public void LongitudinalSection()
 {
     DocumentModifier.ExecuteCommand(LongitudinalSection);
 }
Ejemplo n.º 18
0
 public void SetSubgradeEnvir()
 {
     DocumentModifier.ExecuteCommand(SetSubgradeEnvir);
 }
Ejemplo n.º 19
0
 public void CreateViewport()
 {
     DocumentModifier.ExecuteCommand(CreateViewport);
 }
Ejemplo n.º 20
0
 public static void ClearXData(DocumentModifier docMdf, DatabaseXdataType xdataType)
 {
 }
Ejemplo n.º 21
0
        private static void ConvertInManualMode(DocumentModifier docMdf)
        {
            MText  mTxt = null;
            DBText txt  = null;

            txt = PickDbText(docMdf);
            double mTextWidth = 0;

            if (txt != null)
            {
                txt.Highlight(); // 让此文字显示为被选中的状态
                mTextWidth = txt.TextString.Length * txt.Height * txt.WidthFactor;
                // 以只读方式打开块表   Open the Block table for read
                var acBlkTbl =
                    docMdf.acTransaction.GetObject(docMdf.acDataBase.BlockTableId, OpenMode.ForRead) as BlockTable;

                // 以写方式打开模型空间块表记录   Open the Block table record Model space for write
                var acBlkTblRec =
                    docMdf.acTransaction.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as
                    BlockTableRecord;

                mTxt = new MText()
                {
                    Contents   = txt.TextString,
                    Location   = new Point3d(txt.Position.X, txt.Position.Y + txt.Height, txt.Position.Z),
                    Width      = mTextWidth,
                    TextHeight = txt.Height,
                };
                // 刷格式
                mTxt.SetPropertiesFrom(txt);

                acBlkTblRec.AppendEntity(mTxt);
                docMdf.acTransaction.AddNewlyCreatedDBObject(mTxt, true);

                txt.UpgradeOpen();
                txt.Erase(true);
            }
            //
            if (mTxt != null)
            {
                //
                txt = PickDbText(docMdf);
                while (txt != null)
                {
                    txt.Highlight(); // 让此文字显示为被选中的状态

                    double dbTxtWidth = txt.TextString.Length * txt.Height * txt.WidthFactor;

                    if (dbTxtWidth > mTextWidth)
                    {
                        mTextWidth = dbTxtWidth;
                        mTxt.Width = mTextWidth;
                    }
                    mTxt.Contents += "\\P" + txt.TextString; // “\P”为 MText 中专门用来表示换行的符号
                    // mTxt.Draw();
                    //
                    txt.UpgradeOpen();
                    txt.Erase(true);
                    docMdf.acEditor.UpdateScreen();
                    //
                    txt = PickDbText(docMdf);
                }
            }
        }
Ejemplo n.º 22
0
        /// <summary> 刷新所有的全局选项到内存中 </summary>
        /// <param name="docMdf"></param>
        public static void LoadAllOptionsFromDbToMemory(DocumentModifier docMdf)
        {
            var allXdataTypes = DbXdata.GetAllXdataTypes();

            DbXdata.RefreshOptionsFromDb(docMdf, allXdataTypes);
        }
Ejemplo n.º 23
0
        private static void ConvertInAutoMode(DocumentModifier docMdf)
        {
            var texts = SelectTexts(docMdf);

            if (texts == null || texts.Length == 0)
            {
                return;
            }

            // 将选择的文字按Y坐标排序
            var    sortedTexts = new SortedDictionary <double, Entity>();
            double maxWidth    = 0;

            foreach (var txtId in texts)
            {
                double width = 0;
                var    txt   = txtId.GetObject(OpenMode.ForRead) as Entity;
                if (txt is DBText)
                {
                    var dt = txt as DBText;
                    if (!sortedTexts.ContainsKey(dt.Position.Y))
                    {
                        //
                        width    = dt.TextString.Length * dt.Height * dt.WidthFactor * 1.05; // 1.1 为放大系数
                        maxWidth = Math.Max(maxWidth, width);
                        sortedTexts.Add(dt.Position.Y, dt);
                    }
                }
                else if (txt is MText)
                {
                    var mt = txt as MText;
                    if (!sortedTexts.ContainsKey(mt.Location.Y))
                    {
                        width    = mt.ActualWidth;
                        maxWidth = Math.Max(maxWidth, width);
                        sortedTexts.Add(mt.Location.Y, mt);
                    }
                }
            }

            var sb      = new StringBuilder();
            var textsUd = sortedTexts.Reverse().ToArray(); // 第一个元素的Y坐标值最大,表示在最上方

            foreach (var v in textsUd)
            {
                var txt = v.Value;
                if (txt is DBText)
                {
                    sb.Append(TextUtils.ConvertDbTextSpecialSymbols((txt as DBText).TextString) + @"\P");
                }
                else if (txt is MText)
                {
                    sb.Append((txt as MText).Contents + @"\P");
                }
            }
            //
            var    txtHeight = 0.0;
            var    location  = new Point3d();
            Entity topText   = textsUd[0].Value;

            if (topText is DBText)
            {
                var dt = (topText as DBText);
                txtHeight = dt.Height;
                location  = new Point3d(dt.Position.X, dt.Position.Y + dt.Height, dt.Position.Z);
            }
            else if (topText is MText)
            {
                txtHeight = (topText as MText).TextHeight;
                location  = (topText as MText).Location;
            }
            // 以只读方式打开块表   Open the Block table for read
            var acBlkTbl =
                docMdf.acTransaction.GetObject(docMdf.acDataBase.BlockTableId, OpenMode.ForRead) as BlockTable;

            // 以写方式打开模型空间块表记录   Open the Block table record Model space for write
            var btr =
                docMdf.acTransaction.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as
                BlockTableRecord;

            var mTxt = new MText()
            {
                Location          = location,
                Width             = maxWidth,
                TextHeight        = txtHeight,
                LineSpacingFactor = 0.85,
                Contents          = sb.ToString(),
            };

            // 刷格式
            mTxt.SetPropertiesFrom(topText);
            //
            btr.AppendEntity(mTxt);
            docMdf.acTransaction.AddNewlyCreatedDBObject(mTxt, true);

            // 删除原来的文字
            foreach (var ent in sortedTexts.Values)
            {
                ent.UpgradeOpen();
                ent.Erase(true);
            }
        }
Ejemplo n.º 24
0
        /// <summary>构造方式一:从零开始判断与计算(不能成功构造,则返回 null)  </summary>
        /// <param name="docMdf"></param>
        /// <param name="pline"></param>
        /// <param name="errMsg"></param>
        /// <returns>如果创建失败,则返回 null </returns>
        public static SlopeLine Create(DocumentModifier docMdf, Polyline pline, out string errMsg)
        {
            errMsg = "";
            if (pline.Closed)
            {
                errMsg = "无法识别闭合的边坡对象";
                return(null);
            }

            // 找到对应的中轴线对象

            var ca = FindCenterAxisOnHandle(docMdf, pline);

            if (ca == null)
            {
                ca = FindCenterAxisOnScreen(docMdf, pline);
                if (ca == null)
                {
                    errMsg = "无法识别对应的道路中心线";
                    return(null);
                }
            }
            if (!ca.XData.FullyCalculated)
            {
                ca.CalculateSectionInfoToXData();
                //
                ca.CenterLine.UpgradeOpen();
                ca.FlushXData();
                ca.CenterLine.DowngradeOpen();
            }
            // 判断当前多段线是横断面系统中的哪一个
            var  xdata = ca.XData;
            bool slpMatchedCenterLine = false;

            if (xdata.LeftSlopeHandle == pline.Handle)
            {
                slpMatchedCenterLine = true;
                var retainingWall = xdata.LeftRetainingWallType != RetainingWallType.无
                    ? docMdf.acDataBase.GetObjectId(false, xdata.LeftRetainingWallHandle, 0).GetObject(OpenMode.ForRead)
                                    as Polyline
                    : null;
                //
                return(new SlopeLine(docMdf, pline, ca, true, ca.XData.LeftSlopeFill.Value, xdata.LeftRetainingWallType, retainingWall));
            }
            if (xdata.RightSlopeHandle == pline.Handle)
            {
                slpMatchedCenterLine = true;
                var retainingWall = xdata.RightRetainingWallType != RetainingWallType.无
                    ? docMdf.acDataBase.GetObjectId(false, xdata.RightRetainingWallHandle, 0)
                                    .GetObject(OpenMode.ForRead) as Polyline
                    : null;
                //
                return(new SlopeLine(docMdf, pline, ca, false, ca.XData.RightSlopeFill.Value, xdata.RightRetainingWallType, retainingWall));
            }
            if (!slpMatchedCenterLine)
            {
                errMsg = $"边坡线条({pline.Handle})无法匹配道路中心线(桩号 {xdata.Station})的对应的左边坡({xdata.LeftSlopeHandle})或右边坡({xdata.RightSlopeHandle})。";
            }
            else
            {
                errMsg = $"提取边坡对象出现异常,请重新通过“{SectionsConstructor.CommandName}”命令对横断面系统进行构造";
            }
            return(null);
        }
Ejemplo n.º 25
0
        /// <summary> <seealso cref="CommandDescription"/> </summary>
        public ExternalCmdResult EditEntityAnnotation(DocumentModifier docMdf, SelectionSet impliedSelection)
        {
            _docMdf = docMdf;
            //
            var ent = SelectUtils.PickEntity <Entity>(_docMdf.acEditor, "查看任意一个元素的注释");

            if (ent == null)
            {
                return(ExternalCmdResult.Commit);
            }
            AnnotationEntity.SetAppName(_docMdf);
            var annoEnt = new AnnotationEntity(ent);
            var annots  = annoEnt.ExtractAnnotsFromXdata();

            //
            annoEnt.WriteAnnotationsOnEditor(docMdf);
            bool   cont;
            Entity newEnt = null;

            do
            {
                bool   clearAnnot  = false;
                bool   editInForm  = false;
                bool   setNewValue = false;
                string newAnno     = null;
                cont = ReadEntityAnnot(docMdf.acEditor, out clearAnnot, out editInForm, out setNewValue, out newEnt);
                if (!cont)
                {
                    return(ExternalCmdResult.Commit);
                }
                //
                if (clearAnnot)
                {
                    annoEnt.ClearAnnotations();
                    _docMdf.WriteNow();
                }
                else if (editInForm)
                {
                    _docMdf.WriteNow();
                }
                else if (setNewValue)
                {
                    newAnno = annots.Count == 0 ? "" : annots[0];
                    cont    = SetAnnotations(docMdf.acEditor, ref newAnno);
                    if (!cont)
                    {
                        return(ExternalCmdResult.Commit);
                    }
                    annoEnt.SetAnnotsToXdata(newAnno);
                    //
                    annoEnt.WriteAnnotationsOnEditor(docMdf);
                }
                else
                {
                    // 选择了另一个元素
                    if (newEnt != null)
                    {
                        annoEnt = new AnnotationEntity(newEnt);
                        annots  = annoEnt.ExtractAnnotsFromXdata();
                        //
                        annoEnt.WriteAnnotationsOnEditor(docMdf);
                    }
                }
            } while (cont);

            //
            return(ExternalCmdResult.Commit);
        }
Ejemplo n.º 26
0
        /// <summary> <seealso cref="CommandDescription"/> </summary>
        public ExternalCmdResult EditEntityAnnotation(DocumentModifier docMdf, SelectionSet impliedSelection)
        {
            _docMdf = docMdf;
            //
            var ent = AddinManagerDebuger.PickObject <Entity>(docMdf.acEditor, "查看任意一个元素的注释");

            if (ent == null)
            {
                return(ExternalCmdResult.Cancel);
            }
            //
            AnnotationEntity.SetAppName(docMdf);
            var annoEnt = new AnnotationEntity(ent);
            var annots  = annoEnt.ExtractAnnotsFromXdata();

            //
            annoEnt.WriteAnnotationsOnEditor(docMdf);
            // 如果只有一行注释信息,则直接在Editor中编辑即可
            if (annots.Count <= 1)
            {
                bool   clearAnnot  = false;
                bool   editInForm  = false;
                bool   setNewValue = false;
                string newAnno     = null;
                var    succ        = GetAnnotationsKey(docMdf.acEditor, out clearAnnot, out editInForm, out setNewValue,
                                                       out newAnno);
                if (!succ)
                {
                    return(ExternalCmdResult.Cancel);
                }
                //
                if (clearAnnot)
                {
                    annoEnt.ClearAnnotations();
                }
                else if (editInForm)
                {
                }
                else if (setNewValue)
                {
                    newAnno = annots.Count == 0 ? "" : annots[0];
                    succ    = GetAnnotations(docMdf.acEditor, ref newAnno);
                    if (!succ)
                    {
                        return(ExternalCmdResult.Cancel);
                    }
                    annoEnt.SetAnnotsToXdata(newAnno);
                }
                else
                {
                    // 输入的为一般性的字符
                    // 如果为空,则保持原属性不变
                    if (!string.IsNullOrEmpty(newAnno))
                    {
                        annoEnt.SetAnnotsToXdata(newAnno);
                    }
                }
                // 新的属性值
                annoEnt.WriteAnnotationsOnEditor(docMdf);
            }
            else
            {
                // 要创建出一个窗口以进行编辑
            }
            //
            return(ExternalCmdResult.Commit);
        }
Ejemplo n.º 27
0
        private static ExternalCommandResult Execute(object exCommandIns, SelectionSet impliedSelection, ref string errorMessage, ref IList<ObjectId> errorSet)
        {
            DocumentModifier.LineFeedInCommandLine();

            ExternalCommandResult res = ExternalCommandResult.Failed;
            try
            {
                var mtd = ExCommandFinder.FindExCommandMethod(exCommandIns.GetType());
                if (mtd != null)
                {
                    // 先将焦点交给 AutoCAD 主界面
                    Application.MainWindow.Focus();
                    // ---------------------------- 执行命令 ----------------------------------------
                    object[] paras = new object[] { impliedSelection, errorMessage, errorSet };
                    res = (ExternalCommandResult)mtd.Invoke(exCommandIns, paras);
                    // 将 ref 参数的值提取出来
                    errorMessage = paras[1] as string;
                    errorSet = paras[2] as IList<ObjectId>;
                }

                // 执行操作
                // 如果在执行 Execute()方法时发现某个程序集不存在,则通过AssemblyResolve 事件手动进行加载
                // 所以,所有引用的 zengfy 自定义程序集,都必须在  Execute() 方法中调用至少一次,以解决在Form.Show()时,出现不能找到或加载前面缺失的程序集B的问题。

                // 如果不想通过 AssemblyResolve 来加载缺失的程序集的话,可以在 AddinManager 中自行设计代码,手动在 Execute() 方法之前将要引用的程序集从临时文件夹中通过 Assembly.LoadFile() 进行加载即可。
                // var exCommand = exCommandIns as ICADExCommand;
                // res = exCommand.Execute(impliedSelection, errorMessage: ref errorMessage, elementSet: ref errorSet);
            }
            catch (Exception ex)
            {
                if (string.IsNullOrEmpty(errorMessage))
                {
                    errorMessage = GetDebugMessage(ex); // ex.Message;
                }
                else
                {
                    errorMessage = errorMessage + "\n\r--------------------------------------------\n\r"
                                   + GetDebugMessage(ex); // ex.Message;
                }
                res = ExternalCommandResult.Failed;
            }

            // 对命令的结果进行处理
            switch (res)
            {
                case ExternalCommandResult.Failed:
                    {
                        // 选择出错的单元格
                        if (errorSet != null)
                        {
                            StringBuilder errorIds = new StringBuilder();
                            foreach (var id in errorSet)
                            {
                                errorIds.AppendLine(id.ObjectClass.Name);
                            }
                            errorMessage += "\r\n出错对象:\r\n " + errorIds.ToString();
                        }
                        // MessageBox.Show(errorMessage, @"外部命令执行出错", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        break;
                    }
                case ExternalCommandResult.Cancelled:
                    {
                        // 由于没有在CAD中没有事务或者回滚,所以直接结束就可以了。
                        break;
                    }
                case ExternalCommandResult.Succeeded:
                    {
                        break;
                    }
            }
            return res;
        }
Ejemplo n.º 28
0
 public void HighFillDeepCut()
 {
     DocumentModifier.ExecuteCommand(HighFillDeepCut);
 }
Ejemplo n.º 29
0
 public void GetExtension()
 {
     DocumentModifier.ExecuteCommand(GetExtension);
 }
Ejemplo n.º 30
0
        // 开始具体的调试操作
        public static ExternalCmdResult CreateViewport(DocumentModifier docMdf, SelectionSet impliedSelection)
        {
            // 打开布局
            var lm     = LayoutManager.Current;
            var layout = lm.GetLayoutId(name: "A3").GetObject(OpenMode.ForRead) as Layout;

            lm.CurrentLayout = layout.LayoutName;
            // lm.SetCurrentLayoutId(layout.Id); AutoCAD 2016
            var brt = layout.BlockTableRecordId.GetObject(OpenMode.ForRead) as BlockTableRecord;

            brt.UpgradeOpen();


            // 从模型空间中获取视口裁剪框
            var handle   = ExtensionMethods.ConvertToHandle("a31b");
            var pl_Model = handle.GetDBObject <Curve>(docMdf.acDataBase);

            // 视口的裁剪区域,此区域可以由多段线、圆弧或样条曲线等来定义,而且曲线可以不闭合。
            var layoutClipCurve = Curve.CreateFromGeCurve(geCurve: pl_Model.GetGeCurve());

            brt.AppendEntity(layoutClipCurve);
            docMdf.acTransaction.AddNewlyCreatedDBObject(layoutClipCurve, true);
            var viewExt = new AdvancedExtents3d(layoutClipCurve.GeometricExtents);
            var center  = viewExt.GetAnchor(AdvancedExtents3d.Anchor.GeometryCenter);

            // 创建视口
            Viewport acVport = new Viewport();

            brt.AppendEntity(acVport);
            docMdf.acTransaction.AddNewlyCreatedDBObject(acVport, true);
            brt.DowngradeOpen();

            // 设置视口所对应的裁剪图形
            acVport.On = true;
            acVport.NonRectClipEntityId = layoutClipCurve.ObjectId;
            acVport.NonRectClipOn       = true;

            // -----------------------------------------------   设置视口的显示区域
            acVport.PerspectiveOn = false;
            // ViewHeight属性– 表示视口内模型空间视图的高度。它决定的视口显示的缩放比例
            // 如果要按1:1显示,则需要将其设置为视口多段线所对应的Extents3d的高度。
            acVport.ViewHeight = viewExt.GetHeight();
            // ViewCenter属性- 表示视口内视图的观察中心。它决定的视口显示的平面定位
            // 如果要视图内容范围完全匹配多段线的区域,则需要将其设置为视口多段线的几何中心点。
            acVport.ViewCenter = center.ToXYPlane();
            //ViewHeight属性– 表示视口内模型空间视图的高度。
            acVport.ViewDirection = new Vector3d(0, 0, 1);
            // ViewTarget属性– 表示视口内视图的目标点的位置。
            acVport.ViewTarget = new Point3d(0, 0, 0);
            acVport.Locked     = false;


            // -----------------------------------------------   视口对象在布局中的定位
            // 对视口所绑定的几何曲线的平移和缩放操作可以对视口进行变换,变换过程中视口中的显示内容在布局中的位置也发生同等变换,即是将视口与其中的内容作为一个整体进行变换
            // 但是直接对acVport进行变换,并不会生效。
            layoutClipCurve.TransformBy(Matrix3d.Displacement(new Vector3d(-10, 10, 0)));
            layoutClipCurve.TransformBy(Matrix3d.Scaling(3, center));

            // 对视口所绑定的几何曲线 layoutClipCurve 的Rotation 操作可以对视口进行旋转,但是奇怪的是,在变换过程中,视口中的显示内容相对于布局空间未发生旋转,却进行了平移与缩放。
            // 平移的后的视图中心点依然与视口的几何中心点重合,缩放的比例可以暂且简单理解为"1/cos(angle)"。
            // 而如果要实现视口中内容随视口进行整体旋转,必须对acVport对象进行旋转变换。
            var angle = 45.0 / 180.0 * Math.PI;

            acVport.TransformBy(Matrix3d.Rotation(angle, new Vector3d(0, 0, 1), new Point3d(0, 0, 0)));
            layoutClipCurve.TransformBy(Matrix3d.Rotation(angle, new Vector3d(0, 0, 1), new Point3d(0, 0, 0)));

            //
            return(ExternalCmdResult.Commit);
        }