VBA - information on selection
Hello,Q1: How do I get the number of entities in a selection using VBA?
Q2: What is the command/method to find the type of each entity in a selection using VBA?
Thank you A1: use .Count method of SelectionSet object
A2: you could use typeOf() like:
If typeOf acEnt Is AcadLine then ...
and the likes where acEnt is some AcadEntity type variable you're looping through SelectionSet with Heres my example-attempt:
Sub test() 'define a named function'Filter for circles - I don't know how to implement this type of filtering: 'Dim gpCode(0) As Integer 'Dim dataValue(0) As Variant 'gpCode(0) = 0 'dataValue(0) = "Circle" Dim SS As AcadSelectionSet 'Declare "SS" variable as local Set SS = ThisDrawing.SelectionSets.Add("NewSS") 'create a new selection set object SS.SelectOnScreen 'select the objects to change (invoke the "SelectOnScreen" method) For Each Entity In SS 'iterate over the selection set If Entity.ObjectName = "AcDbCircle" Then 'Filter for circles by objectname Entity.color = 1 'change entity's colour End If Next 'process the next entity MsgBox SS.Count 'alert the total selected amount of objects SS.Delete 'delete the selection set object End Sub
I'm just starting to learn about VBA, so any inputs are appreciated. Grr this may be usefull
Dim FilterDXFCode(0) As IntegerDim FilterDXFVal(0) As VariantFilterDXFCode(0) = 0FilterDXFVal(0) = "INSERT"'FilterDXFCode(1) = 2'FilterDXFVal(1) = "SCHEDTEXT"Set SS = ThisDrawing.SelectionSets.Add("pit1sel")SS.Select acSelectionSetAll, , , FilterDXFCode, FilterDXFValfor circleFilterDXFVal(0) = "CIRCLE"lisp (0 . "Insert") Thanks BIGAL!
This second shot worked:
Sub test() 'define a named functionDim FilterDXFCode(0) As Integer Dim FilterDXFVal(0) As Variant FilterDXFCode(0) = 0 FilterDXFVal(0) = "CIRCLE" Dim SS As AcadSelectionSet 'Declare "SS" variable as local Set SS = ThisDrawing.SelectionSets.Add("NewSS") 'create a new selection set object 'SS.Select acSelectionSetWindow , , , FilterDXFCode, FilterDXFVal '
页:
[1]