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?
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 😉 )
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.
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
HTH, - alfred -
>>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.
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 -
>>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()
Hi,
when your first command finshed and you use AutoCAD command _SELECT with option _P ... does that work?
- alfred -
Yep, with _Select _Previous it works. I try send string to execute from code, but maybe I doing something wrong.
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 -
Can't find what you're looking for? Ask the community or share your knowledge.