Exemplo n.º 1
0
        public void addVertex()
        {
            MLeader ml = Entity as MLeader;

            // For the first point...
            if (_mPts.Count == 0)
            {
                // Add a leader line
                _mLeaderLineIndex = ml.AddLeaderLine(_mLeaderIndex);

                // And a start vertex
                ml.AddFirstVertex(_mLeaderLineIndex, _mTempPoint);

                // Add a second vertex that will be set
                // within the jig
                ml.AddLastVertex(_mLeaderLineIndex, new Point3d(0, 0, 0));
            }
            else
            {
                // For subsequent points,
                // just add a vertex
                ml.AddLastVertex(_mLeaderLineIndex, _mTempPoint);
            }

            // Reset the attachment point, otherwise
            // it seems to get forgotten
            ml.TextAttachmentType = TextAttachmentType.AttachmentMiddle;

            // Add the latest point to our history
            _mPts.Add(_mTempPoint);
        }
Exemplo n.º 2
0
        public void AddMLeader()
        {
            Database db = HostApplicationServices.WorkingDatabase;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                //创建3个点,分别表示引线的终点和两个头点
                Point3d ptEnd = new Point3d(90, 0, 0);
                Point3d pt1   = new Point3d(80, 20, 0);
                Point3d pt2   = new Point3d(100, 20, 0);
                MText   mtext = new MText
                {
                    Contents = "多重引线示例"          //文本内容
                };                               //新建多行文本
                MLeader mleader = new MLeader(); //创建多重引线
                //为多重引线添加引线束,引线束由基线和一些单引线构成
                int leaderIndex = mleader.AddLeader();
                //在引线束中添加一单引线
                int lineIndex = mleader.AddLeaderLine(leaderIndex);
                mleader.AddFirstVertex(lineIndex, pt1);  //在单引线中添加引线头点

                mleader.AddLastVertex(lineIndex, ptEnd); //在单引线中添加引线终点
                //在引线束中再添加一单引线,并只设置引线头点
                lineIndex = mleader.AddLeaderLine(leaderIndex);
                mleader.AddFirstVertex(lineIndex, pt2);
                //设置多重引线的注释为多行文本
                mleader.ContentType = ContentType.MTextContent;
                mleader.MText       = mtext;
                //将多重引线添加到模型空间
                db.AddToModelSpace(mleader);
                trans.Commit();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create an AutoCAD's MLeader's object by two points and text's string
        /// </summary>
        /// <param name="place_point"></param>
        /// <param name="leader_line_start"></param>
        /// <param name="leader_text"></param>
        /// <param name="text_width"></param>
        /// <param name="text_height"></param>
        public static void CreateMLeaderByPoint(Autodesk.AutoCAD.DynamoNodes.Document doc_dyn, ds.Point place_point, ds.Point leader_line_start, string leader_text, double TextRotation = 0d, double LandingGap = 0.04, double text_width = 5, double text_height = 0.2, double arrow_size = 0.5)
        {
            /* Help docs
             * http://bushman-andrey.blogspot.com/2013/01/blog-post.html
             * https://adn-cis.org/kak-sozdat-multivyinosku-v-.net.html
             * https://adn-cis.org/forum/index.php?topic=10503.msg49118#msg49118
             */
            Document doc = doc_dyn.AcDocument;
            //Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor   ed = doc.Editor;

            using (Transaction Tx = db.TransactionManager.StartTransaction())
            {
                BlockTable table = Tx.GetObject(
                    db.BlockTableId,
                    OpenMode.ForRead)
                                   as BlockTable;

                BlockTableRecord model = Tx.GetObject(
                    table[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite)
                                         as BlockTableRecord;

                MLeader leader      = new MLeader();
                var     temp_leader = leader.AddLeader();
                //leader.SetArrowSize(0, arrow_size);
                leader.ArrowSize = arrow_size;
                leader.AddLeaderLine(temp_leader);
                leader.AddFirstVertex(temp_leader, new Point3d(place_point.X, place_point.Y, 0.0));
                leader.AddLastVertex(temp_leader, new Point3d(leader_line_start.X, leader_line_start.Y, 0.0));

                leader.SetDatabaseDefaults();

                leader.ContentType = ContentType.MTextContent;
                leader.SetTextAttachmentType(
                    Autodesk.AutoCAD.DatabaseServices.TextAttachmentType.AttachmentBottomLine,
                    Autodesk.AutoCAD.DatabaseServices.LeaderDirectionType.LeftLeader);

                MText mText = new MText();
                mText.SetDatabaseDefaults();
                mText.Width  = text_width;
                mText.Height = text_height;

                mText.SetContentsRtf(leader_text);
                mText.Rotation       = TextRotation;
                leader.MText         = mText;
                leader.LandingGap    = LandingGap;
                mText.BackgroundFill = false;

                model.AppendEntity(leader);
                Tx.AddNewlyCreatedDBObject(leader, true);

                Tx.Commit();
            }
        }
Exemplo n.º 4
0
        public void AddRoadMLeader()
        {
            Database db = HostApplicationServices.WorkingDatabase;
            //获取符号为点的箭头块的ObjectId
            ObjectId arrowId = db.GetArrowObjectId(DimArrowBlock.Dot);

            //如果当前图形中还未加入上述箭头块,则加入并获取其ObjectId
            if (arrowId == ObjectId.Null)
            {
                DimTools.ArrowBlock = DimArrowBlock.Dot;
                arrowId             = db.GetArrowObjectId(DimArrowBlock.Dot);
            }
            //创建一个点列表,在其中添加4个要标注的点
            List <Point3d> pts = new List <Point3d>();

            pts.Add(new Point3d(150, 0, 0));
            pts.Add(new Point3d(150, 15, 0));
            pts.Add(new Point3d(150, 18, 0));
            pts.Add(new Point3d(150, 20, 0));
            //各标注点对应的文字
            List <string> contents = new List <string> {
                "道路中心线", "机动车道", "人行道", "绿化带"
            };

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                for (int i = 0; i < pts.Count; i++)  //遍历标注点
                {
                    MText txt = new MText();         //创建多行文本
                    txt.Contents = contents[i];      //文本内容
                    MLeader mleader = new MLeader(); //创建多重引线
                    //为多重引线添加引线束,引线束由基线和一些单引线构成
                    int leaderIndex = mleader.AddLeader();
                    //在引线束中添加一单引线,并设置引线头点和终点
                    int lineIndex = mleader.AddLeaderLine(leaderIndex);
                    mleader.AddFirstVertex(lineIndex, pts[i]);
                    mleader.AddLastVertex(lineIndex, pts[0].PolarPoint(Math.PI / 2, 20 + (i + 1) * 5));
                    mleader.ArrowSymbolId = arrowId;//设置单引线的箭头块ObjectId
                    //设置多重引线的注释为多行文本
                    mleader.ContentType = ContentType.MTextContent;
                    mleader.MText       = txt;
                    db.AddToModelSpace(mleader);
                    mleader.ArrowSize    = 1; //多重引线箭头大小
                    mleader.DoglegLength = 0; //多重引线基线长度设为0
                    //将基线连接到引线文字的下方并且绘制下划线
                    mleader.TextAttachmentType = TextAttachmentType.AttachmentBottomLine;
                }
                trans.Commit();
            }
        }
Exemplo n.º 5
0
        public static void Create()
        {
            BaseClass.UseTransaction(trans =>
            {
                try
                {
                    BaseClass.Editor.WriteMessage("\nDraw MLeader Exercise");
                    BlockTable bt;
                    bt = trans.GetObject(BaseClass.Database.BlockTableId, OpenMode.ForRead) as BlockTable;

                    BlockTableRecord btr;
                    btr = trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                    //send message to the user
                    BaseClass.Editor.WriteMessage("\nDrawing an Mleader object: ");

                    //specify mtext prameters

                    string txt    = "Hello George";
                    Point3d insPt = new Point3d(200, 200, 0);
                    using (MLeader ldr = new MLeader())
                    {
                        ldr.ColorIndex = 1;

                        MText mtext = new MText();
                        using (mtext)
                        {
                            mtext.Contents = txt;
                            ldr.MText      = mtext;
                        }

                        //adding leaders
                        int idx = ldr.AddLeaderLine(new Point3d(10, 20, 0));
                        ldr.AddFirstVertex(idx, new Point3d(0, 0, 0));
                        ldr.AddLastVertex(idx, new Point3d(55, 100, 0));

                        btr.AppendEntity(ldr);                    //add line to the BlockTabeReccord
                        trans.AddNewlyCreatedDBObject(ldr, true); //add to the transaction
                    }
                }
                catch (System.Exception ex)
                {
                    BaseClass.Editor.WriteMessage("Error encountered: " + ex.Message);
                    trans.Abort();
                }
            });
        }
            protected override bool WorldDraw(WorldDraw draw)
            {
                var wg = draw.Geometry;

                if (wg != null)
                {
                    ObjectId arrId = AutocadHelpers.GetArrowObjectId(ArrowName);

                    var mtxt = new MText();
                    mtxt.SetDatabaseDefaults();
                    mtxt.Contents   = MlText;
                    mtxt.Location   = _secondPoint;
                    mtxt.Annotative = AnnotativeStates.True;
                    mtxt.TransformBy(AcApp.DocumentManager.MdiActiveDocument.Editor.CurrentUserCoordinateSystem);

                    _mleader = new MLeader();
                    var ldNum = _mleader.AddLeader();
                    _mleader.AddLeaderLine(ldNum);
                    _mleader.SetDatabaseDefaults();
                    _mleader.ContentType           = ContentType.MTextContent;
                    _mleader.ArrowSymbolId         = arrId;
                    _mleader.MText                 = mtxt;
                    _mleader.TextAlignmentType     = TextAlignmentType.LeftAlignment;
                    _mleader.TextAttachmentType    = TextAttachmentType.AttachmentBottomOfTopLine;
                    _mleader.TextAngleType         = TextAngleType.HorizontalAngle;
                    _mleader.EnableAnnotationScale = true;
                    _mleader.Annotative            = AnnotativeStates.True;
                    _mleader.AddFirstVertex(ldNum, FirstPoint);
                    _mleader.AddLastVertex(ldNum, _secondPoint);
                    _mleader.LeaderLineType = LeaderType.StraightLeader;
                    _mleader.EnableDogleg   = false;
                    _mleader.DoglegLength   = 0.0;
                    _mleader.LandingGap     = 1.0;
                    _mleader.TextHeight     = double.Parse(AcApp.GetSystemVariable("TEXTSIZE").ToString());

                    draw.Geometry.Draw(_mleader);
                }

                return(true);
            }
Exemplo n.º 7
0
        public void AddCoordMLeader()
        {
            Database db = HostApplicationServices.WorkingDatabase;
            //获取符号为无的箭头块的ObjectId
            ObjectId arrowId = db.GetArrowObjectId(DimArrowBlock.None);

            //如果当前图形中还未加入上述箭头块,则加入并获取其ObjectId
            if (arrowId == ObjectId.Null)
            {
                DimTools.ArrowBlock = DimArrowBlock.None;
                arrowId             = db.GetArrowObjectId(DimArrowBlock.None);
            }
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                Point3d ptCoord = new Point3d(80, 30, 0); //要标注的坐标点
                MText   mtext   = new MText();            //新建多行文本
                //设置多行文本的内容为点的坐标值,并且分两行表示
                mtext.Contents          = "X:" + ptCoord.X.ToString("0.000") + @"\PY:" + ptCoord.Y.ToString("0.000");
                mtext.LineSpacingFactor = 0.8;  //多行文本的行间距
                MLeader leader = new MLeader(); //创建多重引线
                //为多重引线添加引线束,引线束由基线和一些单引线构成
                int leaderIndex = leader.AddLeader();
                //在引线束中添加单引线
                int lineIndex = leader.AddLeaderLine(leaderIndex);
                //在单引线中添加引线头点(引线箭头所指向的点),位置为要进行标注的点
                leader.AddFirstVertex(lineIndex, ptCoord);
                //在单引线中添加引线终点
                leader.AddLastVertex(lineIndex, ptCoord.PolarPoint(Math.PI / 4, 10));
                //设置单引线的注释类型为多行文本
                leader.ContentType = ContentType.MTextContent;
                leader.MText       = mtext;//设置单引线的注释文字
                //将多重引线添加到模型空间
                db.AddToModelSpace(leader);
                leader.ArrowSymbolId = arrowId; //设置单引线的箭头块ObjectId
                leader.DoglegLength  = 0;       //设置单引线的基线长度为0
                //将基线连接到引线文字的下方并且绘制下划线
                leader.TextAttachmentType = TextAttachmentType.AttachmentBottomOfTopLine;
                trans.Commit();
            }
        }
