highlight a selection set

highlight a selection set

stefan.hofer
Advocate Advocate
7,411 Views
10 Replies
Message 1 of 11

highlight a selection set

stefan.hofer
Advocate
Advocate

in vba i can highlight a selectionSet with

sset.Highlight(true)

how can i do this with vb.net? with the same command i get no error or warning, but nothing is highlighted in autocad...

0 Likes
Accepted solutions (1)
7,412 Views
10 Replies
Replies (10)
Message 2 of 11

arcticad
Advisor
Advisor

 

Using db As Database = HostApplicationServices.WorkingDatabase()
            Using tr As Transaction = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction()
                Dim myDWG As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
                Using lock As DocumentLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument
                    Dim ed As Editor = myDWG.Editor
                    Dim getSelectionResult As PromptSelectionResult = ed.GetSelection()
                    If getSelectionResult.Status = PromptStatus.OK Then
                        For i = 0 To getSelectionResult.Value.Count - 1
                            Dim myEnt As Entity = TryCast(tr.GetObject(getSelectionResult.Value(i).ObjectId, OpenMode.ForRead), Entity)
                            myEnt.Highlight() ' or unhighlight
                        Next
                    End If
                End Using
            End Using
        End Using

 

 

---------------------------



(defun botsbuildbots() (botsbuildbots))
0 Likes
Message 3 of 11

stefan.hofer
Advocate
Advocate

Thank you for this example , but i'll not pick items.

I have already a selection set.

The code works, i can try to find a solution myself - pearhaps...Smiley Happy

 

my sset:

 

        Dim EditArt As String

        For i = 0 To ListBox1.Items.Count - 1
            If ListBox1.SelectedItem(i) Then
                EditArt = ListBox1.SelectedItem.ToString()
            End If
        Next i


        Dim acApp As Object, acDoc As Object
        Dim fType(1), fData(1), sset As Object
        acApp = GetObject(, "autocad.application")
        acDoc = acApp.ActiveDocument

        On Error Resume Next
        sset = acDoc.SelectionSets.Add("h1")

        fType(0) = 0 : fData(0) = "INSERT"
        fType(1) = 2 'DXF-GroupCode
        fData(1) = EditArt 'Name
        'Select Blocks
        sset.Select(acSelectionSetAll, , , fType, fData)

 

 

0 Likes
Message 4 of 11

arcticad
Advisor
Advisor

hint: Take each item in your selection set and convert it to an entity.

---------------------------



(defun botsbuildbots() (botsbuildbots))
0 Likes
Message 5 of 11

norman.yuan
Mentor
Mentor

The OP uses COM API, so the items in the selection set is already entity (AcadEntity, not Autodesk.AutoCAD.DatabaseServices.Entity). He cannot use your code sample.

 

To the OP.

 

Are you doing in stand-alone exe that automates AutoCAD?

 

Since you use COM API, you can do the same as you do in VBA:

 

AcadSelectionSet.Highlight True[False]

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 6 of 11

stefan.hofer
Advocate
Advocate
  • I'm using a palette in autocad, not a exe.
  • in my selectionset are autocad blocks (all blocks with the same name)
  • And i try to Highlight all blocks with the same name (Blockname selected in a ListBox)

sset.Highlight(True) dont work.

vba example attached. (screenshot)

 

 

0 Likes
Message 7 of 11

Anonymous
Not applicable

Call sset.Application.Update() after sset.Highlight(True)

 

-drg

Message 8 of 11

norman.yuan
Mentor
Mentor

Dan's reply would get it to work (but I did not try), although the call to AcadApplication.Update in VBA is not needed. This, I guess, is because of your code calling the COM API from the .NET API, the extra layer of communication.

 

Surely, one can use COM API in the managed API, when necessary. But why you do you have to use COM API for the operation that managed API can do it perfectly in the first place?

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 9 of 11

Anonymous
Not applicable

The behavior the OP asks about is strange; I hadn't even tried it in .Net until now.  I _don't_ need the AcadApplication.Update() in .Net, whether in app context or doc context.

 

The only circumstance in which I needed it was when running out-of-process.  I was originally testing with python; I needed it out-of-process under all circumstances.  Never in-process, with python embedded via arx.

 

So...I can't replicate the behavior at all.  If what's been posted so far doesn't help, s.hover, please post more code.

 

-drg

 

 

 

0 Likes
Message 10 of 11

stefan.hofer
Advocate
Advocate
Accepted solution

whooo i found the wrong code, the problem was not the highlight.

 

sset.Select(AcSelect.acSelectionSetAll, , , fType, fData)

AcSelect

 

ty for your time.

 

this sub works:

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim acApp As Object, acDoc As Object
        Dim fType(1) As Short
        Dim fData(1) As Object
        Dim sset As AcadSelectionSet
        acApp = GetObject(, "autocad.application")
        acDoc = acApp.ActiveDocument

        Dim EditArt As String
        EditArt = ListBox1.SelectedItem.ToString()

        'On Error Resume Next
        sset = acDoc.SelectionSets.Add("h1")

        'Block-Filter setzen
        fType(0) = 0 : fData(0) = "INSERT"
        fType(1) = 2 'DXF-GroupCode
        fData(1) = EditArt 'Name
        'Select Blocks
        sset.Select(AcSelect.acSelectionSetAll, , , fType, fData)

        'Highlight my SelectionSet
        sset.Highlight(True)

        acDoc.SelectionSets.Item("h1").Delete()
        Label4.Text = EditArt
        acDoc.SendCommand("_.PSPACE" & vbCr)
    End Sub

 

 

0 Likes
Message 11 of 11

mucip
Collaborator
Collaborator

Hi @Anonymous ,

Call Application.Update

 

worked like a charm for me. Thanks.

 

Regards,

Mucip:)

0 Likes