/// <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();
            }
        }
        /// <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));
            }
        }
Exemple #3
0
            public MLeaderJig(string contents)
                : base(new MLeader())
            {
                // Store the string passed in
                m_contents = contents;

                // Create a point collection to store our vertices
                m_pts = new Point3dCollection();

                // Create mleader and set defaults
                MLeader ml = Entity as MLeader;

                ml.SetDatabaseDefaults();
                ml.Layer = "DIM";

                // Set up the MText contents
                ml.ContentType = ContentType.MTextContent;

                MText mt = new MText();

                mt.SetDatabaseDefaults();
                mt.Contents = m_contents;

                mt.TextStyleId = GeneralMenu.GetTextstyleId("ESI-STD");

                ml.MText     = mt;
                ml.TextColor = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByAci, 32);

                //ml.TextAlignmentType = TextAlignmentType.LeftAlignment;
                //ml.TextAttachmentType = TextAttachmentType.AttachmentTopOfTop;

                //// Set the frame and landing properties
                //ml.EnableDogleg = true;
                //ml.EnableFrameText = true;
                //ml.EnableLanding = true;

                ml.SetTextAttachmentType(TextAttachmentType.AttachmentMiddleOfTop, LeaderDirectionType.LeftLeader);
                ml.SetTextAttachmentType(TextAttachmentType.AttachmentMiddleOfBottom, LeaderDirectionType.RightLeader);


                // Reduce the standard landing gap
                ml.LandingGap = .125;

                // Add a leader, but not a leader line (for now)
                m_leaderIndex     = ml.AddLeader();
                m_leaderLineIndex = -1;
            }
        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);
        }
        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));
            }
        }
Exemple #6
0
        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();
            }
        }
Exemple #7
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);
            }
        }
            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);
            }
Exemple #9
0
        /// <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);
        }
Exemple #10
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);
        }
Exemple #11
0
        public JigMLeader(string contents)
            : base(new MLeader())
        {
            // Store the string passed in
            _mContents = contents;

            // Create a point collection to store our vertices
            _mPts = new Point3dCollection();

            // Create mleader and set defaults

            MLeader ml = Entity as MLeader;

            ml.SetDatabaseDefaults();

            // Set up the MText contents
            ml.ContentType = ContentType.MTextContent;
            MText mt = new MText();

            mt.SetDatabaseDefaults();
            mt.Contents           = _mContents;
            ml.MText              = mt;
            ml.TextAlignmentType  = TextAlignmentType.LeftAlignment;
            ml.TextAttachmentType = TextAttachmentType.AttachmentMiddle;

            // Set the frame and landing properties
            ml.EnableDogleg    = true;
            ml.EnableFrameText = true;
            ml.EnableLanding   = true;

            // Reduce the standard landing gap
            ml.LandingGap = 0.05;

            // Add a leader, but not a leader line (for now)
            _mLeaderIndex     = ml.AddLeader();
            _mLeaderLineIndex = -1;
        }
Exemple #12
0
        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);
                }
            }
        }
        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.");
                }
            }
        }
Exemple #14
0
        /// <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);
            }
        }