Example #1
0
        public void AddLeader()
        {
            Database db = HostApplicationServices.WorkingDatabase;

            using (var trans = db.TransactionManager.StartTransaction())
            {
                //创建一个在原点直径为0.219的圆。
                Circle circle = new Circle();
                circle.Center   = Point3d.Origin;
                circle.Diameter = 0.219;
                //创建一个多行文本并设置其内容为4Xφd±0.005(其中d为圆的直径)
                MText txt = new MText();
                txt.Contents   = "4X" + TextSpecialSymbol.Diameter + circle.Diameter + TextSpecialSymbol.Tolerance + "0.005";
                txt.Location   = new Point3d(1, 1, 0); //文本位置
                txt.TextHeight = 0.2;                  //文本高度
                db.AddToModelSpace(circle, txt);       //将圆和文本添加到模型空间中
                Leader leader = new Leader();          //创建一个引线对象
                //将圆上一点及文本位置作为引线的顶点
                leader.AppendVertex(circle.Center.PolarPoint(Math.PI / 3, circle.Radius));
                leader.AppendVertex(txt.Location);
                db.AddToModelSpace(leader);       //将引线添加到模型空间中
                leader.Dimgap     = 0.1;          //设置引线的文字偏移为0.1
                leader.Dimasz     = 0.1;          //设置引线的箭头大小为0.1
                leader.Annotation = txt.ObjectId; //设置引线的注释对象为文本
                leader.EvaluateLeader();          //计算引线及其关联注释之间的关系
                trans.Commit();                   //提交更改
            }
        }
Example #2
0
File: Ldr.cs Project: 15831944/EM
        addLdr(Point3dCollection pnt3ds, ObjectId idLayer, double sizeArrow, double sizeGap, Color color,
               ObjectId idMTxt, string nameStyle = "Annotative", bool spline = false)
        {
            ObjectId idLdr = ObjectId.Null;
            Leader   ldr   = new Leader();

            try
            {
                using (Transaction tr = BaseObjs.startTransactionDb())
                {
                    BlockTable       BT = Blocks.getBlockTable();
                    BlockTableRecord MS = (BlockTableRecord)tr.GetObject(BT[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

                    ObjectId            idDimStyle = Dim.getDimStyleTableRecord("Annotative");
                    DimStyleTableRecord dstr       = (DimStyleTableRecord)tr.GetObject(idDimStyle, OpenMode.ForRead);

                    ldr.SetDatabaseDefaults();
                    ldr.HasArrowHead   = true;
                    ldr.DimensionStyle = idDimStyle;
                    ldr.SetDimstyleData(dstr);
                    ldr.LayerId    = idLayer;
                    ldr.Dimasz     = sizeArrow;
                    ldr.Dimgap     = sizeGap;
                    ldr.IsSplined  = spline;
                    ldr.Color      = color;
                    ldr.Annotative = AnnotativeStates.True;

                    for (int i = 0; i < pnt3ds.Count; i++)
                    {
                        try
                        {
                            ldr.AppendVertex(pnt3ds[i]);
                        }
                        catch (System.Exception ex)
                        {
                            BaseObjs.writeDebug(ex.Message + " Ldr.cs: line: 60");
                        }
                    }

                    idLdr = MS.AppendEntity(ldr);
                    tr.AddNewlyCreatedDBObject(ldr, true);

                    if (!idMTxt.IsNull)
                    {
                        ldr.Annotative = AnnotativeStates.True;
                        ldr.Annotation = idMTxt;
                        ldr.Dimtad     = 0;
                        ldr.EvaluateLeader();
                    }

                    tr.Commit();
                }// end using
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(ex.Message + " Ldr.cs: line: 79");
            }

            return(idLdr);
        }
Example #3
0
        /// <summary>
        /// 引线和注释
        /// </summary>

        public static void AddLeaderAnnotation(double YB_x, double YB_y, double Z_x, double Z_y, string zhushi
                                               , int Color, double G_x, double G_y)
        {
            //获取当前数据库
            Document acDoc   = Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;

            //启动事务
            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                //以读模式打开块表
                BlockTable acBlkTbl;
                acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
                                             OpenMode.ForRead) as BlockTable;
                //以写模式打开块表记录模型空间
                BlockTableRecord acBlkTblRec;
                acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
                                                OpenMode.ForWrite) as BlockTableRecord;
                //创建多行文字(MText)注释
                using (MText acMText = new MText())
                {
                    acMText.Contents = zhushi;
                    acMText.Location = new Point3d(Z_x, Z_y, 0);

                    acMText.ColorIndex = Color;
                    acMText.Width      = 2;
                    acMText.Height     = 1.5;
                    //添加新对象到模型空间,记录事务
                    acBlkTblRec.AppendEntity(acMText);
                    acTrans.AddNewlyCreatedDBObject(acMText, true);
                    //创建带注释的引线
                    using (Leader acLdr = new Leader())
                    {
                        acLdr.AppendVertex(new Point3d(YB_x, YB_y, 0));
                        acLdr.AppendVertex(new Point3d(G_x, G_y, 0));
                        acLdr.AppendVertex(new Point3d(G_x, G_y + 1, 0));
                        acLdr.HasArrowHead = true;
                        //添加新对象到模型空间,记录事务
                        acBlkTblRec.AppendEntity(acLdr);
                        acTrans.AddNewlyCreatedDBObject(acLdr, true);
                        //给引线对象附加注释
                        acLdr.Annotation = acMText.ObjectId;
                        acLdr.EvaluateLeader();
                        //释放DBObject对象
                    }
                }
                //提交修改,回收内存
                acTrans.Commit();
            }
        }
Example #4
0
        addLdr(Point3dCollection pnt3ds, bool isSplined = false, MText mTxt = null, string nameLayer = "0", short color = 256)
        {
            ObjectId idLdr = ObjectId.Null;
            Leader   ldr   = new Leader();
            double   scale = Misc.getCurrAnnoScale();

            try
            {
                using (Transaction tr = BaseObjs.startTransactionDb())
                {
                    BlockTableRecord MS = Blocks.getBlockTableRecordMS();

                    ldr.SetDatabaseDefaults();
                    ldr.HasArrowHead = true;
                    ldr.IsSplined    = isSplined;
                    ldr.Dimasz       = scale * 0.09;

                    Layer.manageLayers(nameLayer);
                    ldr.Layer = nameLayer;
                    ldr.Color = Color.FromColorIndex(ColorMethod.ByBlock, color);

                    foreach (Point3d pnt3d in pnt3ds)
                    {
                        ldr.AppendVertex(pnt3d);
                    }
                    idLdr = MS.AppendEntity(ldr);
                    tr.AddNewlyCreatedDBObject(ldr, true);
                    if (mTxt != null)
                    {
                        ldr.Annotation = mTxt.ObjectId;
                        ldr.Dimtad     = 0;
                        ldr.EvaluateLeader();
                    }
                    ldr.Annotative = AnnotativeStates.True;
                    tr.Commit();
                }// end using
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(ex.Message + " Draw.cs: line: 162");
            }

            return(idLdr);
        }