<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Reading Block Attribute Values in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/reading-block-attribute-values/m-p/1966320#M78025</link>
    <description>this is getting it by the tag name&lt;BR /&gt;
&lt;BR /&gt;
For Each ID2 In blkRef.AttributeCollection&lt;BR /&gt;
                            attrefIndex += 1&lt;BR /&gt;
                            Dim attref As AttributeReference = Trans.GetObject(ID2, OpenMode.ForRead)&lt;BR /&gt;
                            'Dim attdef As AttributeDefinition = GetAttributeDefinition(attrefIndex, blkRef, Trans)&lt;BR /&gt;
                            If Not attref Is Nothing Then&lt;BR /&gt;
                                If attref.Tag.Equals(strTag) Then&lt;BR /&gt;
                                    Return attref.TextString&lt;BR /&gt;
                                End If&lt;BR /&gt;
                            End If&lt;BR /&gt;
                        Next&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
pat</description>
    <pubDate>Fri, 11 May 2007 13:06:45 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2007-05-11T13:06:45Z</dc:date>
    <item>
      <title>Reading Block Attribute Values</title>
      <link>https://forums.autodesk.com/t5/net-forum/reading-block-attribute-values/m-p/1966319#M78024</link>
      <description>Hey Everyone,&lt;BR /&gt;
&lt;BR /&gt;
I'm busy developing a standalone application in VB.NET to read the contents out of a DWG file. So far i was able to open DWG file and search for the titleblock. But I'm having problems accessing the title block attributes and it's values. Can someone tell me how this can be done? &lt;BR /&gt;
&lt;BR /&gt;
 have already took a look at the object model from Autocad and also examples written online on how to get attributes but the way it's done is by inserting a block and then requesting it's attributes. In my case i don't need to insert a block, i would like to retrieve the block attributes and it's values.&lt;BR /&gt;
&lt;BR /&gt;
Thanks in advance</description>
      <pubDate>Fri, 11 May 2007 11:06:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/reading-block-attribute-values/m-p/1966319#M78024</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-05-11T11:06:15Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Block Attribute Values</title>
      <link>https://forums.autodesk.com/t5/net-forum/reading-block-attribute-values/m-p/1966320#M78025</link>
      <description>this is getting it by the tag name&lt;BR /&gt;
&lt;BR /&gt;
For Each ID2 In blkRef.AttributeCollection&lt;BR /&gt;
                            attrefIndex += 1&lt;BR /&gt;
                            Dim attref As AttributeReference = Trans.GetObject(ID2, OpenMode.ForRead)&lt;BR /&gt;
                            'Dim attdef As AttributeDefinition = GetAttributeDefinition(attrefIndex, blkRef, Trans)&lt;BR /&gt;
                            If Not attref Is Nothing Then&lt;BR /&gt;
                                If attref.Tag.Equals(strTag) Then&lt;BR /&gt;
                                    Return attref.TextString&lt;BR /&gt;
                                End If&lt;BR /&gt;
                            End If&lt;BR /&gt;
                        Next&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
pat</description>
      <pubDate>Fri, 11 May 2007 13:06:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/reading-block-attribute-values/m-p/1966320#M78025</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-05-11T13:06:45Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Block Attribute Values</title>
      <link>https://forums.autodesk.com/t5/net-forum/reading-block-attribute-values/m-p/1966321#M78026</link>
      <description>I was reading trough your code and i saw the object Trans.. Here is what got me confuse. In this post http://discussion.autodesk.com/thread.jspa?messageID=5362441. At first i did this but i was getting the same error message. So i thought this was the caused of my problem. My Question is , the code you posted, how can i implement this in my standalone application (.EXE).</description>
      <pubDate>Fri, 11 May 2007 14:21:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/reading-block-attribute-values/m-p/1966321#M78026</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-05-11T14:21:42Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Block Attribute Values</title>
      <link>https://forums.autodesk.com/t5/net-forum/reading-block-attribute-values/m-p/1966322#M78027</link>
      <description>The code I sent you was for in process and you are looking for out of process.&lt;BR /&gt;
&lt;BR /&gt;
Right now I do not have anything available for out of process.&lt;BR /&gt;
&lt;BR /&gt;
pat</description>
      <pubDate>Fri, 11 May 2007 14:27:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/reading-block-attribute-values/m-p/1966322#M78027</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-05-11T14:27:19Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Block Attribute Values</title>
      <link>https://forums.autodesk.com/t5/net-forum/reading-block-attribute-values/m-p/1966323#M78028</link>
      <description>Here is a function I use to get an attribute call SIZE by looping through all the block in a drawing, very slow.&lt;BR /&gt;
