Here is a bit cleaner version. When using Reflector to convert code it
changes enum names to their value - hence the '0' instead of
'OpenMode.ForRead'. Also I should have added a 'Continue For' to avoid the
overhead of the second 'If' statement.
{code}
Private Shared Sub _
NestedCircles(ByVal tr As Transaction, ByVal br As BlockReference, ByRef
count As Integer)
Dim btr As BlockTableRecord = _
DirectCast(tr.GetObject(br.BlockTableRecord, OpenMode.ForRead),
BlockTableRecord)
If btr IsNot Nothing Then
For Each id As ObjectId In btr
Dim e As Entity = DirectCast(tr.GetObject(id, OpenMode.ForRead),
Entity)
If TypeOf e Is Circle Then
count += 1
Continue For
End If
'recursive call if nested block ref is found.
If TypeOf e Is BlockReference Then
NestedCircles(tr, DirectCast(e, BlockReference), count)
End If
Next
End If
End Sub
{code}
"Paul Richardson"
wrote in message
news:6233545@discussion.autodesk.com...
This will count all circles in a block including any in blocks nested in the
block. Should give you some ideas.
{code}
Private Shared Sub NestedCircles _
(ByVal tr As Transaction, ByVal br As BlockReference, ByRef count As
Integer)
Dim btr As BlockTableRecord = tr.GetObject(br.BlockTableRecord, 0)
If (Not btr Is Nothing) Then
Dim id As ObjectId
For Each id In btr
Dim e As Entity = tr.GetObject(id, 0)
If TypeOf e Is Circle Then
count += 1
End If
'recursive call for nested blocks.
If TypeOf e Is BlockReference Then
NestedCircles(tr, DirectCast(e, BlockReference), count)
End If
Next
End If
End Sub
{code}
wrote in message
news:6233414@discussion.autodesk.com...
Does any body know how to loop thru all the entity in a block.
Using docLock As DocumentLock =
Application.DocumentManager.MdiActiveDocument.LockDocument()
Using db As Database =
ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database
Using tr As Transaction =
db.TransactionManager.StartTransaction
Try
Dim tbl As BlockTable =
tr.GetObject(db.BlockTableId, OpenMode.ForRead)
Dim bfound As Boolean = False
For Each id As ObjectId In tbl
Dim btr As BlockTableRecord = tr.GetObject(id,
OpenMode.ForRead)
If btr.IsAnonymous = False And btr.IsLayout =
False Then
If UCase(btr.Name) = UCase("Test") Then
Dim sp As ObjectId = btr.BlockBeginId
Dim ep As ObjectId = btr.BlockEndId
For p As Integer = sp To ep step 1.0
'I think something like
this
Next
tr.Commit()
Catch ex As Exception
MsgBox(ex.ToString, MsgBoxStyle.Critical,
"Error...")
tr.Abort()
End Try
End Using
End Using
End Using