.NET

Reply
Active Contributor
s.hofer
Posts: 42
Registered: ‎06-30-2006
Message 1 of 10 (1,688 Views)
Accepted Solution

highlight a selection set

1688 Views, 9 Replies
03-01-2011 06:57 AM

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

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

 

 

*Expert Elite*
arcticad
Posts: 1,286
Registered: ‎06-21-2004
Message 2 of 10 (1,678 Views)

Re: highlight a selection set

03-01-2011 07:15 AM in reply to: s.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))
Active Contributor
s.hofer
Posts: 42
Registered: ‎06-30-2006
Message 3 of 10 (1,642 Views)

Re: highlight a selection set

03-02-2011 08:09 AM 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...:smileyhappy:

 

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)

 

 

*Expert Elite*
arcticad
Posts: 1,286
Registered: ‎06-21-2004
Message 4 of 10 (1,617 Views)

Re: highlight a selection set

03-02-2011 12:17 PM in reply to: s.hofer

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

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



(defun botsbuildbots() (botsbuildbots))
*Expert Elite*
norman.yuan
Posts: 1,064
Registered: ‎04-27-2009
Message 5 of 10 (1,607 Views)

Re: highlight a selection set

03-02-2011 01:04 PM 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]

Active Contributor
s.hofer
Posts: 42
Registered: ‎06-30-2006
Message 6 of 10 (1,593 Views)

Re: highlight a selection set

03-02-2011 11:47 PM 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)

 

 

Active Contributor
dan.glassman
Posts: 43
Registered: ‎09-23-2008
Message 7 of 10 (1,533 Views)

Re: highlight a selection set

03-03-2011 07:29 AM in reply to: s.hofer

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

 

-drg

*Expert Elite*
norman.yuan
Posts: 1,064
Registered: ‎04-27-2009
Message 8 of 10 (1,528 Views)

Re: highlight a selection set

03-03-2011 08:06 AM in reply to: s.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?

Active Contributor
dan.glassman
Posts: 43
Registered: ‎09-23-2008
Message 9 of 10 (1,496 Views)

Re: highlight a selection set

03-03-2011 07:38 PM in reply to: s.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

 

 

 

Active Contributor
s.hofer
Posts: 42
Registered: ‎06-30-2006
Message 10 of 10 (1,467 Views)

Re: highlight a selection set

03-03-2011 11:25 PM 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

 

 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.