<?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: Getting Block Attributes From Title Block in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/getting-block-attributes-from-title-block/m-p/3164174#M59195</link>
    <description>&lt;P&gt;We have&amp;nbsp;not accessed&amp;nbsp;block attrributes in .NET code yet, so take my comments with a grain of salt.&amp;nbsp; There are several posts here (and the swamp) on accessing block attributes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You define item as an&amp;nbsp;object and then use it as an enumerator through a collection of objectids.&amp;nbsp; For me, code&amp;nbsp;is easier to follow&amp;nbsp;if you create an objectid as an enumerator in the for each statement.&amp;nbsp;&amp;nbsp;"For each myObjid as&amp;nbsp;ObjectID in myBTR.ObjectID" is more efficient&amp;nbsp;and cleaner IMO.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In most cases it is easiest to cast the object to the type you require.&amp;nbsp; After&amp;nbsp;you use "If TypeOf item Is AcadBlockReference Then" create your own block reference from the object by casting, something like&lt;/P&gt;&lt;P&gt;Dim myBREF&amp;nbsp;&lt;FONT color="#0000ff" size="2"&gt;&lt;FONT color="#0000ff" size="2"&gt;As &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;BlockReference&amp;nbsp;= &lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;&lt;FONT color="#0000ff" size="2"&gt;CType&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;(myObjidr.GetObject(OpenMode.ForWrite), BlockReference).&amp;nbsp; Once you have created your own object, intellisense provides all of the available methods and properties of the object.&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 20 Sep 2011 15:13:41 GMT</pubDate>
    <dc:creator>fieldguy</dc:creator>
    <dc:date>2011-09-20T15:13:41Z</dc:date>
    <item>
      <title>Getting Block Attributes From Title Block</title>
      <link>https://forums.autodesk.com/t5/net-forum/getting-block-attributes-from-title-block/m-p/3163542#M59194</link>
      <description>&lt;P&gt;Hello, I'm trying to chnage the text of the sheet number and total&amp;nbsp;sheet number attributes for each layout in my drawing.&amp;nbsp; I have code that adds and deletes the specified pages, now I need to edit the attributes to reflect the correct page and correct total amount of pages.&amp;nbsp; Here is my code, based on my old VBA version.&amp;nbsp; Please forgive my ignorance, but I'm teaching myself as I go.&amp;nbsp; Any commenst within the code describing what it does really helps me learn.&lt;/P&gt;&lt;P&gt;I know there is a problem with the line:&lt;/P&gt;&lt;P&gt;For &lt;FONT color="#0000ff" size="2"&gt;&lt;FONT color="#0000ff" size="2"&gt;Each&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt; item &lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;&lt;FONT color="#0000ff" size="2"&gt;In&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt; myBTR.ObjectId&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;I just threw something in there as I searched the internet for help.&amp;nbsp; I've used a njumber of websites and books, but I would really like to find something that teaches about block tables, block table references, block table IDs so I can get a better understanding of breaking stuff down to get the info I need.&amp;nbsp; Any suggestions are welcome.&lt;/FONT&gt;&lt;/P&gt;&lt;PRE&gt;Public Sub updatePageNumbers()
        Dim myDWG As Autodesk.AutoCAD.ApplicationServices.Document
        Dim myDB As Autodesk.AutoCAD.DatabaseServices.Database
        Dim myTransManForPageNumbers As Autodesk.AutoCAD.DatabaseServices.TransactionManager
        Dim myTransForPageNumbers As Transaction
        Dim myLM As DatabaseServices.LayoutManager
        Dim myLMCount As Integer
        Dim myLayout As DatabaseServices.Layout
        Dim myBT As DatabaseServices.BlockTable
        Dim myBTR As DatabaseServices.BlockTableRecord
        Dim myBTRE As DatabaseServices.SymbolTableEnumerator

        myDWG = DocumentManager.MdiActiveDocument
        'myDB = myDWG.Database
        myTransManForPageNumbers = myDWG.TransactionManager
        myTransForPageNumbers = myTransManForPageNumbers.StartTransaction
        myBT = myDB.BlockTableId.GetObject(DatabaseServices.OpenMode.ForWrite)
        myBTRE = myBT.GetEnumerator
        myLM = DatabaseServices.LayoutManager.Current
        myLMCount = myLM.LayoutCount - 1

        Dim strLayoutTotal As String
        Dim strLayoutCounter As Integer
        Dim strLayoutNumber As String
        Dim strLayoutTabName As String

        While myBTRE.MoveNext
            myBTR = myBTRE.Current.GetObject(DatabaseServices.OpenMode.ForRead)
            If myBTR.IsLayout Then
                If Not myBTR.Name = "*Model_Space" Then
                    myLayout = myBTR.LayoutId.GetObject(DatabaseServices.OpenMode.ForRead)
                    strLayoutNumber = myLayout.TabOrder
                    Dim item As Object
                    For Each item In myBTR.ObjectId
                        'Get Each Block Reference
                        If TypeOf item Is AcadBlockReference Then
                            'Check for Attributes
                            If item.HasAttributes Then
                                Dim atts As Object
                                atts = item.GetAttributes
                                'Verify Range is valid
                                If isValid(atts) Then
                                    Dim AttributeCounter As Integer
                                    For AttributeCounter = LBound(atts) To UBound(atts)
                                        'Check if attribute has the correct Tag, then change it to the last sheet number
                                        If atts(AttributeCounter).TagString = "TOTAL_SHEET_NO" Then
                                            'Set Value
                                            atts(AttributeCounter).TextString = strLayoutTotal
                                        End If
                                        'Update the sheet number to be the current or new sheet number
                                        If atts(AttributeCounter).TagString = "SHEET_NO" Then
                                            'Set Value
                                            atts(AttributeCounter).TextString = strLayoutNumber
                                        End If
                                    Next
                                End If
                            End If
                        End If
                    Next
                End If
            End If
        End While
        myDWG.Editor.Regen()
        myTransForPageNumbers.Commit()
        myTransForPageNumbers.Dispose()
        myTransManForPageNumbers.Dispose()
    End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Thanks,&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2011 05:19:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/getting-block-attributes-from-title-block/m-p/3163542#M59194</guid>
      <dc:creator>mgorecki</dc:creator>
      <dc:date>2011-09-20T05:19:11Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Block Attributes From Title Block</title>
      <link>https://forums.autodesk.com/t5/net-forum/getting-block-attributes-from-title-block/m-p/3164174#M59195</link>
      <description>&lt;P&gt;We have&amp;nbsp;not accessed&amp;nbsp;block attrributes in .NET code yet, so take my comments with a grain of salt.&amp;nbsp; There are several posts here (and the swamp) on accessing block attributes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You define item as an&amp;nbsp;object and then use it as an enumerator through a collection of objectids.&amp;nbsp; For me, code&amp;nbsp;is easier to follow&amp;nbsp;if you create an objectid as an enumerator in the for each statement.&amp;nbsp;&amp;nbsp;"For each myObjid as&amp;nbsp;ObjectID in myBTR.ObjectID" is more efficient&amp;nbsp;and cleaner IMO.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In most cases it is easiest to cast the object to the type you require.&amp;nbsp; After&amp;nbsp;you use "If TypeOf item Is AcadBlockReference Then" create your own block reference from the object by casting, something like&lt;/P&gt;&lt;P&gt;Dim myBREF&amp;nbsp;&lt;FONT color="#0000ff" size="2"&gt;&lt;FONT color="#0000ff" size="2"&gt;As &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;BlockReference&amp;nbsp;= &lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;&lt;FONT color="#0000ff" size="2"&gt;CType&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;(myObjidr.GetObject(OpenMode.ForWrite), BlockReference).&amp;nbsp; Once you have created your own object, intellisense provides all of the available methods and properties of the object.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2011 15:13:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/getting-block-attributes-from-title-block/m-p/3164174#M59195</guid>
      <dc:creator>fieldguy</dc:creator>
      <dc:date>2011-09-20T15:13:41Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Block Attributes From Title Block</title>
      <link>https://forums.autodesk.com/t5/net-forum/getting-block-attributes-from-title-block/m-p/3164186#M59196</link>
      <description>&lt;P&gt;You can compare your code to the attached file...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A BlockTableRecord object is a container, of the object ids of the objects, that are conatined within the record, just like the BlockTable object is a container of ObjectId's&amp;nbsp;to BlockTableRecord objects. They both implement the 'IEnumerable' interface so you can basically iterate thru the&amp;nbsp;collection directly without the need of a 'SymbolTableEnumerator'. Something like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Dim myBT As BlockTable = db.BlockTableId.GetObject(OpenMode.ForRead)
