Ad

Wednesday, October 10, 2012

Selecting an Object

Usually when you want the user to interact in selecting an object you want them to select a particular type of object. You don’t want to trust their ability to read the command line. In order to do this you can restrict what type of object AutoCAD will allow to be selected.

PromptEntityOptions opt = new PromptEntityOptions("\nSelect polyline near vertex to label: ");
opt.SetRejectMessage("\nObject must be a polyline.\n");
opt.AddAllowedClass(typeof(Polyline), true);
ObjectId polyObjId = ed.GetEntity(opt).ObjectId;



To do this use the PromptEntityOptions to add allowed classes. The hard part I usually come across is finding the class name. To easily discover the class name we can use the typeof() method passing the object type, in the case above Polyline. AutoCAD will then restrict what’s returned to this class type.

No comments:

LinkWithin

Blog Widget by LinkWithin

Ad