Active Contributor
31 Posts
0 Kudos
Registered: ‎05-09-2007
Post 1 of 3

Problem with editing attributes in a block

248 Views, 2 Replies
03-15-2012 02:02 PM

I'm trying to edit the attributes in a titleblock using VB.net. The block name is "Titleblock". It is already inserted into a drawing. My program does not need to insert it. It only needs to find the reference, for all layouts, and update a couple attributes for the titleblock on everylayout. I know some of the basics, but get confused with blocktables, and blocktablerecords.

Here is a piece of code I was experimenting with. With this code, I'm trying to get to the attributes, and read an attribute value for a drawing number.  It fails when I try to assign a value to the variable blkreftitle. Any help and suggestions would be greatly appreciated.



doc AsDocument = Application.DocumentManager.MdiActiveDocument


Using docLoc AsDocumentLock = doc.LockDocument


Dim db AsDatabase = HostApplicationServices.WorkingDatabase


Using tr AsTransaction = db.TransactionManager.StartTransaction


Dim bt AsBlockTable = db.BlockTableId.GetObject(OpenMode.ForRead)


Dim blID AsObjectId = bt("TITLEBLOCK")


Dim blkRefTitle AsBlockReference = blID.GetObject(OpenMode.ForRead)


Dim myAttColl AsAttributeCollection = blkRefTitle.AttributeCollection


ForEach myAttRefId AsObjectIdIn myAttColl


Dim myAttRef AsAttributeReference = myAttRefId.GetObject(OpenMode.ForWrite)


If myAttRef.Tag = "DWGNUM"Then

                        strDwgNum = myAttRef.TextString













Valued Contributor
95 Posts
1 Kudo
Registered: ‎11-15-2011
Post 2 of 3

Re: Problem with editing attributes in a block

03-16-2012 07:22 AM in reply to: btmcad



firstly, i think that although the block table does contain blocktablerecords and block definitions (and block attribute definitions), the starting point should be the former so that: 

"Dim blkRefTitle AsBlockReference = blID.GetObject(OpenMode.ForRead)" should read

Dim blkRefTitle AsBlockTableRecord = blID.GetObject(OpenMode.ForRead), i.e. access any specificly named blocktablerecord via its 'parent' blocktable.

secondly, a blocktablerecord may or may not then contain blockreferences (derived from the blockdefinition in the blocktable), so only when you find the respective blockreference in its 'parent' blocktablerecord you can access it as such. (i would think the same applies to block attributes: attdefs are kept in the bt and attrefs are appended to the blockref's attcol.)


this is new to me too, but hope this helps.




*Expert Elite*
1,569 Posts
171 Kudos
Registered: ‎10-08-2008
Post 3 of 3

Re: Problem with editing attributes in a block

03-16-2012 09:52 AM in reply to: btmcad

Your main mistake is you don't understand difference between BlockReference

and BlockTableRecord

See nice explanation about this in the post#2 by Norman Yuan from this thread:


secondly, this line of your code:


strDwgNum = myAttRef.TextString

just read attribute value but do not change it

and also if you want to change just one item within the

For Each....Next statement, you have to use Exit For right after

you reach at desired item to avoid infinite or extafluous  loop, something like


For Each obj as AnyType in SomeCollection

If obj.SomeProperty=ExactValue Then


Exit For



hope that helps




Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!