How to retrieve ID of selected object

How to retrieve ID of selected object

Anonymous
Not applicable
2,872 Views
2 Replies
Message 1 of 3

How to retrieve ID of selected object

Anonymous
Not applicable

My goal here is to get the ID of my selected object without using a prompt. For example, the user clicks on a rectangle in the drawing and then clicks on a button from my custom menu. I want to be able to retrieve the ID of this rectangle without getting prompted to pick it first.

 

Right now I'm trying to get the selection set using the PromptSelectionResult value, which asks me to choose the object.

 

I'm guessing there's an easy way of doing this but I can't seem to figure it out... Hopefully this makes sense?

0 Likes
Accepted solutions (1)
2,873 Views
2 Replies
Replies (2)
Message 2 of 3

_gile
Consultant
Consultant
Accepted solution

Hi,

 

If you want to get the pickfirst set content, the button event handler shoud call a cutom command with the Commandflags.UsePickFirst:

 

        [CommandMethod("foo", CommandFlags.UsePickSet)]
        public void Foo()
        {
            var ed = AcAp.DocumentManager.MdiActiveDocument.Editor;
            var selection = ed.SelectImplied();
            if (selection.Status == PromptStatus.OK)
            {
                if (selection.Value.Count == 1)
                {
                    var id = selection.Value[0].ObjectId;
                    AcAp.ShowAlertDialog(id.ObjectClass.Name);
                }
                else
                {
                    AcAp.ShowAlertDialog("More than one object in pickfirst set");
                }
            }
            else
            {
                AcAp.ShowAlertDialog("None pickfirst set");
            }
        }


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 3

Anonymous
Not applicable

Excellent! thank you very much. That worked great

0 Likes