The GetEnumerator method of the BlockTableRecord returns a BlockTableRecordEnumerator which does implement IDisposable.
GetEnumerator is being called on the BlockTableRecord in the examples above not on an AttributeCollection.
Just a bit of my 2¢ and having seen an example from ADN ID: TS88193 which applies to AutoCAD® 2007 and AutoCAD® 2008 versions, you will see that they also use as an example:
Dim iEnumerator As IEnumerator = btr.GetEnumerator()
'Try to get the attribute in the block definition
While (iEnumerator.MoveNext())
....
C# or VB both use it. Of course that doesn't have to make it correct, look how well these forums work. Bottom line: Does it work for you? If so run with it and get on with the show.
I've used something like this in the past to read attributes.
<CommandMethod("attRefs")> Public Sub attRefs()
Call GetAttributes("YourBlockName")
End Sub
Private Sub GetAttributes(ByVal NameOfBlock As String)
Dim findThis() As TypedValue = {New TypedValue(0, "INSERT"), New TypedValue(2, NameOfBlock)}
Dim sf = New SelectionFilter(findThis)
Dim psr As PromptSelectionResult = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.SelectAll(sf)
If psr.Status = PromptStatus.OK Then
Using t As Transaction = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction()
For Each h As ObjectId In From q As ObjectId In psr.Value.GetObjectIds()
Dim br = CType(t.GetObject(h, OpenMode.ForRead), BlockReference)
For i As Integer = 0 To br.AttributeCollection.Count - 1
Dim ar As AttributeReference = CType(t.GetObject(br.AttributeCollection(i), OpenMode.ForRead), AttributeReference)
MsgBox(ar.TextString)
Next
Next
t.Commit()
End Using
End If
End Sub
Tony, I really would like to see your For Each AttributeReference Next example. I could probably learn even more and somebody might even hire my unemployed a$$ but then we would all miss these lively discussions.
That looks like a pretty poor example from ADN given that the GetEnumerator method of BlockTableRecord returns a BlockTableRecordEnumerator type. Although I am making the assumption they have not changed the return type from IEnumerator in 2009.
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<Mikko> wrote in messagePrivate
href="news:6116880@discussion.autodesk.com">news:6116880@discussion.autodesk.com...
Sub GetAttributes(ByVal NameOfBlock As String)
Dim findThis() As
TypedValue = {New TypedValue(0, "INSERT"), New TypedValue(2,
NameOfBlock)}
Dim sf = New SelectionFilter(findThis)
Dim psr As
PromptSelectionResult =
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.SelectAll(sf)
If
psr.Status = PromptStatus.OK Then
Using t As Transaction =
HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction()
For
Each h As ObjectId In From q As ObjectId In
psr.Value.GetObjectIds()
Dim br = CType(t.GetObject(h,
OpenMode.ForRead), BlockReference)
For Each k As ObjectId In
br.AttributeCollection
Dim ar As AttributeReference =
CType(t.GetObject(k, OpenMode.ForRead),
AttributeReference)
MsgBox(ar.TextString)
Next
k
Next
t.Commit()
End Using
End If
End
Sub
Yes you are correct but it doesn't seem to shorten my code
any that I posted earlier. I'm off to Denny's for the free Grand Slam
Breakfast. Today only. Later.....
I think you need sleep beacause you aren't making any sense.
My original post was an example of using For Each and how it correlates to GetEnumerator.
I now realise your reaction was because you think I was telling you that you could shorten your For i To code. I don't know how you came to that conclusion.
Can't find what you're looking for? Ask the community or share your knowledge.