&lt;BR /&gt;
Add a reference to AXDBLib&lt;BR /&gt;
&lt;BR /&gt;
Imports Autodesk&lt;BR /&gt;
Imports Autodesk.AutoCAD&lt;BR /&gt;
Imports Autodesk.AutoCAD.Interop&lt;BR /&gt;
Imports Autodesk.AutoCAD.Interop.Common&lt;BR /&gt;
&lt;BR /&gt;
call Get_size("c:\mydrawing.dwg")&lt;BR /&gt;
&lt;BR /&gt;
Function Get_size(ByVal SourceFile As String) As String&lt;BR /&gt;
        'Dim PaperSize As String&lt;BR /&gt;
        'Dim odbxdoc As AxDbDocument&lt;BR /&gt;
        'Dim OutputSize As PageSizeEnum&lt;BR /&gt;
        'Dim AcadApp As AcadApplication&lt;BR /&gt;
        'Dim Paper As String &lt;BR /&gt;
        Dim blkref As AcadBlockReference&lt;BR /&gt;
        Dim AttArray As Object&lt;BR /&gt;
        Dim obj As Object&lt;BR /&gt;
        Dim Msg, Style, Title, Help, Ctxt, response, MyString&lt;BR /&gt;
        Dim i&lt;BR /&gt;
        On Error Resume Next&lt;BR /&gt;
&lt;BR /&gt;
        ' Check for Open AutoCAD&lt;BR /&gt;
        AcadApp = GetObject(, "AutoCAD.Application.16.2")&lt;BR /&gt;
        If Err.Number  0 Then&lt;BR /&gt;
            Err.Clear()&lt;BR /&gt;
            ' if not Open run new AutoCAD &lt;BR /&gt;
            AcadApp = CreateObject("AutoCAD.Application.16.2")&lt;BR /&gt;
        End If&lt;BR /&gt;
        ' AvDbDocument&lt;BR /&gt;
&lt;BR /&gt;
        Dim Block As AcadBlock&lt;BR /&gt;
        Dim strOut As String&lt;BR /&gt;
        PaperSize = ""&lt;BR /&gt;
        odbxdoc = AcadApp.GetInterfaceObject("ObjectDBX.AxDbDocument.16")&lt;BR /&gt;
        odbxdoc.Open(SourceFile)&lt;BR /&gt;
        Console.WriteLine("Blockcount = " &amp;amp; odbxdoc.Blocks.Count)&lt;BR /&gt;
        Dim count = 0&lt;BR /&gt;
        For Each Block In odbxdoc.Blocks&lt;BR /&gt;
            '___________________________________________________________________________&lt;BR /&gt;
            If Not Block.Name.StartsWith("*") Then&lt;BR /&gt;
                'look in all blocks for the attribute "size"&lt;BR /&gt;
                PaperSize = getAttribute_Info("SIZE", Block.Name)&lt;BR /&gt;
                '___________________________________________________________________________&lt;BR /&gt;
&lt;BR /&gt;
                If PaperSize  "" Then&lt;BR /&gt;
                    Get_size = PaperSize&lt;BR /&gt;
                    odbxdoc.close()&lt;BR /&gt;
                    Exit Function&lt;BR /&gt;
                End If&lt;BR /&gt;
            End If&lt;BR /&gt;
        Next Block&lt;BR /&gt;
        odbxdoc.close()&lt;BR /&gt;
        Console.WriteLine(strOut)&lt;BR /&gt;
        AcadApp.Documents.Close()&lt;BR /&gt;
        'CrawlDrawingEx(odbxdoc)&lt;BR /&gt;
&lt;BR /&gt;
    End Function</description>
      <pubDate>Tue, 12 Jun 2007 22:00:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/reading-block-attribute-values/m-p/1966323#M78028</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-06-12T22:00:20Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Block Attribute Values</title>
      <link>https://forums.autodesk.com/t5/net-forum/reading-block-attribute-values/m-p/1966324#M78029</link>
      <description>Will be this help for you?&lt;BR /&gt;
