.NET

.NET

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

Set MLeader ArrowObject to Closed-Filled.

214 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 (166 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
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.