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

Remove selected item from on screen selection

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
greg
829 Views, 5 Replies

Remove selected item from on screen selection

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.

5 REPLIES 5
Message 2 of 6
DiningPhilosopher
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

 

 

Message 3 of 6
DouceDeux
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.

Message 4 of 6


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

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 5 of 6
greg
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. 🙂

 

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

Message 6 of 6
Alexander.Rivilis
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.

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

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