&lt;BR /&gt;
~'J'~&lt;BR /&gt;
&lt;BR /&gt;
Imports System&lt;BR /&gt;
Imports System.IO&lt;BR /&gt;
Imports System.Reflection&lt;BR /&gt;
Imports System.Collections.Generic&lt;BR /&gt;
Imports System.Runtime.InteropServices&lt;BR /&gt;
Imports Autodesk.AutoCAD.EditorInput&lt;BR /&gt;
Imports Autodesk.AutoCAD.Runtime&lt;BR /&gt;
Imports Autodesk.AutoCAD.Geometry&lt;BR /&gt;
Imports Autodesk.AutoCAD.DatabaseServices&lt;BR /&gt;
Imports Autodesk.AutoCAD.ApplicationServices&lt;BR /&gt;
&lt;BR /&gt;
Namespace BlockUtils&lt;BR /&gt;
    Public Class AttributeUtils&lt;BR /&gt;
        &lt;COMMANDMETHOD&gt; _&lt;BR /&gt;
        Public Sub ChangeAttributes()&lt;BR /&gt;
            Dim doc As Document = Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;
            Dim ed As Editor = doc.Editor&lt;BR /&gt;
            Using db As Database = HostApplicationServices.WorkingDatabase()&lt;BR /&gt;
                Using tr As Transaction = db.TransactionManager.StartTransaction()&lt;BR /&gt;
                    Try&lt;BR /&gt;
                        Dim blockName As String = "Title_Block"&lt;BR /&gt;
                        Dim attag As String = "REV_NO"&lt;BR /&gt;
                        Dim atvalue As String = "001-002-003-004-005"&lt;BR /&gt;
                        Dim bt As BlockTable = DirectCast(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)&lt;BR /&gt;
                        If bt.Has(blockName) Then&lt;BR /&gt;
                            ed.WriteMessage(vbCr &amp;amp; "Block does exist: " &amp;amp; blockName)&lt;BR /&gt;
                            Dim btr As BlockTableRecord = DirectCast(tr.GetObject(bt(blockName), OpenMode.ForWrite), BlockTableRecord)&lt;BR /&gt;
                            Dim blockRefIds As ObjectIdCollection = btr.GetBlockReferenceIds(False, False)&lt;BR /&gt;
                            If blockRefIds.Count &amp;gt; 0 Then&lt;BR /&gt;
                                For Each id As ObjectId In blockRefIds&lt;BR /&gt;
                                    Dim br As BlockReference = DirectCast(tr.GetObject(id, OpenMode.ForWrite), BlockReference)&lt;BR /&gt;
                                    Dim attcol As AttributeCollection = br.AttributeCollection&lt;BR /&gt;
                                    For Each attId As ObjectId In attcol&lt;BR /&gt;
                                        'Dim attref As AttributeReference = tr.GetObject(attId, OpenMode.ForWrite, True)&lt;BR /&gt;
                                        Dim attref As AttributeReference = DirectCast(tr.GetObject(attId, OpenMode.ForWrite), AttributeReference)&lt;BR /&gt;
                                        If attag.Equals(attref.Tag) Then&lt;BR /&gt;
                                            attref.TextString = atvalue&lt;BR /&gt;
                                        End If&lt;BR /&gt;
                                    Next&lt;BR /&gt;
                                Next&lt;BR /&gt;
                            End If&lt;BR /&gt;
                        End If&lt;BR /&gt;
                        tr.Commit()&lt;BR /&gt;
                    Catch ex As Autodesk.AutoCAD.Runtime.Exception&lt;BR /&gt;
                        ed.WriteMessage("Exception: " + ex.Message)&lt;BR /&gt;
                    Finally&lt;BR /&gt;
                        tr.Dispose()&lt;BR /&gt;
                    End Try&lt;BR /&gt;
                End Using&lt;BR /&gt;
                db.Dispose()&lt;BR /&gt;
            End Using&lt;BR /&gt;
        End Sub&lt;BR /&gt;
    End Class&lt;BR /&gt;
End Namespace&lt;/COMMANDMETHOD&gt;</description>
      <pubDate>Wed, 13 Jun 2007 11:10:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/reading-block-attribute-values/m-p/1966324#M78029</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-06-13T11:10:06Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Block Attribute Values</title>
      <link>https://forums.autodesk.com/t5/net-forum/reading-block-attribute-values/m-p/1966325#M78030</link>
      <description>Fatty - Your code has a lot of problems.&lt;BR /&gt;
