Message 1 of 3
No need to iterate through every entity in the drawing

Not applicable
03-17-2009
01:03 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
The For Each loop in CodeOne_Click works fine. I use CodeTwo_Click to not iterate through every entity in the drawing. But the For Each loop falls back into an error when not only blocks are in a drawing. Where do I get wrong?
Thx
Private Const Selectedblock = "TREE"
Private Sub CodeOne_Click()
Dim oEntity As AcadEntity
Dim oBlkRef As AcadBlockReference
For Each oEntity In ThisDrawing.ModelSpace
If TypeOf oEntity Is AcadBlockReference Then
Set oBlkRef = oEntity
If oBlkRef.EffectiveName = Selectedblock Then
oBlkRef.Visible = True
End If
End If
Next oEntity
End Sub
Private Sub CodeTwo_Click()
Dim oBlkRef As AcadBlockReference
For Each oBlkRef In ThisDrawing.ModelSpace
If oBlkRef.EffectiveName = Selectedblock Then
Call getBlockReference(oBlkRef.Handle)
oBlkRef.Visible = True
End If
Next oBlkRef
End Sub
Private Sub getBlockReference(ByVal sHandle As String)
Dim oBlkRef As AcadBlockReference
On Error GoTo 0 ' turn on the default error handler
Set oBlkRef = ThisDrawing.HandleToObject(sHandle)
End Sub
The For Each loop in CodeOne_Click works fine. I use CodeTwo_Click to not iterate through every entity in the drawing. But the For Each loop falls back into an error when not only blocks are in a drawing. Where do I get wrong?
Thx
Private Const Selectedblock = "TREE"
Private Sub CodeOne_Click()
Dim oEntity As AcadEntity
Dim oBlkRef As AcadBlockReference
For Each oEntity In ThisDrawing.ModelSpace
If TypeOf oEntity Is AcadBlockReference Then
Set oBlkRef = oEntity
If oBlkRef.EffectiveName = Selectedblock Then
oBlkRef.Visible = True
End If
End If
Next oEntity
End Sub
Private Sub CodeTwo_Click()
Dim oBlkRef As AcadBlockReference
For Each oBlkRef In ThisDrawing.ModelSpace
If oBlkRef.EffectiveName = Selectedblock Then
Call getBlockReference(oBlkRef.Handle)
oBlkRef.Visible = True
End If
Next oBlkRef
End Sub
Private Sub getBlockReference(ByVal sHandle As String)
Dim oBlkRef As AcadBlockReference
On Error GoTo 0 ' turn on the default error handler
Set oBlkRef = ThisDrawing.HandleToObject(sHandle)
End Sub