.NET

Reply
Active Contributor
greg
Posts: 33
Registered: ‎02-13-2013
Message 1 of 6 (340 Views)
Accepted Solution

Remove selected item from on screen selection

340 Views, 5 Replies
02-16-2013 01:51 PM

I have other related posts but felt this was a separate question that could deserve its own post so here goes.

 

I presently have code that will select objects on screen based on particular stored object handles.  The code then prompts the user to add additional selections once these handle selections are made.  No problem.  The problem lies with attempting to deselect the objects that were selected via object handles.  I should say highlighted because that is what the present code is doing.  It is highlighting the objects on screen.  The code I am using follows:

 

 

                Dim ids(1) As ObjectId
                ids(0) = ObjectIdFromHandle(myDocDB, "1D6")
                ids(1) = ObjectIdFromHandle(myDocDB, "1DE")
                Autodesk.AutoCAD.Internal.Utils.SelectObjects(ids)

                '  Get the Pickfirst selection set
                Dim acSSPrompt As PromptSelectionResult
                acSSPrompt = ed.SelectImplied()

                Dim Objs As ObjectIdCollection
                If acSSPrompt.Status = PromptStatus.OK Then
                    Objs = New ObjectIdCollection(acSSPrompt.Value.GetObjectIds)
                Else
                    Objs = New ObjectIdCollection
                End If

                ed.SetImpliedSelection(New ObjectId(-1) {})
                If Objs.Count > 0 Then
                    HighlightEntities(Objs)
                End If
                acSSPrompt = ed.GetSelection()
                If acSSPrompt.Status = PromptStatus.OK Then
                    For Each obj As ObjectId In acSSPrompt.Value.GetObjectIds
                        Objs.Add(obj)
                    Next
                    Dim ids2 As ObjectId() = New ObjectId(Objs.Count - 1) {}
                    Objs.CopyTo(ids, 0)
                    ed.SetImpliedSelection(ids2)
                End If


    Private Sub HighlightEntities(objIds As ObjectIdCollection)
        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim tr As Transaction = doc.TransactionManager.StartTransaction()
        Using tr
            For Each objId As ObjectId In objIds
                Dim ent As Entity = TryCast(tr.GetObject(objId, OpenMode.ForRead), Entity)
                If ent IsNot Nothing Then
                    ent.Highlight()

                End If
            Next
        End Using
    End Sub

 

Thanks in advance for any help anyone can provide.

Highlighting and selecting are two very different things. 

 

The problem you have is that you want to allow a user to 'edit' a selection. Unfortunately, there is no built-in API that allows that.  It can be done, but involves the use of a kludge.

 

See this swamp post

 

 

Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 2 of 6 (299 Views)

Re: Remove selected item from on screen selection

02-19-2013 09:05 PM in reply to: greg

Highlighting and selecting are two very different things. 

 

The problem you have is that you want to allow a user to 'edit' a selection. Unfortunately, there is no built-in API that allows that.  It can be done, but involves the use of a kludge.

 

See this swamp post

 

 

Active Contributor
DouceDeux
Posts: 46
Registered: ‎09-04-2012
Message 3 of 6 (286 Views)

Re: Remove selected item from on screen selection

02-20-2013 05:56 AM in reply to: greg

I'm not sure I'm reading it right or this is a topic I don't know much about.

But, if you want to deselect something (at this point you should have a SelectionSet built through an ObjectId array - ObjectId[]) can't you just create a new SelectionSet without the ObjectId selected for deselection and then set the new Implied selection?

 

[CommandMethod("test1", CommandFlags.UsePickSet|CommandFlags.Redraw)]
public void test1()
{
  //You may create the original seletion here or already have it at this point
  
  //Ask for an object to deselect
  ObjectId[] MyObjectIds = new ObjectId[count-1];
  //Create new selection without the object to deselect
  newEditor.SetImpliedSelection(MyObjectIds);
}

 Or maybe what you want is to get the current selection after the deselecting objects (Shift + Click) which would be:

 

[CommandMethod("test2", CommandFlags.UsePickSet|CommandFlags.Redraw)]
public void test2()
{
  Document newDoc = Application.DocumentManager.MdiActiveDocument;
  Editor newEditor = newDoc.Editor;

  PromptSelectionResult newPSR = newEditor.SelectImplied();

  if (newPSR.Status == PromptStatus.Error)
  {
    //This happens when nothing was selected when using SelectImplied()
    //You may ommit this control and just use the next one, not sure, try it either way.
  }
  if (newPSR.Status == PromptStatus.OK)
  {
    //Do something with the selection.
  }
}

 You need to commandflag UsePickSet to use SelectImplied and that other function correctly.

You need Redraw for your new selection to show properly after using newEditor.Regen(); which you should add at the end of your commands if you want to regenerate the current view of AutoCAD model space.

Moderator
Alexander.Rivilis
Posts: 1,412
Registered: ‎04-09-2008
Message 4 of 6 (276 Views)

Re: Remove selected item from on screen selection

02-20-2013 06:44 AM in reply to: DouceDeux

DouceDeux wrote:

I'm not sure I'm reading it right or this is a topic I don't know much about.


He wants to give the user ability to operate with previous selected entities (add new primitives to selectionset or remove existing entities from selectionset).

 

Tony (DiningPhilosopherdid exactly what greg asked. And he did it very beautiful in his own style!


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Active Contributor
greg
Posts: 33
Registered: ‎02-13-2013
Message 5 of 6 (269 Views)

Re: Remove selected item from on screen selection

02-20-2013 07:01 AM in reply to: greg

hmm...Never heard of a kludge.  I will need to look into this.  I will also look at the swamp post and see what I can make work.  Thanks for the link  DiningPhilosopher   

 

Alexander, was your response to Tony a sarcastic response or do you agree with Tony's response and Swamp post?  Just curious. :smileyhappy:

 

Thanks, I will let you know how I make out.

Moderator
Alexander.Rivilis
Posts: 1,412
Registered: ‎04-09-2008
Message 6 of 6 (265 Views)

Re: Remove selected item from on screen selection

02-20-2013 07:11 AM in reply to: greg

No sarcasm! I respect Tony for his knowledge and for the fact that he shares this knowledge with others. I believe that this forum is at a high level thanks to Tony! If you do not be lazy and read this forum, you will find that Tony answers the questions more than a dozen years. He's the only one who dedicate a separate topic on this forum.


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.