&lt;BR /&gt;
You are disposing the current database (via the&lt;BR /&gt;
Using directive), and you are disposing the&lt;BR /&gt;
transaction even though the Using directive is&lt;BR /&gt;
doing that for you.&lt;BR /&gt;
&lt;BR /&gt;
You might want to consider spending a little&lt;BR /&gt;
time learning to use the language and the&lt;BR /&gt;
API yourself before you try to teach others to&lt;BR /&gt;
use it.&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD 2008&lt;BR /&gt;
Supporting AutoCAD 2000 through 2008&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
&lt;FATTY&gt; wrote in message news:5624566@discussion.autodesk.com...&lt;BR /&gt;
Will be this help for you?&lt;BR /&gt;
&lt;BR /&gt;
~'J'~&lt;BR /&gt;
&lt;BR /&gt;
Imports System&lt;BR /&gt;
Imports System.IO&lt;BR /&gt;
Imports System.Reflection&lt;BR /&gt;
Imports System.Collections.Generic&lt;BR /&gt;
Imports System.Runtime.InteropServices&lt;BR /&gt;
Imports Autodesk.AutoCAD.EditorInput&lt;BR /&gt;
Imports Autodesk.AutoCAD.Runtime&lt;BR /&gt;
Imports Autodesk.AutoCAD.Geometry&lt;BR /&gt;
Imports Autodesk.AutoCAD.DatabaseServices&lt;BR /&gt;
Imports Autodesk.AutoCAD.ApplicationServices&lt;BR /&gt;
&lt;BR /&gt;
Namespace BlockUtils&lt;BR /&gt;
    Public Class AttributeUtils&lt;BR /&gt;
        &lt;COMMANDMETHOD&gt; _&lt;BR /&gt;
        Public Sub ChangeAttributes()&lt;BR /&gt;
            Dim doc As Document = Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;
            Dim ed As Editor = doc.Editor&lt;BR /&gt;
            Using db As Database = HostApplicationServices.WorkingDatabase()&lt;BR /&gt;
                Using tr As Transaction = db.TransactionManager.StartTransaction()&lt;BR /&gt;
                    Try&lt;BR /&gt;
                        Dim blockName As String = "Title_Block"&lt;BR /&gt;
                        Dim attag As String = "REV_NO"&lt;BR /&gt;
                        Dim atvalue As String = "001-002-003-004-005"&lt;BR /&gt;
                        Dim bt As BlockTable = DirectCast(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)&lt;BR /&gt;
                        If bt.Has(blockName) Then&lt;BR /&gt;
                            ed.WriteMessage(vbCr &amp;amp; "Block does exist: " &amp;amp; blockName)&lt;BR /&gt;
                            Dim btr As BlockTableRecord = DirectCast(tr.GetObject(bt(blockName), OpenMode.ForWrite), BlockTableRecord)&lt;BR /&gt;
                            Dim blockRefIds As ObjectIdCollection = btr.GetBlockReferenceIds(False, False)&lt;BR /&gt;
                            If blockRefIds.Count &amp;gt; 0 Then&lt;BR /&gt;
                                For Each id As ObjectId In blockRefIds&lt;BR /&gt;
                                    Dim br As BlockReference = DirectCast(tr.GetObject(id, OpenMode.ForWrite), BlockReference)&lt;BR /&gt;
                                    Dim attcol As AttributeCollection = br.AttributeCollection&lt;BR /&gt;
                                    For Each attId As ObjectId In attcol&lt;BR /&gt;
                                        'Dim attref As AttributeReference = tr.GetObject(attId, OpenMode.ForWrite, True)&lt;BR /&gt;
                                        Dim attref As AttributeReference = DirectCast(tr.GetObject(attId, OpenMode.ForWrite), AttributeReference)&lt;BR /&gt;
                                        If attag.Equals(attref.Tag) Then&lt;BR /&gt;
                                            attref.TextString = atvalue&lt;BR /&gt;
                                        End If&lt;BR /&gt;
                                    Next&lt;BR /&gt;
                                Next&lt;BR /&gt;
                            End If&lt;BR /&gt;
                        End If&lt;BR /&gt;
                        tr.Commit()&lt;BR /&gt;
                    Catch ex As Autodesk.AutoCAD.Runtime.Exception&lt;BR /&gt;
                        ed.WriteMessage("Exception: " + ex.Message)&lt;BR /&gt;
                    Finally&lt;BR /&gt;
                        tr.Dispose()&lt;BR /&gt;
                    End Try&lt;BR /&gt;
                End Using&lt;BR /&gt;
                db.Dispose()&lt;BR /&gt;
            End Using&lt;BR /&gt;
        End Sub&lt;BR /&gt;
    End Class&lt;BR /&gt;
End Namespace&lt;/COMMANDMETHOD&gt;&lt;/FATTY&gt;</description>
      <pubDate>Wed, 13 Jun 2007 11:52:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/reading-block-attribute-values/m-p/1966325#M78030</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-06-13T11:52:43Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Block Attribute Values</title>
      <link>https://forums.autodesk.com/t5/net-forum/reading-block-attribute-values/m-p/1966326#M78031</link>
      <description>Tony It's your deal to teach others &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
