Esempio n. 1
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;
            }
        /// <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();
            }
        }
Esempio n. 3
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.");
                }
            }
        }