Adding objects to the PICKFIRST set.

Adding objects to the PICKFIRST set.

Ertqwa
Advocate Advocate
1,273 Views
6 Replies
Message 1 of 7

Adding objects to the PICKFIRST set.

Ertqwa
Advocate
Advocate

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.

0 Likes
Accepted solutions (1)
1,274 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable

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

0 Likes
Message 3 of 7

DiningPhilosopher
Collaborator
Collaborator

You need to define your command method with the CommandFlags.Redraw flag in order to set the pickfirst selection.

0 Likes
Message 4 of 7

Ertqwa
Advocate
Advocate

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.

0 Likes
Message 5 of 7

Ertqwa
Advocate
Advocate

Hello.

 

Redraw:

When the pickfirst set or grip set are retrieved, they are not cleared within AutoCAD.
Command can retrieve the pickfirst set and the grip set by using the ads_ssgetfirst function.
Command can retrieve the pickfirst set via ads_ssget("I.").
Command can set both the pickfirst and grip sets using the ads_sssetfirst function. Objects in these sets are redrawn with the proper grip handles and highlighting upon completion of the command. 

Seems like I should use it, but without it the command works exactly the same. It doesn't solve the problem.
Thank you for your response.

0 Likes
Message 6 of 7

Jeff_M
Consultant
Consultant
Accepted solution

@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.

Jeff_M, also a frequent Swamper
EESignature
Message 7 of 7

Anonymous
Not applicable

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); }
0 Likes