.NET

Reply
New Member
sebastian.k212
Posts: 2
Registered: ‎11-19-2013
Message 1 of 3 (263 Views)

Bind MLeader to an entity

263 Views, 2 Replies
11-19-2013 01:19 AM

Hi all,

 

I have a method DrawMLeaderLine(Database db, Transaction tr, Point3d point, string text) that draws me a MLeader line to the given point with the given text as annotation. The MLeader line points to the midpoint of a Line entity. What I need is a binding between the Line midpoint and the MLeader line, so when I move or resize the Line, the MLeader line should follow! I already tried to solve that, using constraints, but it doesn't work for Leaders.

 

This is my code...

 

public static MLeader DrawMLeaderLine(Database db, Transaction tr, Point3d point, string text)
        {
            Point3d mTextLocation = point + new Vector3d(5, 5, 0);

            BlockTableRecord btr = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;

            MText mText = new MText();
            mText.SetDatabaseDefaults();
            mText.SetContentsRtf(text);
            mText.Location = mTextLocation;

            MLeader mLeader = new MLeader();
            mLeader.SetDatabaseDefaults();
            mLeader.ArrowSize = 1.0d;
            mLeader.LandingGap = 0.5d;
            mLeader.DoglegLength = 1.0d;
            
            mLeader.ContentType = ContentType.MTextContent;
            mLeader.MText = mText;

            
            int idx = mLeader.AddLeaderLine(point);
            //mLeader.AddFirstVertex(idx, point + new Vector3d(2, 2, 0));
            
            btr.AppendEntity(mLeader);
            tr.AddNewlyCreatedDBObject(mLeader, true);

            return mLeader;
        }

 

will be called from a different class...

 

            Line line = DrawingUtil.DrawLine(doc.Database, tr, closestPoints.Item1, closestPoints.Item2);
 
            //Get midpoint of line
            double midPointX = (line.EndPoint.X + line.StartPoint.X) / 2.0d;
            double midPointY = (line.EndPoint.Y + line.StartPoint.Y) / 2.0d;
            Point3d midPointOfLine = new Point3d(midPointX, midPointY, 0);
 
            //Draw the leaderline
            MLeader leaderLine = DrawingUtil.DrawMLeaderLine(doc.Database, tr, midPointOfLine, "Connection");

 

Can anyone tell me, how I can "bind", "connect", "attach" (or whatever) the leaderline to the midpoint of the line?

 

Thanks for your replies...

Sebastian.

 

Distinguished Mentor
BlackBox_
Posts: 785
Registered: ‎02-25-2013
Message 2 of 3 (237 Views)

Re: Bind MLeader to an entity

11-19-2013 05:28 AM in reply to: sebastian.k212

sebastian.k212 wrote:

What I need is a binding between the Line midpoint and the MLeader line, so when I move or resize the Line, the MLeader line should follow! 

 


 

This may be helpful:

 

Anchoring AutoCAD entities to each other using .NET

 



"Potential has a shelf life." - Margaret Atwood


Autodesk Exchange Apps ~ Autoloader ~ AutoCAD Security


AutoCAD® 2014, and Civil 3D® 2014 Certified Professional ~ Autodesk® Authorized Developer

New Member
sebastian.k212
Posts: 2
Registered: ‎11-19-2013
Message 3 of 3 (206 Views)

Re: Bind MLeader to an entity

11-20-2013 12:32 AM in reply to: BlackBox_

Thanks for the link. But what I am looking for is more an AutoCAD feature. With the solution presented in the link, I have to listen to Move Commands and then recalculate the Anchoring. But then I have problems with copy/paste and reloading the file, etc.

 

When I create a MultiLeader manually in AutoCAD, there is a binding or anchoring by default. If I move the entity, the MultiLeader Line will follow. Which mechanism is used here? When I create it programmatically, this anchoring doesn't happen. 

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.