コード例 #1
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();
            }
        }
コード例 #2
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);
        }
コード例 #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();
            }
        }
コード例 #4
0
ファイル: XyLeader.cs プロジェクト: Alain72/AgwXyLeader
        private bool DrawLeader(ObjectId mLeaderStyleId, IList <Point3d> pnt)
        {
            var leader = new MLeader()
            {
                MLeaderStyle = mLeaderStyleId,
                Layer        = "0",
            };

            using (Active.Document.LockDocument())
                using (Transaction tr = Active.Database.TransactionManager.StartTransaction())
                {
                    try
                    {
                        var idx       = leader.AddLeaderLine(pnt[0]);
                        var direction = 1.0;
                        if ((pnt[0] - pnt[1]).DotProduct(Vector3d.XAxis) < 0)
                        {
                            direction = -1;
                        }

                        leader.SetDogleg(idx, Vector3d.XAxis.MultiplyBy(direction));

                        var text = "{X= " + Decimal.Round((decimal)pnt[0].X, 2) + "}" +
                                   "\\P{Y= " + Decimal.Round((decimal)pnt[0].Y, 2) + "}";

                        pnt.RemoveAt(0);

                        foreach (Point3d pt in pnt)
                        {
                            leader.AddFirstVertex(idx, pt);
                        }

                        MText mText = new MText();
                        mText.SetDatabaseDefaults();

                        mText.Annotative       = AnnotativeStates.True;
                        mText.Contents         = text;
                        mText.Attachment       = (direction < 0) ? AttachmentPoint.MiddleRight : AttachmentPoint.MiddleLeft;
                        leader.MText           = mText;
                        leader.TextHeight      = 1.75;
                        leader.EnableFrameText = true;

                        Active.Database.AddEntities(leader);
                        tr.Commit();
                        return(true);
                    }
                    catch (System.Exception e)
                    {
                        Console.WriteLine(e);
                        return(false);
                    }
                }
        }
コード例 #5
0
ファイル: MLeaderTools.cs プロジェクト: VB6Hobbyst7/AutoCad-1
        /// <summary>
        /// http://adndevblog.typepad.com/autocad/2012/05/how-to-create-mleader-objects-in-net.html
        /// </summary>
        /// <param name="blkLeader"></param>
        /// <param name="location"></param>
        /// <param name="firstVertex"></param>
        /// <param name="secondVertex"></param>
        /// <returns></returns>
        public static ObjectId CreateMLeader(BlockTableRecord blkLeader, Point3d location, Point3d firstVertex, Point3d secondVertex)
        {
            MLeader leader = new MLeader();

            leader.SetDatabaseDefaults();

            leader.ContentType = ContentType.BlockContent;

            leader.BlockContentId = blkLeader.Id;
            leader.BlockPosition  = location;

            int idx = leader.AddLeaderLine(secondVertex);

            leader.AddFirstVertex(idx, firstVertex);

            //Handle Block Attributes
            //int AttNumber = 0;

            //Doesn't take in consideration oLeader.BlockRotation

            /*Matrix3d Transfo = Matrix3d.Displacement(
             *  leader.BlockPosition.GetAsVector());*/
            using (Transaction trans = Tools.StartTransaction())
            {
                /*foreach (ObjectId blkEntId in blkLeader)
                 * {
                 *  AttributeDefinition AttributeDef = trans.GetObject(
                 *      blkEntId,
                 *      OpenMode.ForRead)
                 *          as AttributeDefinition;
                 *
                 *  if (AttributeDef != null)
                 *  {
                 *      AttributeReference AttributeRef =
                 *          new AttributeReference();
                 *
                 *      AttributeRef.SetAttributeFromBlock(
                 *          AttributeDef,
                 *          Transfo);
                 *
                 *      AttributeRef.Position =
                 *          AttributeDef.Position.TransformBy(Transfo);
                 *
                 *      AttributeRef.TextString = "Attrib #" + (++AttNumber);
                 *
                 *      leader.SetBlockAttribute(blkEntId, AttributeRef);
                 *  }
                 * }*/

                return(Tools.AppendEntityEx(trans, leader, true));
            }
        }
