Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi Team, I have to get the vertices or Grip points of a MULTILEADER and looking for C# code for that.
Solved! Go to Solution.
Hi Team, I have to get the vertices or Grip points of a MULTILEADER and looking for C# code for that.
Solved! Go to Solution.
Have you looked into/tried with MLeader.GetVertex(int, int) ? You may also need to look into MLeader.GetFirst[Last]Vertex(int).
Hi Norman. I have tried both options but getting the attached exception (Exception.PNG). Can you please suggest me what I am doing wrong here.
This is my code, please let me know for any other information.
Entity ent = tr.GetObject(selObj.ObjectId, OpenMode.ForRead) as Entity;
MLeader mLeader = ent as MLeader;
Point3d pntFirst = mLeader.GetVertex(0, 0); or Point3d pntFirst = mLeader.GetFirstVertex(0);
I am getting same exception for when tried using both options.
Well, following code works for me with a simple MLeader entity as shown in picture below:
[CommandMethod("MLTest")]
public static void TestMLeader()
{
var dwg = CadApp.DocumentManager.MdiActiveDocument;
var ed = dwg.Editor;
var res = ed.GetEntity("\nSelect an MLEADER entity:");
if (res.Status == PromptStatus.OK)
{
using (var tran = dwg.TransactionManager.StartTransaction())
{
var mleader = (MLeader)tran.GetObject(res.ObjectId, OpenMode.ForRead);
var leaderIndex = (int)mleader.GetLeaderIndexes()[0];
var leaderlineIndexes = mleader.GetLeaderLineIndexes(leaderIndex);
var leaderlineIndex = (int)leaderlineIndexes[0];
var firstVertex = mleader.GetFirstVertex(leaderlineIndex);
var lastVertex = mleader.GetLastVertex(leaderlineIndex);
ed.WriteMessage(
$"\nFirst vertex = {firstVertex.ToString()}");
ed.WriteMessage(
$"\nLast vertex = {lastVertex.ToString()}");
var vertex = mleader.GetVertex(leaderlineIndex, 0);
ed.WriteMessage(
$"\nFirst vertex of the first leader line = {vertex.ToString()}");
tran.Commit();
}
}
}
Basically, you need to call GetLeaderIndexes() and GetLeaderLineIndexes() to see if there is how many leaders and how many leader lines. there could be leader only (i.e. a leader without leader line). Since you need to get vertex on LEADERLINE, there must be at least one LeaderLine for your code to work.
Hi Norman, thanks for the code sample and looks like I am able to get the vertices now and only thing missing in my code was
var leaderlineIndex = (int)leaderlineIndexes[0];
I was passing leaderlineIndexes to find the first or last vertex.