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