Fatty - You don't understand what the 'Using'
directive is. If you don't understand it, then
you need to learn about it, not guess about it.
There's no VB.NET learning resources in your
language? That's hard to believe.
The book you need is about VB.NET, not about
AutoCAD. You can't learn to program AutoCAD
with .NET API before you first learn to use the
VB.NET language.
If you go back into this newsgroup you will see
posts I've made here about 'Using' and Dispose,
and that should tell you what's wrong with your
code.
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com
wrote in message news:5624583@discussion.autodesk.com...
Tony It's your deal to teach others 🙂
but I try to write the code only
Again, I have not have any books on
my native language therefore is problem here
Here is revised version, let me know, please,
what is will be wrong again
Imports System
Imports System.IO
Imports System.Reflection
Imports System.Collections.Generic
Imports System.Runtime.InteropServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.ApplicationServices
Namespace BlockUtils
Public Class AttributeUtils
_
Public Sub ChangeAttributes()
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
Using db As Database = HostApplicationServices.WorkingDatabase()
Using tr As Transaction = db.TransactionManager.StartTransaction()
Try
Dim blockName As String = "Title_Block"
Dim attag As String = "REV_NO"
Dim atvalue As String = "001-002-003-004-005"
Dim bt As BlockTable = DirectCast(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
If bt.Has(blockName) Then
ed.WriteMessage(vbCr & "Block does exist: " & blockName)
Dim btr As BlockTableRecord = DirectCast(tr.GetObject(bt(blockName), OpenMode.ForWrite), BlockTableRecord)
Dim blockRefIds As ObjectIdCollection = btr.GetBlockReferenceIds(False, False)
If blockRefIds.Count > 0 Then
For Each id As ObjectId In blockRefIds
Dim br As BlockReference = DirectCast(tr.GetObject(id, OpenMode.ForWrite), BlockReference)
Dim attcol As AttributeCollection = br.AttributeCollection
For Each attId As ObjectId In attcol
'Dim attref As AttributeReference = tr.GetObject(attId, OpenMode.ForWrite, True)
Dim attref As AttributeReference = DirectCast(tr.GetObject(attId, OpenMode.ForWrite), AttributeReference)
If attag.Equals(attref.Tag) Then
attref.TextString = atvalue
End If
Next
Next
End If
End If
tr.Commit()
Catch ex As Autodesk.AutoCAD.Runtime.Exception
ed.WriteMessage("Exception: " + ex.Message)
Finally
End Try
End Using
End Using
End Sub
End Class
End Namespace