コード例 #6
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();
            }
        }
コード例 #7
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();
                }
            });
        }
コード例 #8
0
        public static ObjectId GenerateLeader(string contents, Point3d leaderPosition, Point3d textPosition)
        {
            var leaderId = ObjectId.Null;
            var acCurDb  = Application.DocumentManager.MdiActiveDocument.Database;

            using (var acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                var acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;

                if (acBlkTbl != null)
                {
                    var acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                    if (acBlkTblRec != null)
                    {
                        using (var leader = new MLeader())
                        {
                            var mText = new MText
                            {
                                Width    = 20,
                                Contents = contents,
                                Location = textPosition
                            };

                            mText.SetDatabaseDefaults();

                            leader.SetDatabaseDefaults();
                            leader.ContentType = ContentType.MTextContent;
                            leader.MText       = mText;
                            leader.TextHeight  = 2;
                            leader.AddLeaderLine(leaderPosition);
                            leader.Layer = Constants.LAYER_DEF_POINTS_NAME;

                            leaderId = acBlkTblRec.AppendEntity(leader);
                            acTrans.AddNewlyCreatedDBObject(leader, true);
                        }
                    }
                }

                acTrans.Commit();
            }

            return(leaderId);
        }
コード例 #9
0
ファイル: MLeaderTools.cs プロジェクト: VB6Hobbyst7/AutoCad-1
        public static ObjectId CreateMLeader(MText mText, Point3d location)
        {
            MLeader leader = new MLeader();

            leader.SetDatabaseDefaults();

            leader.ContentType = ContentType.MTextContent;

            leader.MText = mText;

            int idx = leader.AddLeaderLine(new Point3d(1, 1, 0));

            leader.AddFirstVertex(idx, new Point3d(0, 0, 0));

            using (Transaction trans = Tools.StartTransaction())
            {
                return(Tools.AppendEntityEx(trans, leader, true));
            }
        }
コード例 #10
0
ファイル: Commands.cs プロジェクト: dirkrossger/Plant3D
        public static void netTextMLeader()
        {
            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();
                leader.SetDatabaseDefaults();

                leader.ContentType = ContentType.MTextContent;

                MText mText = new MText();
                mText.SetDatabaseDefaults();
                //mText.Width = 100;
                //mText.Height = 50;
                mText.SetContentsRtf("MLeader");
                mText.Location = new Point3d(1, 1, 0);

                leader.MText = mText;

                int idx = leader.AddLeaderLine(new Point3d(0, 0, 0));
                leader.AddFirstVertex(idx, new Point3d(0, 0, 0));

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

                Tx.Commit();
            }
        }
コード例 #11
0
        public MLeaderDraw(string content, List <Point3d> points, Point3d basePt)
        {
            Init();
            PrepareMtext(basePt, content);

            Vector3d offset  = new Vector3d(2, 3.6, 0);
            MLeader  mleader = new MLeader();

            mleader.SetDatabaseDefaults();
            mleader.ContentType = ContentType.MTextContent;

            mt.TransformBy(Matrix3d.Displacement(offset.DivideBy(asc.Scale)));

            mleader.MText = mt;

            foreach (Point3d ptt in points)
            {
                int idx = mleader.AddLeaderLine(basePt);
                mleader.SetFirstVertex(idx, ptt);
            }
        }
コード例 #12
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();
            }
        }
コード例 #13
0
            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);
            }
