<?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: Change Block Attribute in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/change-block-attribute/m-p/2997352#M61113</link>
    <description>&lt;P&gt;I really hate the way this forum mangles code pasted directly from Visual studio&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyway, I couldn't find the blog post I was looking for, so I just tweeked the code you posted.&amp;nbsp; Note, I changed the variable name for the ModelSpace BlockTableRecord, just to reduce confusion, and I inserted the necessary block of code for adding the attributes.&amp;nbsp; As you read it, you'll see there is not really anything magical going on, it's just that with other forms of autocad automation, this was never necessary before.&amp;nbsp; Changes Highlighted.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Public Sub AddBlock(ByVal blockname)&lt;BR /&gt;&amp;nbsp;Dim db As Database = HostApplicationServices.WorkingDatabase()&lt;BR /&gt;&amp;nbsp;Using tr As Transaction = db.TransactionManager.StartTransaction()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;' Test if block exists in the block table&lt;BR /&gt;&amp;nbsp;&amp;nbsp;Dim bt As BlockTable = DirectCast(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;Dim id As ObjectId = bt(blockname)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;Dim btr As BlockTableRecord = tr.GetObject(id, OpenMode.ForRead, False, True)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;Dim br As New BlockReference(New Point3d(0, 0, 0), id)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;Dim &lt;FONT color="#ff0000"&gt;MS&lt;/FONT&gt; As BlockTableRecord = DirectCast(tr.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;' Add the block reference to Model space&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;FONT color="#ff0000"&gt;MS&lt;/FONT&gt;.AppendEntity(br)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;tr.AddNewlyCreatedDBObject(br, True)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;FONT color="#0000ff"&gt;If btr.HasAttributeDefinitions Then&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Dim AtDef As AttributeDefinition, AttRef As AttributeReference&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;For Each SubEntId As ObjectId In btr&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;If SubEntId.ObjectClass.Name = "AcDbAttributeDefinition" Then&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;AtDef = tr.GetObject(SubEntId, OpenMode.ForRead, False, True)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;AttRef = New AttributeReference&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;AttRef.SetAttributeFromBlock(AtDef, br.BlockTransform)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;br.AttributeCollection.AppendAttribute(AttRef)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;tr.AddNewlyCreatedDBObject(AttRef, True)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;AtDef.Dispose()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;AttRef.Dispose()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;End If&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Next&lt;BR /&gt;&amp;nbsp;&amp;nbsp;End If&lt;BR /&gt;&lt;/FONT&gt;&amp;nbsp;&amp;nbsp;BlockRefID = br.ObjectId&lt;BR /&gt;&amp;nbsp;&amp;nbsp;' Commit the transaction&lt;BR /&gt;&amp;nbsp;&amp;nbsp;tr.Commit()&lt;BR /&gt;&amp;nbsp;End Using&lt;BR /&gt;End Sub&lt;/P&gt;</description>
    <pubDate>Wed, 20 Apr 2011 20:05:49 GMT</pubDate>
    <dc:creator>chiefbraincloud</dc:creator>
    <dc:date>2011-04-20T20:05:49Z</dc:date>
    <item>
      <title>Change Block Attribute</title>
      <link>https://forums.autodesk.com/t5/net-forum/change-block-attribute/m-p/2996912#M61107</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I’m new to this and I do need to understand better how to access the BTR, read and write BRef, attDef, AttRef etc. But this has me stumped. There are a few different examples &amp;nbsp;but can’t find anything that works and don't know why.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have inserted a block in modelspace, I have the BlockRefID and now want to change its attribute values.&lt;/P&gt;&lt;P&gt;This finds the attributes tags but doesn’t write the sValue. Can anyone spot why it isn’t writing the value to the block or suggest something better&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Public Sub ChangeAttributeValue(ByVal BlockRefID As ObjectId, ByVal sTagName As String, ByVal sValue As String)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim doc As Document = Application.DocumentManager.MdiActiveDocument&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim db As Database = doc.Database&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim tr As Transaction = db.TransactionManager.StartTransaction()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim br As BlockReference = DirectCast(tr.GetObject(BlockRefID, OpenMode.ForWrite), BlockReference)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim RefBTR As BlockTableRecord = tr.GetObject(br.BlockTableRecord, OpenMode.ForRead)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim attEnt As Entity&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Try&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; For Each attID As ObjectId In RefBTR&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; attEnt = tr.GetObject(attID, OpenMode.ForRead)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If TypeOf attEnt Is AttributeDefinition Then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim attDef As AttributeDefinition = attEnt&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim attRef As AttributeReference = New AttributeReference()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; attRef.SetAttributeFromBlock(attDef, br.BlockTransform)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If attRef.Tag = sTagName Then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;attRef.TextString = sValue&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Exit Sub&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Next&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Catch ex As Autodesk.AutoCAD.Runtime.Exception&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tr.Abort()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Finally&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tr.Commit()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;End Try&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Sub&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope someone can help.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Apr 2011 16:02:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/change-block-attribute/m-p/2996912#M61107</guid>
      <dc:creator>SRSDS</dc:creator>
      <dc:date>2011-04-20T16:02:53Z</dc:date>
    </item>
    <item>
      <title>Re: Change Block Attribute</title>
      <link>https://forums.autodesk.com/t5/net-forum/change-block-attribute/m-p/2997104#M61108</link>
      <description>&lt;P&gt;The code you have there is not doing what you think it's doing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What you have done is opened the block definition, created a New Attribute Reference, set it's value, then threw it in the trash.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What you need to do is skip the BlockTableRecord (definition).&amp;nbsp; Open the BlockReference as you have done, then change your For Each to:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For Each AttRefId in br.AttributeCollection&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; dim AttRef as AttributeReference = tr.GetObject(AttRefId, OpenMode.ForWrite, false, true)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; If AttRef.Tag = sTagName then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; End If&lt;/P&gt;&lt;P&gt;Next&lt;/P&gt;</description>
      <pubDate>Wed, 20 Apr 2011 17:38:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/change-block-attribute/m-p/2997104#M61108</guid>
      <dc:creator>chiefbraincloud</dc:creator>
      <dc:date>2011-04-20T17:38:34Z</dc:date>
    </item>
    <item>
      <title>Re: Change Block Attribute</title>
      <link>https://forums.autodesk.com/t5/net-forum/change-block-attribute/m-p/2997150#M61109</link>
      <description>&lt;P&gt;Thanks Chief,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thats one of the few things I've tried. A similar procedure works fine with the dynamic block properties.&lt;/P&gt;&lt;P&gt;Strange thing is that the blockref (br) does show the 27 items in the DynamicBlockReferencePropertyCollection (which I can access and change) but 0 items in the AttributeColection when it has 3 Attributes.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Public Sub ChangeAttributeValue(ByVal BlockRefID As ObjectId, ByVal sTagName As String, ByVal sValue As String)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dim doc As Document = Application.DocumentManager.MdiActiveDocument&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Using db As Database = HostApplicationServices.WorkingDatabase()&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Using tr As Transaction = db.TransactionManager.StartTransaction()&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Try&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dim br As BlockReference = DirectCast(tr.GetObject(BlockRefID, OpenMode.ForWrite), BlockReference)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dim attcol As AttributeCollection = br.AttributeCollection&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;For Each attId As ObjectId In attcol&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dim attref As AttributeReference = DirectCast(tr.GetObject(attId, OpenMode.ForWrite), AttributeReference)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;If attref.Tag = sTagName Then&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;attref.TextString = sValue&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;End If&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Next&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;tr.Commit()&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Catch ex As Autodesk.AutoCAD.Runtime.Exception&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ed.WriteMessage("Exception: " + ex.Message)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Finally&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;tr.Dispose()&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;End Try&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;End Using&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;db.Dispose()&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;End Using&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;End Sub&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Apr 2011 18:00:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/change-block-attribute/m-p/2997150#M61109</guid>
      <dc:creator>SRSDS</dc:creator>
      <dc:date>2011-04-20T18:00:16Z</dc:date>
    </item>
    <item>
      <title>Re: Change Block Attribute</title>
      <link>https://forums.autodesk.com/t5/net-forum/change-block-attribute/m-p/2997176#M61110</link>
      <description>&lt;P&gt;I should have copied the code changes you suggested but the result is the same. 0 AttRefs in the collection.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; Public Sub ChangeAttributeValue(ByVal BlockRefID As ObjectId, ByVal sTagName As String, ByVal sValue As String)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dim doc As Document = Application.DocumentManager.MdiActiveDocument&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dim db As Database = doc.Database&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dim tr As Transaction = db.TransactionManager.StartTransaction()&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dim br As BlockReference = DirectCast(tr.GetObject(BlockRefID, OpenMode.ForWrite), BlockReference)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Try&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;For Each AttRefId In br.AttributeCollection&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dim AttRef As AttributeReference = tr.GetObject(AttRefId, OpenMode.ForWrite, False, True)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;If AttRef.Tag = sTagName Then&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;AttRef.TextString = sValue&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Exit Sub&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;End If&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Next&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Catch ex As Autodesk.AutoCAD.Runtime.Exception&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;tr.Abort()&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Finally&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;tr.Commit()&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;End Try&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;End Sub&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Apr 2011 18:11:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/change-block-attribute/m-p/2997176#M61110</guid>
      <dc:creator>SRSDS</dc:creator>
      <dc:date>2011-04-20T18:11:47Z</dc:date>
    </item>
    <item>
      <title>Re: Change Block Attribute</title>
      <link>https://forums.autodesk.com/t5/net-forum/change-block-attribute/m-p/2997264#M61111</link>
      <description>&lt;P&gt;I think the problem is my Addblock routine. It adds a block reference but without any attributes. Why would it do that?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Public Sub AddBlock(ByVal blockname)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dim db As Database = HostApplicationServices.WorkingDatabase()&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Using tr As Transaction = db.TransactionManager.StartTransaction()&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;' Test if block exists in the block table&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dim bt As BlockTable = DirectCast(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dim id As ObjectId = bt(blockname)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dim br As New BlockReference(New Point3d(0, 0, 0), id)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dim btr As BlockTableRecord = DirectCast(tr.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;' Add the block reference to Model space&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;btr.AppendEntity(br)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;tr.AddNewlyCreatedDBObject(br, True)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;BlockRefID = br.ObjectId&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;' Commit the transaction&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;tr.Commit()&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;End Using&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;End Sub&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Apr 2011 19:12:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/change-block-attribute/m-p/2997264#M61111</guid>
      <dc:creator>SRSDS</dc:creator>
      <dc:date>2011-04-20T19:12:37Z</dc:date>
    </item>
    <item>
      <title>Re: Change Block Attribute</title>
      <link>https://forums.autodesk.com/t5/net-forum/change-block-attribute/m-p/2997306#M61112</link>
      <description>&lt;P&gt;Basically this tells me you did not properly add the Attribute References to the BlockReference when it was inserted,&amp;nbsp;a process which was not necessary if coding in VBA or .NET COM automation, or LSP.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The For Each loop you had in your original post is just short of what is needed to accomplish that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I see that while I have been typing and searching Through The Interface for an example you have arrived at the same conclusion.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Give me a minute, I'll find an example.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Apr 2011 19:38:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/change-block-attribute/m-p/2997306#M61112</guid>
      <dc:creator>chiefbraincloud</dc:creator>
      <dc:date>2011-04-20T19:38:32Z</dc:date>
    </item>
    <item>
      <title>Re: Change Block Attribute</title>
      <link>https://forums.autodesk.com/t5/net-forum/change-block-attribute/m-p/2997352#M61113</link>
      <description>&lt;P&gt;I really hate the way this forum mangles code pasted directly from Visual studio&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyway, I couldn't find the blog post I was looking for, so I just tweeked the code you posted.&amp;nbsp; Note, I changed the variable name for the ModelSpace BlockTableRecord, just to reduce confusion, and I inserted the necessary block of code for adding the attributes.&amp;nbsp; As you read it, you'll see there is not really anything magical going on, it's just that with other forms of autocad automation, this was never necessary before.&amp;nbsp; Changes Highlighted.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Public Sub AddBlock(ByVal blockname)&lt;BR /&gt;&amp;nbsp;Dim db As Database = HostApplicationServices.WorkingDatabase()&lt;BR /&gt;&amp;nbsp;Using tr As Transaction = db.TransactionManager.StartTransaction()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;' Test if block exists in the block table&lt;BR /&gt;&amp;nbsp;&amp;nbsp;Dim bt As BlockTable = DirectCast(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;Dim id As ObjectId = bt(blockname)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;Dim btr As BlockTableRecord = tr.GetObject(id, OpenMode.ForRead, False, True)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;Dim br As New BlockReference(New Point3d(0, 0, 0), id)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;Dim &lt;FONT color="#ff0000"&gt;MS&lt;/FONT&gt; As BlockTableRecord = DirectCast(tr.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;' Add the block reference to Model space&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;FONT color="#ff0000"&gt;MS&lt;/FONT&gt;.AppendEntity(br)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;tr.AddNewlyCreatedDBObject(br, True)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;FONT color="#0000ff"&gt;If btr.HasAttributeDefinitions Then&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Dim AtDef As AttributeDefinition, AttRef As AttributeReference&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;For Each SubEntId As ObjectId In btr&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;If SubEntId.ObjectClass.Name = "AcDbAttributeDefinition" Then&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;AtDef = tr.GetObject(SubEntId, OpenMode.ForRead, False, True)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;AttRef = New AttributeReference&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;AttRef.SetAttributeFromBlock(AtDef, br.BlockTransform)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;br.AttributeCollection.AppendAttribute(AttRef)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;tr.AddNewlyCreatedDBObject(AttRef, True)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;AtDef.Dispose()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;AttRef.Dispose()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;End If&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Next&lt;BR /&gt;&amp;nbsp;&amp;nbsp;End If&lt;BR /&gt;&lt;/FONT&gt;&amp;nbsp;&amp;nbsp;BlockRefID = br.ObjectId&lt;BR /&gt;&amp;nbsp;&amp;nbsp;' Commit the transaction&lt;BR /&gt;&amp;nbsp;&amp;nbsp;tr.Commit()&lt;BR /&gt;&amp;nbsp;End Using&lt;BR /&gt;End Sub&lt;/P&gt;</description>
      <pubDate>Wed, 20 Apr 2011 20:05:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/change-block-attribute/m-p/2997352#M61113</guid>
      <dc:creator>chiefbraincloud</dc:creator>
      <dc:date>2011-04-20T20:05:49Z</dc:date>
    </item>
    <item>
      <title>Re: Change Block Attribute</title>
      <link>https://forums.autodesk.com/t5/net-forum/change-block-attribute/m-p/2997930#M61114</link>
      <description>&lt;P&gt;Thanks so much!!&lt;/P&gt;&lt;P&gt;Been stumbling around for quite a while. At least I have a slightly better understanding now.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2011 06:14:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/change-block-attribute/m-p/2997930#M61114</guid>
      <dc:creator>SRSDS</dc:creator>
      <dc:date>2011-04-21T06:14:33Z</dc:date>
    </item>
  </channel>
</rss>