For Each btrid As ObjectId In myBT
	Dim myBTR As BlockTableRecord = btrid.GetObject(OpenMode.ForRead)
	For Each id As ObjectId In myBTR
		Dim obj As DBObject = id.GetObject(OpenMode.ForRead)
	Next
Next&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But it is important to note that BlockTable&amp;nbsp;and BlockTableRecord's are containers of ObjectId's and not the objects themselves.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, you&amp;nbsp;DO NOT&amp;nbsp;want to dispose of the TransactionManager object:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dim myTransManForPageNumbers As Autodesk.AutoCAD.DatabaseServices.TransactionManager&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;myTransManForPageNumbers.Dispose()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Not good, remove the Dispose() line from your code!!&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2011 15:18:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/getting-block-attributes-from-title-block/m-p/3164186#M59196</guid>
      <dc:creator>cadMeUp</dc:creator>
      <dc:date>2011-09-20T15:18:41Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Block Attributes From Title Block</title>
      <link>https://forums.autodesk.com/t5/net-forum/getting-block-attributes-from-title-block/m-p/3164238#M59197</link>
      <description>&lt;P&gt;Also if you know the TitleBlock's 'BlockName'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;you can grab its objectId using BlockTable("Name")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;then use GetBlockReferenceIds to get all the BlockReferences&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you need the Layout name then get it's owner and use LayoutId.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2011 15:41:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/getting-block-attributes-from-title-block/m-p/3164238#M59197</guid>
      <dc:creator>jeff</dc:creator>
      <dc:date>2011-09-20T15:41:13Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Block Attributes From Title Block</title>
      <link>https://forums.autodesk.com/t5/net-forum/getting-block-attributes-from-title-block/m-p/3164826#M59198</link>
      <description>&lt;P&gt;Hi fieldguy,&lt;/P&gt;&lt;P&gt;Thanks for the information.&amp;nbsp; I'll have to study up on enumerators, but yes I understand what you mean about mixing objects and object ID's.&amp;nbsp; I'll have to be more careful about that.&amp;nbsp; I'll also be looking&amp;nbsp;at CTYPE information.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again,&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2011 20:51:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/getting-block-attributes-from-title-block/m-p/3164826#M59198</guid>
      <dc:creator>mgorecki</dc:creator>
      <dc:date>2011-09-20T20:51:42Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Block Attributes From Title Block</title>
      <link>https://forums.autodesk.com/t5/net-forum/getting-block-attributes-from-title-block/m-p/3164860#M59199</link>
      <description>&lt;P&gt;Hi cadMeUp,&lt;/P&gt;&lt;P&gt;Thank you fro the explainations of the BlockTable and BlockTableRecords.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you also for the code.&amp;nbsp; I'm going to be busy this afternoon dissecting it and finding out what all it does.&amp;nbsp; It does seem very straightforward though.&lt;/P&gt;&lt;P&gt;I've also removed the "transManager.dispose" from my code.&amp;nbsp; I must have seen it in an example somewhere.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2011 21:10:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/getting-block-attributes-from-title-block/m-p/3164860#M59199</guid>
      <dc:creator>mgorecki</dc:creator>
      <dc:date>2011-09-20T21:10:03Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Block Attributes From Title Block</title>
      <link>https://forums.autodesk.com/t5/net-forum/getting-block-attributes-from-title-block/m-p/3164866#M59200</link>
      <description>&lt;P&gt;Hi Jeff,&lt;/P&gt;&lt;P&gt;For this case, I will not know the title blocks blockname, as it will change from drawing to drawing, but thanks for the info about grabbing the ID by using the BlockTable name.&amp;nbsp; I believe I have another application that could use something like that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2011 21:14:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/getting-block-attributes-from-title-block/m-p/3164866#M59200</guid>
      <dc:creator>mgorecki</dc:creator>
      <dc:date>2011-09-20T21:14:21Z</dc:date>
    </item>
  </channel>
</rss>

