Author Topic: Entity selection with PrompEntityOption  (Read 1999 times)

0 Members and 1 Guest are viewing this topic.

latour_g

  • Newt
  • Posts: 184
Entity selection with PrompEntityOption
« on: July 16, 2014, 11:51:11 AM »
In one of my tool, I need the user to select several objects so I'm using PromptEntityOptions and PromptEntityResult.
The thing is the user has to be able to unselect object during the selection (and I need to know wich object has been unselected).  Is it possible to do that with the current prompt I'm using ?

(Shift + click is not enable while in the prompt)

Thank you
« Last Edit: July 16, 2014, 01:39:03 PM by latour_g »

BillZndl

  • Guest
Re: Entity selection with PrompEntityOption
« Reply #1 on: July 16, 2014, 01:50:32 PM »
Can you use a Selection Set?
It will allow you to add & remove entities and highlights the entities that you've selected and will unhighlight the entities that you remove.
You can also use any of the built in selection options available in AutoCAD.

Here's a quick test I just threw together:

Code: [Select]
[CommandMethod("TestF", CommandFlags.Session)]

        public SelectionSet TestFunctions()
        {
            Document doc = AcadApp.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;

            PromptSelectionOptions pso = new PromptSelectionOptions();
            pso.SingleOnly = false;
            pso.MessageForAdding = "add";
            pso.MessageForRemoval = "remove";

            PromptSelectionResult psr = ed.GetSelection(pso);
            SelectionSet ss = psr.Value;

            return ss;

        }

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Entity selection with PrompEntityOption
« Reply #2 on: July 16, 2014, 01:56:37 PM »
Here is a link to the swamps SelectionSet Library Thread.  There are many useful methods in there regarding selectionsets and one is sure to fit what you need.


http://www.theswamp.org/index.php?topic=31864.msg373461#msg373461
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

latour_g

  • Newt
  • Posts: 184
Re: Entity selection with PrompEntityOption
« Reply #3 on: July 16, 2014, 02:55:13 PM »
Unfortunately I can't use SelectionSet, the user want to pick every single object.  The command Select of Autocad would work but I think I could not get the ObjectId while the object are being select/unselect.

Here is the inferface of my program (sorry if there are spelling errors, it was in french but I change in to english for you), perhaps it's gonna be clearer if I explain more in details what I'm doing.  The user want to calculate the lenght of a pipe network.  So each time he click on an object, it shows the total length.  He can hit pause to break a line or anything he need to do then he can restart is selection and continue to select object.

BillZndl

  • Guest
Re: Entity selection with PrompEntityOption
« Reply #4 on: July 16, 2014, 03:41:19 PM »
Nothing that would be easy I know of.

You could add a button for "remove lines" and have those lines removed from the container and update/report the results.

latour_g

  • Newt
  • Posts: 184
Re: Entity selection with PrompEntityOption
« Reply #5 on: July 16, 2014, 03:45:26 PM »
Yep, that's what's I'm gonna do ! Thanks


Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Entity selection with PrompEntityOption
« Reply #6 on: July 16, 2014, 04:06:41 PM »
You can automate the entire process by using the SelectionAdded and SelectionRemoved event of the editor.  Then you would not have to have an add/remove button on your form.

The objectId is obtained by the e.AddedObjects.GetObjectIds() or the e.RemovedObjects.GetObjectIds() methods.

There is an entry in the post that I linked above that shows how to use the added event to automate this sort of thing.  You should be able to modify it to meet your needs.
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

WILL HATCH

  • Bull Frog
  • Posts: 450
Re: Entity selection with PrompEntityOption
« Reply #7 on: July 18, 2014, 12:11:18 PM »
I don't think Keith's intent was fully understood here.  When your pipe objects are added or removed from the selection set and the events fire you have the opportunity to update your calculations and visuals. 

The only part I'm not sure how to do right now is how to resume after you paused.  Guessing this could be managed somehow with the Editor.PromptingForSelection event

Since you've likely already hacked it together with a prompt entity I would suggest that immediately after the pick is made you check the state of the shift key
Code - C#: [Select]
  1. using System.Windows.Input     // reference PresentationCore.dll
  2. .....
  3. PromptEntityResult per = ed.GetEntity(....);
  4. if(per.Status != PromptStatus.OK) return;
  5. if( Keyboard.IsKeyDown(Key.LeftShift) ||
  6.    Keyboard.IsKeyDown(Key.RightShift))
  7.    {
  8.       //remove per.Value from main set if was already included
  9.    }
  10.    else
  11.    {
  12.       //add per.Value to main set if not already included
  13.    }

This is a HACK and not recommended for any serious use, but will probably save the painful user experience.  PresentationCore.dll is ~4MB in size and will have a performance penalty in loading.