本帖最后由 kvstone 于 2012-12-11 22:01 编辑
首先,我有个疑问,为Blockreference 添加新的属性,是否需要先给 BlockTableRecored 添加属性,在对每个BlockReference添加属性
然后,下面的程序是为了给BlockTableRecord添加新属性,程序可以运行,没有任何错误,但是属性并没有添加成功,请大家帮忙看看,挑挑毛病在哪
- Public Sub AddAttribute(ByVal attTag As String, ByVal attText As String)
- Dim doc As Document = Application.DocumentManager.MdiActiveDocument
- Dim attRef As AttributeReference
- Dim blkTr As BlockTableRecord
- Using docLock As DocumentLock = doc.LockDocument
- Using trs As Transaction = doc.Database.TransactionManager.StartTransaction()
- bkRef = trs.GetObject(MyClass.BlockId, OpenMode.ForRead)
- If bkRef.IsDynamicBlock Then
- _blkTbRecId = bkRef.DynamicBlockTableRecord
- Else
- _blkTbRecId = bkRef.BlockTableRecord
- End If
- blkTr = TryCast(trs.GetObject(_blkTbRecId, OpenMode.ForWrite), BlockTableRecord)
- Dim attDef As AttributeDefinition = New AttributeDefinition(blkTr.Origin, attText, attTag, "", doc.Database.Textstyle)
- blkTr.AppendEntity(attDef)
- trs.AddNewlyCreatedDBObject(attDef, True)
- trs.Commit()
- End Using
- End Using
- End Sub
|