.NET

.NET

Reply
Valued Contributor
70 Posts
1 Kudo
Registered: ‎02-03-2012
Post 1 of 2

Set MLeader ArrowObject to Closed-Filled.

218 Views, 1 Replies
02-14-2012 01:35 AM

I'm testing code from Kean:

http://through-the-interface.typepad.com/through_the_interface/2007/01/creating_an_aut.html

 

Everything is ok, it works great.

 

But I have one problem. I would like to have closed-filled arrow with my MLeader, but when I send stringname = "" or "." I'm getting error about no found key.

 

Anyone has got some clue for me? I googled I found nothing.

AC 2007, WinXP x86, VS2010, NET 3.5

*Expert Elite*
1,569 Posts
171 Kudos
Registered: ‎10-08-2008
Post 2 of 2

Re: Set MLeader ArrowObject to Closed-Filled.

02-15-2012 10:27 PM in reply to: GrzesiekGP

Here is working example tested on A2010

{code}

      [CommandMethod("mldf")]
        public void MleaderTest()
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = doc.Database;
            Matrix3d ucs = ed.CurrentUserCoordinateSystem;
           object dimld= Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("dimldrblk");
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                try
                {
                    Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("dimldrblk", ".");
                    Point3d arrowPoint = ed.GetPoint("\nPick a point for the arrowhead: ").Value;
                    PromptPointOptions pto = new PromptPointOptions("\nPick a point for text: ");
                    pto.UseBasePoint = true;
                    pto.UseDashedLine = true;
                    pto.BasePoint = arrowPoint;
                    Point3d symbolPoint = ed.GetPoint(pto).Value;
                    Vector3d vec;
                    if (arrowPoint.X <= symbolPoint.X)
                    {
                        vec = new Vector3d(1, 0, 0);
                    }
                    else
                    {
                        vec = new Vector3d(-1, 0, 0);
                    }
                    BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                    double th = db.Dimtxt;
                    MText mtxt = new MText();
                    mtxt.SetDatabaseDefaults();
                    mtxt.Attachment = vec == new Vector3d(1, 0, 0) ? AttachmentPoint.MiddleLeft : AttachmentPoint.MiddleRight;
                    mtxt.TextHeight = th;
                    mtxt.Width = 0.0;
                    mtxt.Contents = "Line 1\\PLine2";
 
                    MLeader mldr = new MLeader();
                    mldr.LeaderLineType = LeaderType.StraightLeader;
                    /* --- add other properties here --- */
                    mldr.AddLeaderLine(arrowPoint);
                    mldr.AddFirstVertex(0, arrowPoint);
                    mldr.AddFirstVertex(1, symbolPoint);
                    mldr.ArrowSymbolId = db.Dimldrblk;
                   
                    DBDictionary dict = (DBDictionary)tr.GetObject(db.MLeaderStyleDictionaryId, OpenMode.ForRead);
                    ObjectId mlstyleid = dict.GetAt("Standard");
                    mldr.MLeaderStyle = mlstyleid;
                    mldr.ContentType = ContentType.MTextContent;

                    mldr.MText = mtxt;
                    mldr.TextLocation = symbolPoint;
                    mldr.SetDogleg(0, vec);
                    mldr.LandingGap = th/4;
                    mldr.DoglegLength = th;
 
                    btr.AppendEntity(mldr);
                    tr.AddNewlyCreatedDBObject(mldr, true);
                    tr.Commit();
                }
                catch (Autodesk.AutoCAD.Runtime.Exception ex)
                {
                    ed.WriteMessage(ex.Message + "\n" + ex.StackTrace);
                }
                finally
                {
                    Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("dimldrblk", dimld);
                }
            }
        }

{code}

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!