but I try to write the code only&lt;BR /&gt;
Again, I have not have any books on&lt;BR /&gt;
my native language therefore is problem here&lt;BR /&gt;
&lt;BR /&gt;
Here is revised version, let me know, please,&lt;BR /&gt;
what is will be wrong again&lt;BR /&gt;
&lt;BR /&gt;
Imports System&lt;BR /&gt;
Imports System.IO&lt;BR /&gt;
Imports System.Reflection&lt;BR /&gt;
Imports System.Collections.Generic&lt;BR /&gt;
Imports System.Runtime.InteropServices&lt;BR /&gt;
Imports Autodesk.AutoCAD.EditorInput&lt;BR /&gt;
Imports Autodesk.AutoCAD.Runtime&lt;BR /&gt;
Imports Autodesk.AutoCAD.Geometry&lt;BR /&gt;
Imports Autodesk.AutoCAD.DatabaseServices&lt;BR /&gt;
Imports Autodesk.AutoCAD.ApplicationServices&lt;BR /&gt;
&lt;BR /&gt;
Namespace BlockUtils&lt;BR /&gt;
Public Class AttributeUtils&lt;BR /&gt;
_&lt;BR /&gt;
Public Sub ChangeAttributes()&lt;BR /&gt;
Dim doc As Document = Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;
Dim ed As Editor = doc.Editor&lt;BR /&gt;
Using db As Database = HostApplicationServices.WorkingDatabase()&lt;BR /&gt;
Using tr As Transaction = db.TransactionManager.StartTransaction()&lt;BR /&gt;
Try&lt;BR /&gt;
Dim blockName As String = "Title_Block"&lt;BR /&gt;
Dim attag As String = "REV_NO"&lt;BR /&gt;
Dim atvalue As String = "001-002-003-004-005"&lt;BR /&gt;
Dim bt As BlockTable = DirectCast(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)&lt;BR /&gt;
If bt.Has(blockName) Then&lt;BR /&gt;
ed.WriteMessage(vbCr &amp;amp; "Block does exist: " &amp;amp; blockName)&lt;BR /&gt;
Dim btr As BlockTableRecord = DirectCast(tr.GetObject(bt(blockName), OpenMode.ForWrite), BlockTableRecord)&lt;BR /&gt;
Dim blockRefIds As ObjectIdCollection = btr.GetBlockReferenceIds(False, False)&lt;BR /&gt;
If blockRefIds.Count &amp;gt; 0 Then&lt;BR /&gt;
For Each id As ObjectId In blockRefIds&lt;BR /&gt;
Dim br As BlockReference = DirectCast(tr.GetObject(id, OpenMode.ForWrite), BlockReference)&lt;BR /&gt;
Dim attcol As AttributeCollection = br.AttributeCollection&lt;BR /&gt;
For Each attId As ObjectId In attcol&lt;BR /&gt;
'Dim attref As AttributeReference = tr.GetObject(attId, OpenMode.ForWrite, True)&lt;BR /&gt;
Dim attref As AttributeReference = DirectCast(tr.GetObject(attId, OpenMode.ForWrite), AttributeReference)&lt;BR /&gt;
If attag.Equals(attref.Tag) Then&lt;BR /&gt;
attref.TextString = atvalue&lt;BR /&gt;
End If&lt;BR /&gt;
Next&lt;BR /&gt;
Next&lt;BR /&gt;
End If&lt;BR /&gt;
End If&lt;BR /&gt;
tr.Commit()&lt;BR /&gt;
Catch ex As Autodesk.AutoCAD.Runtime.Exception&lt;BR /&gt;
ed.WriteMessage("Exception: " + ex.Message)&lt;BR /&gt;
Finally&lt;BR /&gt;
End Try&lt;BR /&gt;
End Using&lt;BR /&gt;
End Using&lt;BR /&gt;
End Sub&lt;BR /&gt;
End Class&lt;BR /&gt;
End Namespace</description>
      <pubDate>Wed, 13 Jun 2007 12:13:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/reading-block-attribute-values/m-p/1966326#M78031</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-06-13T12:13:40Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Block Attribute Values</title>
      <link>https://forums.autodesk.com/t5/net-forum/reading-block-attribute-values/m-p/1966327#M78032</link>
      <description>What is your reason for using Using in the following line:&lt;BR /&gt;
&lt;BR /&gt;
Using db As Database = HostApplicationServices.WorkingDatabase()</description>
      <pubDate>Wed, 13 Jun 2007 22:30:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/reading-block-attribute-values/m-p/1966327#M78032</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-06-13T22:30:07Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Block Attribute Values</title>
      <link>https://forums.autodesk.com/t5/net-forum/reading-block-attribute-values/m-p/1966328#M78033</link>
      <description>Fatty - You don't understand what the 'Using'&lt;BR /&gt;
