Hello Forum,
I add an entity to the PICKFIRST selection set as follows.
Editor.SetImpliedSelection(new ObjectId[] { oiTarget }); entTarget.Highlight(); // Entity.
After this, I can type the CAD command "erase", and the selected entity is erased. However, if I press the DELETE key the entity is not erased (nothing happens). Why is that?
If I select something on screen with my cursor, the DELETE will erase it.
Thank you for you time.
Solved! Go to Solution.
Solved by Jeff_M. Go to Solution.
I tried the following command in both AutoCAD 2012 and 2013 and I had no problem with either ERASE or the DEL key. I didn't need to call Entity.Highlight() for the entities to be highlighted either. Has it got to do with some other part of your code?
[CommandMethod("MyCommand")] static public void MyCommand() { Document doc = Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; PromptEntityResult per = ed.GetEntity("\nSelect entity: "); if (per.Status != PromptStatus.OK) return; ObjectId id = per.ObjectId; ed.SetImpliedSelection(new ObjectId[] { id }); }
Art
You need to define your command method with the CommandFlags.Redraw flag in order to set the pickfirst selection.
Hello,
you are right, I do not need to use highlight. Nice one.
You're code works, unless I do the following:
- Draw a rectangle.
- Move the cursor onto a toolbar (outside the drawing area).
- Active your command by typing the command name.
- Select the entity by typing "last" (so I don't have to move the cursor).
- Pressing the DELETE key: entity doesn't get delete.
- As soon as I move the mouse back into the drawing area, the DELETE key works again.
Eventhough AutoCAD still has the focus, if the cursor is outside the drawing area, DELETE key doesn't erase. Same as with my code.
Didn't notice it until now. Not sure if this is an AutoCAD problem, but maybe more of a windows-topic.
Thank you.
Hello.
Redraw:
@Ertqwa wrote:
....
Eventhough AutoCAD still has the focus, if the cursor is outside the drawing area, DELETE key doesn't erase. Same as with my code.
Didn't notice it until now. Not sure if this is an AutoCAD problem, but maybe more of a windows-topic.
Thank you.
Base AutoCAD commands act exactly the same way.
Draw an object,
Move cursor to the ribbon/toolbar area,
Type in SELECT,
Last, the object you drew is selected,
Enter,
Press delete key, nothing will happen.
The reason is, I believe, due to the need to track what the mouse is doing outside of the drawing canvas, so the drawing no longer has focus.
Have you tried to pass back the focus to graphics window just before exiting your command? Entities should remain selected and DEL key should work.
[DllImport("user32.dll")] private static extern System.IntPtr SetFocus(System.IntPtr hwnd); public static void ActivateEditor() { SetFocus(Autodesk.AutoCAD.ApplicationServices.Application.MainWindow.Handle); }