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

highlight a selection set

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
stefan.hofer
6678 Views, 10 Replies

highlight a selection set

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

10 REPLIES 10
Message 2 of 11
arcticad
in reply to: stefan.hofer

 

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))
Message 3 of 11
stefan.hofer
in reply to: arcticad

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)

 

 

Message 4 of 11
arcticad
in reply to: stefan.hofer

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

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



(defun botsbuildbots() (botsbuildbots))
Message 5 of 11
norman.yuan
in reply to: arcticad

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]

Message 6 of 11
stefan.hofer
in reply to: norman.yuan

  • 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)

 

 

Message 7 of 11
dan.glassman
in reply to: stefan.hofer

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

 

-drg

Message 8 of 11
norman.yuan
in reply to: stefan.hofer

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?

Message 9 of 11
dan.glassman
in reply to: stefan.hofer

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

 

 

 

Message 10 of 11
stefan.hofer
in reply to: dan.glassman

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

 

 

Message 11 of 11
mucip
in reply to: dan.glassman

Hi @dan.glassman ,

Call Application.Update

 

worked like a charm for me. Thanks.

 

Regards,

Mucip:)

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