Exemplo n.º 8
0
        protected override bool WorldDraw(WorldDraw draw)
        {
            var wg = draw.Geometry;

            if (wg != null)
            {
                var arrId = AutocadHelpers.GetArrowObjectId(AutocadHelpers.StandardArrowhead._NONE);

                var mText = new MText
                {
                    Contents   = MlText,
                    Location   = _secondPoint,
                    Annotative = AnnotativeStates.True
                };
                mText.SetDatabaseDefaults();

                _mLeader = new MLeader();
                var ldNum = _mLeader.AddLeader();
                _mLeader.AddLeaderLine(ldNum);
                _mLeader.ContentType           = ContentType.MTextContent;
                _mLeader.ArrowSymbolId         = arrId;
                _mLeader.MText                 = mText;
                _mLeader.TextAlignmentType     = TextAlignmentType.LeftAlignment;
                _mLeader.TextAttachmentType    = TextAttachmentType.AttachmentBottomOfTopLine;
                _mLeader.TextAngleType         = TextAngleType.HorizontalAngle;
                _mLeader.EnableAnnotationScale = true;
                _mLeader.Annotative            = AnnotativeStates.True;
                _mLeader.AddFirstVertex(ldNum, FirstPoint);
                _mLeader.AddLastVertex(ldNum, _secondPoint);
                _mLeader.LeaderLineType = LeaderType.StraightLeader;
                _mLeader.SetDatabaseDefaults();

                draw.Geometry.Draw(_mLeader);
            }

            return(true);
        }