<?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: How Can I Get All Block Attributes and change it in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/how-can-i-get-all-block-attributes-and-change-it/m-p/3932127#M49453</link>
    <description>&lt;P&gt;Your request is open to many possibilities. You could ask the users to select a particular BlockReference or perhaps you already know which one&amp;nbsp;you need to change and so on.&amp;nbsp; Here I am attaching a sample to change the AttributeReference TextString of all the BlockReferences on the drawing which have attributes.&amp;nbsp; Hope it helps or gives you some ideas.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Public Sub GetAllAttributes()
            Dim Ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
            Dim Doc As Autodesk.AutoCAD.ApplicationServices.Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
            Dim DocLock As Autodesk.AutoCAD.ApplicationServices.DocumentLock
            Dim Db As Database = HostApplicationServices.WorkingDatabase
            Dim Ids As New ObjectIdCollection
            Dim BlkTblRec As BlockTableRecord
            Dim AttRef As AttributeReference
            Dim BlkRef As BlockReference
            Dim BlkTbl As BlockTable
            Dim AttRefId As ObjectId
            Dim RefId As ObjectId
            Dim Id As ObjectId
            Dim Mtxt As MText

            DocLock = Doc.LockDocument

            Try

                Using Trans As Transaction = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.TransactionManager.StartTransaction

                    BlkTbl = CType(Trans.GetObject(Db.BlockTableId, OpenMode.ForRead), BlockTable)

                    For Each Id In BlkTbl

                        BlkTblRec = CType(Trans.GetObject(Id, OpenMode.ForRead), BlockTableRecord)

                        If BlkTblRec.HasAttributeDefinitions = True Then

                            Ids = BlkTblRec.GetBlockReferenceIds(False, False)

                            If Ids.Count &amp;gt; 0 Then

                                For Each RefId In Ids

                                    BlkRef = CType(Trans.GetObject(RefId, OpenMode.ForWrite), BlockReference)

                                    For Each AttRefId In BlkRef.AttributeCollection

                                        AttRef = CType(Trans.GetObject(AttRefId, OpenMode.ForWrite), AttributeReference)

                                        If AttRef.IsMTextAttribute Then

                                            Mtxt = AttRef.MTextAttribute

                                            Mtxt.Contents = "New TextString"

                                            AttRef.MTextAttribute = Mtxt

                                            AttRef.UpdateMTextAttribute()

                                        Else

                                            AttRef.TextString = "New TextString"

                                        End If


                                    Next

                                Next

                            End If

                        End If

                    Next

                    Trans.Commit()

                End Using

            Catch ex As Exception

                MessageBox.Show(ex.Message, "Changing Attributes", MessageBoxButtons.OK, MessageBoxIcon.Error)

            Finally

                DocLock.Dispose()

            End Try

        End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 22 May 2013 12:46:13 GMT</pubDate>
    <dc:creator>HJohn1</dc:creator>
    <dc:date>2013-05-22T12:46:13Z</dc:date>
    <item>
      <title>How Can I Get All Block Attributes and change it</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-can-i-get-all-block-attributes-and-change-it/m-p/3931980#M49452</link>
      <description>&lt;P&gt;hi every one&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How Can I Get All Block Attributes and change it&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2013 10:46:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-can-i-get-all-block-attributes-and-change-it/m-p/3931980#M49452</guid>
      <dc:creator>Amremad</dc:creator>
      <dc:date>2013-05-22T10:46:22Z</dc:date>
    </item>
    <item>
      <title>Re: How Can I Get All Block Attributes and change it</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-can-i-get-all-block-attributes-and-change-it/m-p/3932127#M49453</link>
      <description>&lt;P&gt;Your request is open to many possibilities. You could ask the users to select a particular BlockReference or perhaps you already know which one&amp;nbsp;you need to change and so on.&amp;nbsp; Here I am attaching a sample to change the AttributeReference TextString of all the BlockReferences on the drawing which have attributes.&amp;nbsp; Hope it helps or gives you some ideas.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Public Sub GetAllAttributes()
            Dim Ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
            Dim Doc As Autodesk.AutoCAD.ApplicationServices.Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
            Dim DocLock As Autodesk.AutoCAD.ApplicationServices.DocumentLock
            Dim Db As Database = HostApplicationServices.WorkingDatabase
            Dim Ids As New ObjectIdCollection
            Dim BlkTblRec As BlockTableRecord
            Dim AttRef As AttributeReference
            Dim BlkRef As BlockReference
            Dim BlkTbl As BlockTable
            Dim AttRefId As ObjectId
            Dim RefId As ObjectId
            Dim Id As ObjectId
            Dim Mtxt As MText

            DocLock = Doc.LockDocument

            Try

                Using Trans As Transaction = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.TransactionManager.StartTransaction

                    BlkTbl = CType(Trans.GetObject(Db.BlockTableId, OpenMode.ForRead), BlockTable)

                    For Each Id In BlkTbl

                        BlkTblRec = CType(Trans.GetObject(Id, OpenMode.ForRead), BlockTableRecord)

                        If BlkTblRec.HasAttributeDefinitions = True Then

                            Ids = BlkTblRec.GetBlockReferenceIds(False, False)

                            If Ids.Count &amp;gt; 0 Then

                                For Each RefId In Ids

                                    BlkRef = CType(Trans.GetObject(RefId, OpenMode.ForWrite), BlockReference)

                                    For Each AttRefId In BlkRef.AttributeCollection

                                        AttRef = CType(Trans.GetObject(AttRefId, OpenMode.ForWrite), AttributeReference)

                                        If AttRef.IsMTextAttribute Then

                                            Mtxt = AttRef.MTextAttribute

                                            Mtxt.Contents = "New TextString"

                                            AttRef.MTextAttribute = Mtxt

                                            AttRef.UpdateMTextAttribute()

                                        Else

                                            AttRef.TextString = "New TextString"

                                        End If


                                    Next

                                Next

                            End If

                        End If

                    Next

                    Trans.Commit()

                End Using

            Catch ex As Exception

                MessageBox.Show(ex.Message, "Changing Attributes", MessageBoxButtons.OK, MessageBoxIcon.Error)

            Finally

                DocLock.Dispose()

            End Try

        End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2013 12:46:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-can-i-get-all-block-attributes-and-change-it/m-p/3932127#M49453</guid>
      <dc:creator>HJohn1</dc:creator>
      <dc:date>2013-05-22T12:46:13Z</dc:date>
    </item>
    <item>
      <title>Re: How Can I Get All Block Attributes and change it</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-can-i-get-all-block-attributes-and-change-it/m-p/3932905#M49454</link>
      <description>&lt;P&gt;You should probably take some time to read the docs for the APIs you're attempting to use in that code, to understand them better.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;GetBlockReferenceIds( false, false ) will return the ids of any block that is directly or indirectly inserted into the block whose BlockTableRecord you invoke the method on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since your code is iterating over the entire contents of the BlockTable, the 'false' argument to GetBlockReferenceIds() is redundant.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2013 23:21:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-can-i-get-all-block-attributes-and-change-it/m-p/3932905#M49454</guid>
      <dc:creator>DiningPhilosopher</dc:creator>
      <dc:date>2013-05-22T23:21:29Z</dc:date>
    </item>
    <item>
      <title>Re: How Can I Get All Block Attributes and change it</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-can-i-get-all-block-attributes-and-change-it/m-p/3933879#M49455</link>
      <description>&lt;P&gt;DP you&amp;nbsp;advice has been well&amp;nbsp;taken, thank you for pointing it out and sharing your knowledge.&amp;nbsp; I really wish I could be able to understand everything I read on the docs.&amp;nbsp; I guess that perhaps&amp;nbsp;the documentation&amp;nbsp;has been wrintten by people who know for people who know, not for the layperson like me.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 May 2013 14:02:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-can-i-get-all-block-attributes-and-change-it/m-p/3933879#M49455</guid>
      <dc:creator>HJohn1</dc:creator>
      <dc:date>2013-05-23T14:02:52Z</dc:date>
    </item>
    <item>
      <title>Re: How Can I Get All Block Attributes and change it</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-can-i-get-all-block-attributes-and-change-it/m-p/3944500#M49456</link>
      <description>&lt;P&gt;sorry for late&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;i was very sick , but now iam good , thanks god&lt;BR /&gt;thank you very much MR.&amp;nbsp;HJohn1 for helping me&lt;/P&gt;</description>
      <pubDate>Sun, 02 Jun 2013 09:13:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-can-i-get-all-block-attributes-and-change-it/m-p/3944500#M49456</guid>
      <dc:creator>Amremad</dc:creator>
      <dc:date>2013-06-02T09:13:31Z</dc:date>
    </item>
    <item>
      <title>Re: How Can I Get All Block Attributes and change it</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-can-i-get-all-block-attributes-and-change-it/m-p/3944501#M49457</link>
      <description>&lt;P&gt;thanks MR. DiningPhilosopher for you advice&lt;/P&gt;&lt;P&gt;i promise you i will do than&lt;/P&gt;</description>
      <pubDate>Sun, 02 Jun 2013 09:14:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-can-i-get-all-block-attributes-and-change-it/m-p/3944501#M49457</guid>
      <dc:creator>Amremad</dc:creator>
      <dc:date>2013-06-02T09:14:20Z</dc:date>
    </item>
    <item>
      <title>Re: How Can I Get All Block Attributes and change it</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-can-i-get-all-block-attributes-and-change-it/m-p/3946202#M49458</link>
      <description>&lt;P&gt;I need this type of thing too. &amp;nbsp;Thanks for posting. &amp;nbsp;I am getting some errors when I just plugged it into my code. &amp;nbsp;Is there an Autodesk dll I forgot to include causing the error past Autodesk.AutoCAD.ApplicationServices.?&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jun 2013 12:51:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-can-i-get-all-block-attributes-and-change-it/m-p/3946202#M49458</guid>
      <dc:creator>jaboone</dc:creator>
      <dc:date>2013-06-04T12:51:02Z</dc:date>
    </item>
    <item>
      <title>Re: How Can I Get All Block Attributes and change it</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-can-i-get-all-block-attributes-and-change-it/m-p/3947103#M49459</link>
      <description>&lt;P&gt;Mr.&amp;nbsp; Jaboone&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;can you send me your source code to see what's a problem !!!&lt;/P&gt;&lt;P&gt;and tell me what's the version of cad&amp;nbsp; and framework ?&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jun 2013 08:39:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-can-i-get-all-block-attributes-and-change-it/m-p/3947103#M49459</guid>
      <dc:creator>Amremad</dc:creator>
      <dc:date>2013-06-05T08:39:30Z</dc:date>
    </item>
    <item>
      <title>Re: How Can I Get All Block Attributes and change it</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-can-i-get-all-block-attributes-and-change-it/m-p/3947416#M49460</link>
      <description>&lt;P&gt;It seems that when I put the code in a tutorial there were no errors, but then putting it in another, it had fewer errors. &amp;nbsp;Let me investigate why and I will get back.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jun 2013 14:00:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-can-i-get-all-block-attributes-and-change-it/m-p/3947416#M49460</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-06-05T14:00:56Z</dc:date>
    </item>
    <item>
      <title>Re: How Can I Get All Block Attributes and change it</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-can-i-get-all-block-attributes-and-change-it/m-p/3947434#M49461</link>
      <description>&lt;P&gt;&amp;nbsp;i think you , you must choose the correct framework version&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jun 2013 14:13:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-can-i-get-all-block-attributes-and-change-it/m-p/3947434#M49461</guid>
      <dc:creator>Amremad</dc:creator>
      <dc:date>2013-06-05T14:13:25Z</dc:date>
    </item>
  </channel>
</rss>

