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.
@Anonymous 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
"How we think determines what we do, and what we do determines what we get."
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.