我做过一些vb编程,但不多。使用上面的代码,我得到了一个运行时错误。“需要对象”
调试突出显示此行:
- Sub [color="red"]NameOfYourChoice[/color]()
- ' We create our group codes and data values for our selection set.
- Dim gpCode(1) As Integer
- Dim dataValue(1) As Variant
- Dim SS_Blk As AcadSelectionSet
- Dim i As Integer, n As Integer
-
- SS_delete 1
-
- ' This is our filter.
- ' We set the group codes and data values for what we want to find.
- Set SS_blk = ThisDrawing.SelectionSets.Add("SS_blk")
- gpCode(0) = 0: dataValue(0) = "INSERT"
- gpCode(1) = 8: dataValue(1) = "[color="red"]layer entities are on[/color]"
-
- SS_blk.Select acSelectionSetAll, , , gpCode, dataValue
- ' because VBA is object oriented, we have to create the references for our blocks
- ' We create our blocks and the attributes in our blocks.
- Dim Cur_Blk As AcadBlockReference
- Dim Blk_Atts() As AcadAttributeReference
- Dim Cur_Att As AcadAttributeReference
-
- ' This is where we make our loop
- ' " For i ". " i " is equal to the item number in the selection set
- ' until we get to the count of how many entities in SS_blk -1,
- ' because our item count in a selection set starts at 0 not at 1
- ' like in a collection.
- For i = 0 To SS_blk.Count - 1
- Set Cur_Blk = SS_Example.Item(i)
- Blk_Atts = Cur_Blk.GetAttributes
-
- ' " For n ", " n ' is equal to the attribute number in the current block.
- For n = 0 To UBound(Blk_Atts)
- Set Cur_Att = Blk_Atts(n)
-
- If Cur_Att.TagString = "GROUPID" Then
- CurAtt.textstring = CurAtt.textstring + [color="red"]100[/color]
- ' if the attribute text string = 7 then +2 would put it at 9
- End If
- Next n
- Next i
-
- Application.Update
- End Sub
- '-------------------
- Sub SS_delete(x As Byte)
- If ThisDrawing.SelectionSets.Count > 0 Then
- Dim i As Integer
- On Error Resume Next
- For i = 0 To ThisDrawing.SelectionSets.Count - 1
- ThisDrawing.SelectionSets.Item(i).Delete
- Next i
- On Error GoTo 0
- End If
- End Sub
我对这件事还不太熟悉。 |