Reputation: 41
I am working in AutoCad and with Excel VBA. In my code, I read in a Excel Worksheet the info that I need from the drawing including the Handle of the Entities I am interested on.
My next step is to verify some Acad Drawing info based on Excel calculations. For this, I pick the Entities Handle ID on Excel and it highlights the Entity on Acad. Some times Entities highlighting doesn't do enough contrast to differentiate the entity of my interest between all the other objects.
It would be better if the entity I need to verify get selected, as it is made in Acad environment with the mouse. Unfortunately, the practical way to verify the info is accessing by the Handle ID.
I have looked for alternatives in Internet and found something regarding with SelectionSets, but result was not different of just highlight the entity.
Any suggestion to select (as with the mouse) or to improve the colors or highlighting characteristics of the entities?
The code I am using is:
'''Sub dfSelHnd()
Dim actldwg As AcadDocument
Dim tAr(0) As AcadEntity 'Add items to selectionset must be done with arrays
Dim rng As Range
Dim txt As String
''---
''---
''---
Set rng = Selection
Set actldwg = AutoCAD.Application.ActiveDocument
txt = rng.Value '' txt is the HandleID
Set tAr(0) = actldwg.HandleToObject(txt)
Call zoomit(actldwg, tAr(0))
tAr(0).Highlight (True)
End Sub'''
Here the visualization examples:
Upvotes: 0
Views: 2875
Reputation: 1697
You can select entities in VBA by select group.
ThisDrawing.SendCommand ("_SELECT" + vbCr + "G" + vbCr + GroupName + vbCr + vbCr)
So first You need to create selectionset, then make a group from selectionset. Full sample would be:
Public Sub Test()
Dim ssh As AcadSelectionSet
Dim Ftyp(1) As Integer
Dim Fdat(1) As Variant
Dim BlockName As String
BlockName = "A-1"
Dim F1, F2 As Variant
Ftyp(0) = 0: Fdat(0) = "Insert"
Ftyp(1) = 2: Fdat(1) = BlockName
Set sstest = ThisDrawing.SelectionSets.Add("sstest")
F1 = Ftyp
F2 = Fdat
sstest.Select acSelectionSetAll, , , Ftyp, Fdat
Dim GroupName As String
GroupName = "sstest"
Dim group As AcadGroup
Set group = ThisDrawing.Groups.Add(GroupName)
For Each Item In sstest
group.AppendItems (Item)
Next
sstest.Delete
ThisDrawing.SendCommand ("_SELECT" + vbCr + "G" + vbCr + GroupName + vbCr + vbCr)
group.Delete
End Sub
This sample code mark selected blocks (by name). Now You should change the way of selection. But it's not the question, so I hope You will handle it easy.
Upvotes: 0