directive is. If you don't understand it, then&lt;BR /&gt;
you need to learn about it, not guess about it.&lt;BR /&gt;
&lt;BR /&gt;
There's no VB.NET learning resources in your&lt;BR /&gt;
language?  That's hard to believe.&lt;BR /&gt;
&lt;BR /&gt;
The book you need is about VB.NET, not about&lt;BR /&gt;
AutoCAD. You can't learn to program AutoCAD&lt;BR /&gt;
with .NET API before you first learn to use the &lt;BR /&gt;
VB.NET language.&lt;BR /&gt;
&lt;BR /&gt;
If you go back into this newsgroup you will see&lt;BR /&gt;
posts I've made here about 'Using' and Dispose,&lt;BR /&gt;
and that should tell you what's wrong with your &lt;BR /&gt;
code.&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD 2008&lt;BR /&gt;
Supporting AutoCAD 2000 through 2008&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
&lt;FATTY&gt; wrote in message news:5624583@discussion.autodesk.com...&lt;BR /&gt;
Tony It's your deal to teach others &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
but I try to write the code only&lt;BR /&gt;
Again, I have not have any books on&lt;BR /&gt;
my native language therefore is problem here&lt;BR /&gt;
&lt;BR /&gt;
Here is revised version, let me know, please,&lt;BR /&gt;
what is will be wrong again&lt;BR /&gt;
&lt;BR /&gt;
Imports System&lt;BR /&gt;
Imports System.IO&lt;BR /&gt;
Imports System.Reflection&lt;BR /&gt;
Imports System.Collections.Generic&lt;BR /&gt;
Imports System.Runtime.InteropServices&lt;BR /&gt;
Imports Autodesk.AutoCAD.EditorInput&lt;BR /&gt;
Imports Autodesk.AutoCAD.Runtime&lt;BR /&gt;
Imports Autodesk.AutoCAD.Geometry&lt;BR /&gt;
Imports Autodesk.AutoCAD.DatabaseServices&lt;BR /&gt;
Imports Autodesk.AutoCAD.ApplicationServices&lt;BR /&gt;
&lt;BR /&gt;
Namespace BlockUtils&lt;BR /&gt;
Public Class AttributeUtils&lt;BR /&gt;
_&lt;BR /&gt;
Public Sub ChangeAttributes()&lt;BR /&gt;
Dim doc As Document = Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;
Dim ed As Editor = doc.Editor&lt;BR /&gt;
Using db As Database = HostApplicationServices.WorkingDatabase()&lt;BR /&gt;
Using tr As Transaction = db.TransactionManager.StartTransaction()&lt;BR /&gt;
Try&lt;BR /&gt;
Dim blockName As String = "Title_Block"&lt;BR /&gt;
Dim attag As String = "REV_NO"&lt;BR /&gt;
Dim atvalue As String = "001-002-003-004-005"&lt;BR /&gt;
Dim bt As BlockTable = DirectCast(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)&lt;BR /&gt;
If bt.Has(blockName) Then&lt;BR /&gt;
ed.WriteMessage(vbCr &amp;amp; "Block does exist: " &amp;amp; blockName)&lt;BR /&gt;
Dim btr As BlockTableRecord = DirectCast(tr.GetObject(bt(blockName), OpenMode.ForWrite), BlockTableRecord)&lt;BR /&gt;
Dim blockRefIds As ObjectIdCollection = btr.GetBlockReferenceIds(False, False)&lt;BR /&gt;
If blockRefIds.Count &amp;gt; 0 Then&lt;BR /&gt;
For Each id As ObjectId In blockRefIds&lt;BR /&gt;
Dim br As BlockReference = DirectCast(tr.GetObject(id, OpenMode.ForWrite), BlockReference)&lt;BR /&gt;
Dim attcol As AttributeCollection = br.AttributeCollection&lt;BR /&gt;
For Each attId As ObjectId In attcol&lt;BR /&gt;
'Dim attref As AttributeReference = tr.GetObject(attId, OpenMode.ForWrite, True)&lt;BR /&gt;
Dim attref As AttributeReference = DirectCast(tr.GetObject(attId, OpenMode.ForWrite), AttributeReference)&lt;BR /&gt;
If attag.Equals(attref.Tag) Then&lt;BR /&gt;
attref.TextString = atvalue&lt;BR /&gt;
End If&lt;BR /&gt;
Next&lt;BR /&gt;
Next&lt;BR /&gt;
End If&lt;BR /&gt;
End If&lt;BR /&gt;
tr.Commit()&lt;BR /&gt;
Catch ex As Autodesk.AutoCAD.Runtime.Exception&lt;BR /&gt;
ed.WriteMessage("Exception: " + ex.Message)&lt;BR /&gt;
Finally&lt;BR /&gt;
End Try&lt;BR /&gt;
End Using&lt;BR /&gt;
End Using&lt;BR /&gt;
End Sub&lt;BR /&gt;
End Class&lt;BR /&gt;
End Namespace&lt;/FATTY&gt;</description>
      <pubDate>Thu, 14 Jun 2007 01:45:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/reading-block-attribute-values/m-p/1966328#M78033</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-06-14T01:45:18Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Block Attribute Values</title>
      <link>https://forums.autodesk.com/t5/net-forum/reading-block-attribute-values/m-p/1966329#M78034</link>
      <description>Fatty - If you try testing your code before you post it, &lt;BR /&gt;
you will learn from your own mistakes, and others will&lt;BR /&gt;
not have to pay for your mistakes.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD 2008&lt;BR /&gt;
Supporting AutoCAD 2000 through 2008&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
&lt;FATTY&gt; wrote in message news:5624583@discussion.autodesk.com...&lt;BR /&gt;
Tony It's your deal to teach others &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
but I try to write the code only&lt;BR /&gt;
Again, I have not have any books on&lt;BR /&gt;
my native language therefore is problem here&lt;BR /&gt;
&lt;BR /&gt;
Here is revised version, let me know, please,&lt;BR /&gt;
what is will be wrong again&lt;BR /&gt;
&lt;BR /&gt;
Imports System&lt;BR /&gt;
Imports System.IO&lt;BR /&gt;
Imports System.Reflection&lt;BR /&gt;
Imports System.Collections.Generic&lt;BR /&gt;
Imports System.Runtime.InteropServices&lt;BR /&gt;
Imports Autodesk.AutoCAD.EditorInput&lt;BR /&gt;
Imports Autodesk.AutoCAD.Runtime&lt;BR /&gt;
Imports Autodesk.AutoCAD.Geometry&lt;BR /&gt;
Imports Autodesk.AutoCAD.DatabaseServices&lt;BR /&gt;
Imports Autodesk.AutoCAD.ApplicationServices&lt;BR /&gt;
&lt;BR /&gt;
Namespace BlockUtils&lt;BR /&gt;
Public Class AttributeUtils&lt;BR /&gt;
_&lt;BR /&gt;
Public Sub ChangeAttributes()&lt;BR /&gt;
Dim doc As Document = Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;
Dim ed As Editor = doc.Editor&lt;BR /&gt;
Using db As Database = HostApplicationServices.WorkingDatabase()&lt;BR /&gt;
Using tr As Transaction = db.TransactionManager.StartTransaction()&lt;BR /&gt;
Try&lt;BR /&gt;
Dim blockName As String = "Title_Block"&lt;BR /&gt;
Dim attag As String = "REV_NO"&lt;BR /&gt;
Dim atvalue As String = "001-002-003-004-005"&lt;BR /&gt;
Dim bt As BlockTable = DirectCast(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)&lt;BR /&gt;
If bt.Has(blockName) Then&lt;BR /&gt;
ed.WriteMessage(vbCr &amp;amp; "Block does exist: " &amp;amp; blockName)&lt;BR /&gt;
Dim btr As BlockTableRecord = DirectCast(tr.GetObject(bt(blockName), OpenMode.ForWrite), BlockTableRecord)&lt;BR /&gt;
Dim blockRefIds As ObjectIdCollection = btr.GetBlockReferenceIds(False, False)&lt;BR /&gt;
If blockRefIds.Count &amp;gt; 0 Then&lt;BR /&gt;
For Each id As ObjectId In blockRefIds&lt;BR /&gt;
Dim br As BlockReference = DirectCast(tr.GetObject(id, OpenMode.ForWrite), BlockReference)&lt;BR /&gt;
Dim attcol As AttributeCollection = br.AttributeCollection&lt;BR /&gt;
For Each attId As ObjectId In attcol&lt;BR /&gt;
'Dim attref As AttributeReference = tr.GetObject(attId, OpenMode.ForWrite, True)&lt;BR /&gt;
Dim attref As AttributeReference = DirectCast(tr.GetObject(attId, OpenMode.ForWrite), AttributeReference)&lt;BR /&gt;
If attag.Equals(attref.Tag) Then&lt;BR /&gt;
attref.TextString = atvalue&lt;BR /&gt;
End If&lt;BR /&gt;
Next&lt;BR /&gt;
Next&lt;BR /&gt;
End If&lt;BR /&gt;
End If&lt;BR /&gt;
tr.Commit()&lt;BR /&gt;
Catch ex As Autodesk.AutoCAD.Runtime.Exception&lt;BR /&gt;
ed.WriteMessage("Exception: " + ex.Message)&lt;BR /&gt;
Finally&lt;BR /&gt;
End Try&lt;BR /&gt;
End Using&lt;BR /&gt;
End Using&lt;BR /&gt;
End Sub&lt;BR /&gt;
End Class&lt;BR /&gt;
End Namespace&lt;/FATTY&gt;</description>
      <pubDate>Thu, 14 Jun 2007 01:45:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/reading-block-attribute-values/m-p/1966329#M78034</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-06-14T01:45:19Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Block Attribute Values</title>
      <link>https://forums.autodesk.com/t5/net-forum/reading-block-attribute-values/m-p/1966330#M78035</link>
      <description>Hi Nathan, yes you are right, I did &lt;BR /&gt;
it mechanically &lt;BR /&gt;
&lt;BR /&gt;
~'J'~</description>
      <pubDate>Thu, 14 Jun 2007 07:11:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/reading-block-attribute-values/m-p/1966330#M78035</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-06-14T07:11:31Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Block Attribute Values</title>
      <link>https://forums.autodesk.com/t5/net-forum/reading-block-attribute-values/m-p/1966331#M78036</link>
      <description>Tony, thanks a lot again for your explanation,&lt;BR /&gt;
of course, I'll learn further&lt;BR /&gt;
But at the moment my code worked good&lt;BR /&gt;
for me with no any mistakes &lt;BR /&gt;
I tested it extensivelly&lt;BR /&gt;
&lt;BR /&gt;
~'J'~</description>
      <pubDate>Thu, 14 Jun 2007 07:14:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/reading-block-attribute-values/m-p/1966331#M78036</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-06-14T07:14:51Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Block Attribute Values</title>
      <link>https://forums.autodesk.com/t5/net-forum/reading-block-attribute-values/m-p/1966332#M78037</link>
      <description>&lt;NATHAN taylor=""&gt; wrote &lt;BR /&gt;
&lt;BR /&gt;
&amp;gt;&amp;gt; What is your reason for using Using in the following line:&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt;&amp;gt; Using db As Database = HostApplicationServices.WorkingDatabase()&lt;BR /&gt;
&lt;BR /&gt;
He's not supposed to do it, but the runtime knows&lt;BR /&gt;
that, so it catches the mistake and there is no harm&lt;BR /&gt;
done, but it doesn't change the fact that it shouldn't &lt;BR /&gt;
be done to begin with, and there are other managed&lt;BR /&gt;
objects that are not as forgiving.&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD 2008&lt;BR /&gt;
Supporting AutoCAD 2000 through 2008&lt;BR /&gt;
http://www.acadxtabs.com&lt;/NATHAN&gt;</description>
      <pubDate>Thu, 14 Jun 2007 08:24:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/reading-block-attribute-values/m-p/1966332#M78037</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-06-14T08:24:59Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Block Attribute Values</title>
      <link>https://forums.autodesk.com/t5/net-forum/reading-block-attribute-values/m-p/1966333#M78038</link>
      <description>Check this out.&lt;BR /&gt;
&lt;BR /&gt;
http://usa.autodesk.com/adsk/servlet/index?siteID=123112&amp;amp;id=1911627&lt;BR /&gt;
&lt;BR /&gt;
There is a sample application in most of the packages to read block attributes.  Just pick your preferred programming style.  I would post an example I customized, but it would be way too long.  YOu could take one of the examples and simply change the property or attribute names to what you need.  &lt;BR /&gt;
&lt;BR /&gt;
(PSST.  Don't forget to delete the stuff you don't want.)..........=8^D&lt;BR /&gt;
&lt;BR /&gt;
Rudedog&lt;BR /&gt;
"Fooling computers since 1971."</description>
      <pubDate>Thu, 21 Jun 2007 17:03:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/reading-block-attribute-values/m-p/1966333#M78038</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-06-21T17:03:43Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Block Attribute Values</title>
      <link>https://forums.autodesk.com/t5/net-forum/reading-block-attribute-values/m-p/1966334#M78039</link>
      <description>Why not insert it, read it, then delete it when you are done.</description>
      <pubDate>Wed, 27 Jun 2007 16:56:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/reading-block-attribute-values/m-p/1966334#M78039</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-06-27T16:56:56Z</dc:date>
    </item>
  </channel>
</rss>