コード例 #14
0
ファイル: MultiLeader.cs プロジェクト: koropet/PKUserTools
        /// <summary>
        /// Выноска, которая создается если группа объектов вертикальная
        /// </summary>
        void PrepareSubLeader()
        {
            var pm = Input.Point("Выберите точку для дополнительной выноски");

            if (Input.StatusBad)
            {
                return;
            }

            MLeader add_mleader = new MLeader();

            add_mleader.SetDatabaseDefaults();
            add_mleader.ContentType = ContentType.MTextContent;
            mt.Rotation             = 0;
            mt.Location             = pm;
            add_mleader.MText       = mt;

            int idx = add_mleader.AddLeaderLine(pm);

            add_mleader.SetFirstVertex(idx, mtp);

            geometry.Add(add_mleader);
        }
コード例 #15
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);
        }
コード例 #16
0
        public static void BlkCoords()
        {
            Document acDoc = Application.DocumentManager.MdiActiveDocument;

            if (acDoc == null)
            {
                return;
            }
            Database acCurrDb = acDoc.Database;

            using (Transaction acTrans = acCurrDb.TransactionManager.StartTransaction())
            {
                TypedValue[] acTypValArr = new TypedValue[1];
                acTypValArr.SetValue(new TypedValue((int)DxfCode.Start, "INSERT"), 0);
                SelectionFilter       acSelFilter   = new SelectionFilter(acTypValArr);
                PromptSelectionResult acSSPromptRes = acDoc.Editor.GetSelection(acSelFilter);
                if (acSSPromptRes.Status == PromptStatus.OK)
                {
                    SelectionSet acSSet = acSSPromptRes.Value;
                    foreach (SelectedObject acSObj in acSSet)
                    {
                        if (acSObj != null)
                        {
                            BlockReference acBlockRef = acTrans.GetObject(acSObj.ObjectId, OpenMode.ForWrite) as BlockReference;
                            if (acBlockRef != null)
                            {
                                BlockTable acBlkTbl = acTrans.GetObject(
                                    acCurrDb.BlockTableId, OpenMode.ForRead) as BlockTable;

                                BlockTableRecord acBlkTblRec = acTrans.GetObject(
                                    acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                                MLeader acMLeader = new MLeader();
                                acMLeader.SetDatabaseDefaults();
                                acMLeader.ContentType = ContentType.MTextContent;

                                MText acMText = new MText();

                                double xCoord = acBlockRef.Position.X;
                                double yCoord = acBlockRef.Position.Y;
                                double zCoord = acBlockRef.Position.Z;

                                acMText.Contents = "X= " + xCoord.ToString("F2") +
                                                   "\nY= " + yCoord.ToString("F2");
                                acMText.Height  = 1;
                                acMLeader.MText = acMText;

                                acMLeader.TextHeight         = 1;
                                acMLeader.TextLocation       = new Point3d(xCoord + 5, yCoord + 5, zCoord);
                                acMLeader.ArrowSize          = 1;
                                acMLeader.EnableDogleg       = true;
                                acMLeader.DoglegLength       = 0;
                                acMLeader.EnableLanding      = true;
                                acMLeader.LandingGap         = 1;
                                acMLeader.ExtendLeaderToText = true;
                                acMLeader.SetTextAttachmentType(TextAttachmentType.AttachmentBottomOfTopLine, LeaderDirectionType.LeftLeader);
                                acMLeader.SetTextAttachmentType(TextAttachmentType.AttachmentBottomOfTopLine, LeaderDirectionType.RightLeader);

                                acMLeader.AddLeaderLine(acBlockRef.Position);

                                acBlkTblRec.AppendEntity(acMLeader);
                                acTrans.AddNewlyCreatedDBObject(acMLeader, true);
                            }
                        }
                    }
                    acTrans.Commit();
                    acDoc.Editor.Regen();
                }
                else
                {
                    acDoc.Editor.WriteMessage("\nCanceled.");
                }
            }
        }
コード例 #17
0
ファイル: MultiLeader.cs プロジェクト: koropet/PKUserTools
        /// <summary>
        /// Мультивыноска из объектов со стрелками на одной линии
        /// </summary>
        public void MakeArrowsInline()
        {
            base.Execute();
            asc = UT.GetAnnoScale("CANNOSCALE");
            var     objects = new List <Entity>();
            var     points = new List <Point3d>();
            Point3d p1, p2;
            Line    p1p2;

            Vector3d offset = new Vector3d(2, 3.6, 0);

            var sset = Input.Objects("Выберите объекты"); if (Input.StatusBad)

            {
                return;
            }


            p1 = Input.Point("Выберите точку мультивыноски"); if (Input.StatusBad)
            {
                return;
            }
            p2 = Input.Point("Выберите точку для задания направления"); if (Input.StatusBad)
            {
                return;
            }

            p1p2 = new Line(p1, p2);
            Tweet("\nНачинаем транзакцию");
            using (var th = new TransactionHelper())
            {
                objects = th.ReadObjects(sset);

                Tweet("\nНачинаем поиск точек");
                foreach (Entity ent in objects)
                {
                    var pt_arr = UT.IntersectWith(p1p2, ent);
                    if (pt_arr.Count > 0)
                    {
                        points.Add(pt_arr[0]);
                    }
                }

                Tweet("\nНачинаем подготовку текста");

                mtp  = p1;
                text = "хх";
                PrepareMtext(0);

                Tweet("\nНачинаем подготовку выноски");
                MLeader mleader = new MLeader();
                mleader.SetDatabaseDefaults();
                mleader.ContentType = ContentType.MTextContent;

                mt.TransformBy(Matrix3d.Displacement(offset.DivideBy(asc.Scale)));

                mleader.MText = mt;

                Tweet("\nДобавляем линии");
                foreach (Point3d ptt in points)
                {
                    int idx = mleader.AddLeaderLine(p1);
                    mleader.SetFirstVertex(idx, ptt);
                }
                Tweet("\nЗаписываем объекты");
                th.WriteObject(mleader);
            }
        }
コード例 #18
0
ファイル: PropertyWorker.cs プロジェクト: koropet/PKUserTools
        static void PropertyMLeader(string name, int pow)
        {
            var acDoc   = App.DocumentManager.MdiActiveDocument;
            var acCurDb = acDoc.Database;
            var acEd    = acDoc.Editor;
            var sset    = Input.Objects("Выберите объект"); if (Input.StatusBad)

            {
                return;
            }

            asc = UT.GetAnnoScale("CANNOSCALE");
            Vector3d offset = new Vector3d(2, 3.6, 0);
            var      areas  = new List <double>();

            using (var th = new TransactionHelper())
            {
                var ents = th.EditObjects(sset);

                foreach (var e in ents)
                {
                    var p = PropertyWorker.GetProperty(e, name);
                    if (p == null)
                    {
                        Messaging.Tweet("Skip");
                        continue;
                    }
                    areas.Add((double)p.pValue);
                }
            }
            foreach (var d in areas)
            {
                double measured_d = PKUserTools.Measurings.UnitsForm.measuringUnits.Value(PKUserTools.Measurings.UnitsForm.modelUnits, d, pow);

                using (var th = new TransactionHelper())
                {
                    var pt1 = Input.Point("Первая точка выноски"); if (Input.StatusBad)
                    {
                        return;
                    }
                    var pt2 = Input.Point("Вторая точка выноски"); if (Input.StatusBad)
                    {
                        return;
                    }

                    //TODO сделать общий класс создания мультивыносок
                    var   mleader = new MLeader();
                    MText mt;
                    PrepareMtext(0, out mt, acCurDb, pt2);

                    mleader.SetDatabaseDefaults();
                    mleader.ContentType = ContentType.MTextContent;

                    mt.TransformBy(Matrix3d.Displacement(offset.DivideBy(asc.Scale)));

                    mt.Contents = string.Format("{0:F3}", measured_d);

                    mleader.MText = mt;

                    int idx = mleader.AddLeaderLine(pt1);
                    mleader.SetFirstVertex(idx, pt1);

                    th.WriteObject(mleader);
                }
            }
        }