.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Adding objects to the PICKFIRST set.

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
Ertqwa
807 Views, 6 Replies

Adding objects to the PICKFIRST set.

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.

6 REPLIES 6
Message 2 of 7
Artvegas
in reply to: Ertqwa

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

Message 3 of 7

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

Message 4 of 7
Ertqwa
in reply to: Artvegas

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.

Message 5 of 7
Ertqwa
in reply to: DiningPhilosopher

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.

Message 6 of 7
Jeff_M
in reply to: Ertqwa


@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
mcicognani
in reply to: Ertqwa

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

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost