Author Topic: Block attribute reference and attribute definition  (Read 3358 times)

0 Members and 1 Guest are viewing this topic.

kvstone

  • Guest
Block attribute reference and attribute definition
« on: December 07, 2012, 09:24:41 AM »
If i want to add a new attribute to exist block(contains attributes), what is the correct/necessary step?

1. add new attribute definition to blockTableRecord(necessary?)
2. add new attribute reference to block reference?

Then, if the block definition has more then one block reference, need i add attribute reference to each reference?

TheMaster

  • Guest
Re: Block attribute reference and attribute definition
« Reply #1 on: December 10, 2012, 07:33:01 PM »
If i want to add a new attribute to exist block(contains attributes), what is the correct/necessary step?

1. add new attribute definition to blockTableRecord(necessary?)
2. add new attribute reference to block reference?

Then, if the block definition has more then one block reference, need i add attribute reference to each reference?

Yes, which is essentially what the ATTSYNC command does.

You have to add the attribute definition to the block definition so that subsequently-inserted blocks will have the attribute, and you have to add attribute references to each existing block reference.

kvstone

  • Guest
Re: Block attribute reference and attribute definition
« Reply #2 on: December 11, 2012, 08:39:27 AM »

Yes, which is essentially what the ATTSYNC command does.

You have to add the attribute definition to the block definition so that subsequently-inserted blocks will have the attribute, and you have to add attribute references to each existing block reference.

Tks ,TT

I wrote the following code to add a new Att Definition to a block table record,
it runs without any error, but that seems nothing happened ,and no att has been added to the block.

Pls help me to check what i missed. Appreciate.


Code - vb.net: [Select]
  1.     Public Sub AddAttribute(ByVal attTag As String, ByVal attText As String)
  2.         Dim doc As Document = Application.DocumentManager.MdiActiveDocument
  3.         Dim attRef As AttributeReference
  4.         Dim blkTr As BlockTableRecord
  5.         Using docLock As DocumentLock = doc.LockDocument
  6.             Using trs As Transaction = doc.Database.TransactionManager.StartTransaction()
  7.                 bkRef = trs.GetObject(MyClass.BlockId, OpenMode.ForRead)
  8.                 If bkRef.IsDynamicBlock Then
  9.                     _blkTbRecId = bkRef.DynamicBlockTableRecord
  10.                 Else
  11.                     _blkTbRecId = bkRef.BlockTableRecord
  12.                 End If
  13.  
  14.                 blkTr = TryCast(trs.GetObject(_blkTbRecId, OpenMode.ForWrite), BlockTableRecord)
  15.                 Dim attDef As AttributeDefinition = New AttributeDefinition(blkTr.Origin, attText, attTag, "", doc.Database.Textstyle)
  16.  
  17.                 blkTr.AppendEntity(attDef)
  18.                 trs.AddNewlyCreatedDBObject(attDef, True)
  19.  
  20.                 trs.Commit()
  21.             End Using
  22.         End Using
  23.     End Sub
  24.  

Jeff H

  • Needs a day job
  • Posts: 6117
Re: Block attribute reference and attribute definition
« Reply #3 on: December 11, 2012, 10:12:12 AM »
 

Yes, which is essentially what the ATTSYNC command does.

You have to add the attribute definition to the block definition so that subsequently-inserted blocks will have the attribute, and you have to add attribute references to each existing block reference.

Tks ,TT

I wrote the following code to add a new Att Definition to a block table record,
it runs without any error, but that seems nothing happened ,and no att has been added to the block.

Pls help me to check what i missed. Appreciate.


Code - vb.net: [Select]
  1.     Public Sub AddAttribute(ByVal attTag As String, ByVal attText As String)
  2.         Dim doc As Document = Application.DocumentManager.MdiActiveDocument
  3.         Dim attRef As AttributeReference
  4.         Dim blkTr As BlockTableRecord
  5.         Using docLock As DocumentLock = doc.LockDocument
  6.             Using trs As Transaction = doc.Database.TransactionManager.StartTransaction()
  7.                 bkRef = trs.GetObject(MyClass.BlockId, OpenMode.ForRead)
  8.                 If bkRef.IsDynamicBlock Then
  9.                     _blkTbRecId = bkRef.DynamicBlockTableRecord
  10.                 Else
  11.                     _blkTbRecId = bkRef.BlockTableRecord
  12.                 End If
  13.  
  14.                 blkTr = TryCast(trs.GetObject(_blkTbRecId, OpenMode.ForWrite), BlockTableRecord)
  15.                 Dim attDef As AttributeDefinition = New AttributeDefinition(blkTr.Origin, attText, attTag, "", doc.Database.Textstyle)
  16.  
  17.                 blkTr.AppendEntity(attDef)
  18.                 trs.AddNewlyCreatedDBObject(attDef, True)
  19.  
  20.                 trs.Commit()
  21.             End Using
  22.         End Using
  23.     End Sub
  24.  

Yes, which is essentially what the ATTSYNC command does.

You have to add the attribute definition to the block definition so that subsequently-inserted blocks will have the attribute, and you have to add attribute references to each existing block reference.
Quickly looking looks like you got the first half he mentioned.