Community
AutoCAD Forum
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get selected entities using SelectPrevious()

9 REPLIES 9
Reply
Message 1 of 10
Anonymous
737 Views, 9 Replies

Get selected entities using SelectPrevious()

I'm traing to select entities which were selected before ending command.
Here the code:

 

PromptSelectionResult selectionResult = ed.SelectPrevious();
            if (selectionResult.Status == PromptStatus.OK)
            {
                using (Transaction tr = doc.Database.TransactionManager.StartTransaction())
                {
                    SelectionSet previousSelectedEntities = selectionResult.Value;
                    ObjectId[] objIds = previousSelectedEntities.GetObjectIds();
                    Autodesk.AutoCAD.Internal.Utils.SelectObjects(objIds);
                    ed.Regen();
                }
            }

But selectionResult.Status return Error.
How solve this problem?

 

9 REPLIES 9
Message 2 of 10
Alfred.NESWADBA
in reply to: Anonymous

Hi,

 

welcome @Anonymous.autodesk.com!

 

No need for a transaction to get a selectionset

 

Even more important:
>> I'm traing to select entities which were selected before ending command

Do you mean you try to select before your current command started?

Or how is it to understand "before command ending"?

 

- alfred -

PS: the forum for AutoCAD customization with .NET question is >>>there<<< (for your future questions 😉 )

 

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2025
------------------------------------------------------------------------------------

(not an Autodesk consultant)
Message 3 of 10

For example : I select something, then run my custom command. Then in another command I need to select entities which were selected before previous command.

Message 4 of 10

Hi,

 

>> I select something, then run my custom command

So the objects are gripped when you start your command? Then it's the implied-selection set and not the previous selection set!

 

Autodesk.AutoCAD.EditorInput.Editor.SetImpliedSelection(Autodesk.AutoCAD.DatabaseServices.ObjectId())

 

And to make sure your command definition does not kill the selection use the attribute to make sure the command can handle the implied selection set.

Add this attribute to the Runtime.CommandMethod parameters:

 

Autodesk.AutoCAD.Runtime.CommandFlags.UsePickSet

(>>>here are some details<<<)

 

HTH, - alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2025
------------------------------------------------------------------------------------

(not an Autodesk consultant)
Message 5 of 10

>>So the objects are gripped when you start your command?

NO. I select some entities. Then I run my first custom command (in this command I don't need to get selected entities). When my first custom command end work, I run second cusom command in which I need get selected entities which were selected before I run first command.
The problem that when first command end works, all selected elements become deselected. 

Message 6 of 10

Hi,

 

>> The problem that when first command end works, all selected elements become deselected. 

Have you read my hint about UsePickSet ... a command can hold the pickfirstselection set ... or does your first command deselect the currently selected objects?

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2025
------------------------------------------------------------------------------------

(not an Autodesk consultant)
Message 7 of 10

>>or does your first command deselect the currently selected objects?

 

Yep, you're absolutely right. First command deselect currently selected, and when second command run i can't get needed selected element  using selectImplied()

Message 8 of 10

Hi,

 

when your first command finshed and you use AutoCAD command _SELECT with option _P ... does that work?

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2025
------------------------------------------------------------------------------------

(not an Autodesk consultant)
Message 9 of 10

Yep, with _Select _Previous it works. I try send string to execute from code, but maybe I doing something wrong.

Message 10 of 10

Hi,

 

sorry for my limited time ... can you reproduce this with a small sample project with 2 commands, the first does just hello world and the second the selection?

If so then please upload this sample solution, it's less time then to get that in a reproducable state for us.

 

If that does not happen, then your first command does something which blocks the previous selectionset from beeing available after the commands execution. Maybe it's then necessary to look with of the functions in the first command kills it.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2025
------------------------------------------------------------------------------------

(not an Autodesk consultant)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report