how to select entity programmatically c#

goldhorse.million
Advocate
Advocate

how to select entity programmatically c#

goldhorse.million
Advocate
Advocate

Now I am making a function that select entities with some values(objectid...).

For example after I get closed polyline, I save it to Entity list.
When I want to see that polyline I select a button.
Just that moment every Entity list item should be selected.

Could someone can help  me?

List<Entity> entlist = new List<Entity>();
foreach (Polyline wpl in Plugin.awindowpline)
                            {
                                  entlist.Add(wpl);                                  
                            }
0 Likes
Reply
Accepted solutions (1)
1,150 Views
4 Replies
Replies (4)

_gile
Mentor
Mentor

Hi,

 

Have a look at the Editor.SetImpliedSelection method.

 

PS: We do not know what is 'Plugin.awindowpline' but it looks like a static field containig a collection of Polyline instances. As said in another post, it is a very bad practice to use DBObjects (such as entities) outside of the scope of the transaction used to new or open them. You should use an ObjecId collection instead.

You should study this section of the docs (at least the two first topics: Work With ObjectIds and Use Transactions With the TransactionManager).



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes

goldhorse.million
Advocate
Advocate

Hi, _gile. Thanks for your reply.

Editor.SetImpliedSelection function has SelectionSet parameter.

Even if I have that entity's objectId how can I select that entity by using Editor.SetImpliedSelection function in other transaction. I should make it in other transaction. 

Here number is index of list and err is class including ObjectId List.

Error statement:

Severity Code Description Project File Line Suppression State
Error CS1503 Argument 1: cannot convert from 'Autodesk.AutoCAD.DatabaseServices.ObjectId' to 'Autodesk.AutoCAD.EditorInput.SelectionSet' 

 

Document curdoc = Application.DocumentManager.MdiActiveDocument;
                    var database = curdoc.Database;
                    var ed = curdoc.Editor;
                    using (DocumentLock docLock = curdoc.LockDocument())
                    {
                        using (Transaction acTrans = database.TransactionManager.StartTransaction())
                        {
                            ed.SetImpliedSelection(err.objIdlist[number]);
                            acTrans.Commit();
                        }
                        ed.UpdateScreen();
                    }

 

 

0 Likes

_gile
Mentor
Mentor
Accepted solution

@goldhorse.million  a écrit :

Editor.SetImpliedSelection function has SelectionSet parameter.


You did not attentively read the docs Editor.SetImpliedSelection is overloaded it can use either a SelectionSet or an ObjectId[]  (array of ObjectIds).

 

You do not need to call this method inside of a transaction because it only requires ObjectIds.

Assuming objIdList is of type: List<ObjectId>, you can simply do:

ed.SetImpliedSelection(objIdlist.ToArray());

 

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

goldhorse.million
Advocate
Advocate

I really appreicate your help.

0 Likes