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...
Solved! Go to Solution.
Solved by stefan.hofer. Go to Solution.
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
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...
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)
hint: Take each item in your selection set and convert it to an entity.
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
sset.Highlight(True) dont work.
vba example attached. (screenshot)
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
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
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
Can't find what you're looking for? Ask the community or share your knowledge.