Your Welcome.
I noticed that Autocad will not Release the file once it has been modified with ObjectDBX
I had to close Autocad.
This will release the file when it is finished
{code}
Public Sub runCode()
Dim strFilename = ("c:\test.dwg")
If Not isFileInUse(strFileName) Then
SetAttribute (strFileName)
End If
End Sub
Public Function SetAttribute(ByVal strFileName As String) As Boolean
Dim BT As BlockTable
Dim Btr As BlockTableRecord
Dim ent As entity
Dim bDwg As New Database(False, True)
Dim rtnValue As Boolean
Dim strAttTag As String = "SHT_TTL_L2"
Dim strAttText As String = "SOMETEXT"
Dim strBlockName As String = "Ford_A1"
bDwg.ReadDwgFile(strFileName, System.IO.FileShare.ReadWrite, True, "")
Dim db As Database = bDwg
Dim tr As Autodesk.AutoCAD.DatabaseServices.TransactionManager = bDwg.TransactionManager
Using tr.StartTransaction()
' get Block table
BT = CType(db.BlockTableId.GetObject(DatabaseServices.OpenMode.ForWrite), BlockTable)
' get Modelspace
Btr = CType(BT(BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite), BlockTableRecord)
' get Iteration for modelspace
Dim iter As BlockTableRecordEnumerator = Btr.GetEnumerator
While iter.MoveNext
' get each object in the modelspace
ent = iter.Current.GetObject(OpenMode.ForRead)
If TypeOf ent Is BlockReference Then
Dim Block As BlockReference = ent
' Check if the block name matches
If Block.name = strBlockName Then
For Each Id As ObjectId In Block.AttributeCollection
' get Attribute
Dim AttEnt As Entity = Id.GetObject(Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite)
' Check each Attribute for matching name
If TypeOf AttEnt Is AttributeReference Then
Dim attRef As AttributeReference = AttEnt
If attRef.Tag = strAttTag Then
' Change text String
attRef.TextString = strAttText
' Save Changes
bDwg.SaveAs(strFileName, DwgVersion.Current)
' Set Return value
rtnValue = True
' get out of the loop
Exit While
End If
End If
Next
End If
End If
End While
End Using
' Close File
bDwg.CloseInput (True)
' Release file inuse
bDwg.Dispose()
' Clear Reference
bDwg = Nothing
' Return Value
Return rtnValue
End Function
{code}
---------------------------

(defun botsbuildbots() (botsbuildbots))