.NET

Reply
Valued Contributor
GrzesiekGP
Posts: 67
Registered: ‎02-03-2012
Message 1 of 2 (207 Views)

Set MLeader ArrowObject to Closed-Filled.

207 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*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 2 of 2 (159 Views)

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
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.