Vertices or Grip Points of MULTILEADER

Vertices or Grip Points of MULTILEADER

subash.nalla
Enthusiast Enthusiast
364 Views
4 Replies
Message 1 of 5

Vertices or Grip Points of MULTILEADER

subash.nalla
Enthusiast
Enthusiast

Hi Team, I have to get the vertices or Grip points of a MULTILEADER and looking for C# code for that.

0 Likes
Accepted solutions (1)
365 Views
4 Replies
Replies (4)
Message 2 of 5

norman.yuan
Mentor
Mentor

Have you looked into/tried with MLeader.GetVertex(int, int) ? You may also need to look into MLeader.GetFirst[Last]Vertex(int).

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 5

subash.nalla
Enthusiast
Enthusiast

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.

 

 

0 Likes
Message 4 of 5

norman.yuan
Mentor
Mentor
Accepted solution

Well, following code works for me with a simple MLeader entity as shown in picture below: 

normanyuan_0-1745253314963.png

 

        [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.

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 5 of 5

subash.nalla
Enthusiast
Enthusiast

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.

0 Likes