brID = modelspace.AppendEntity(blockRef)
tr.AddNewlyCreatedDBObject(blockRef, True)
For Each idAtt As ObjectId In btr
Dim subent As Entity
subent = CType(tr.GetObject(idAtt, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead), Entity)
If TypeOf subent Is AttributeDefinition Then
Dim str_text As String
Dim attDef As AttributeDefinition
attDef = CType(subent, AttributeDefinition)
Dim attRef As New AttributeReference()
attRef.SetAttributeFromBlock(attDef, blockRef.BlockTransform)
Dim ptBase As New Autodesk.AutoCAD.Geometry.Point3d(attRef.Position.X, attRef.Position.Y, attRef.Position.Z)
attRef.Position = ptBase
attRef.Tag = attDef.Tag
attRef.TextString = str_text
End If
Dim idTmp As ObjectId
idTmp = blockRef.AttributeCollection.AppendAttribute(attRef)
tr.AddNewlyCreatedDBObject(attRef, True)
Code: [Select]brID = modelspace.AppendEntity(blockRef)
tr.AddNewlyCreatedDBObject(blockRef, True)
For Each idAtt As ObjectId In btr
Dim subent As Entity
subent = CType(tr.GetObject(idAtt, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead), Entity) <--opening objects unnecessarily
If TypeOf subent Is AttributeDefinition Then
Dim str_text As String
Dim attDef As AttributeDefinition
attDef = CType(subent, AttributeDefinition)
Dim attRef As New AttributeReference()
attRef.SetAttributeFromBlock(attDef, blockRef.BlockTransform)<--should set database defaults first
Dim ptBase As New Autodesk.AutoCAD.Geometry.Point3d(attRef.Position.X, attRef.Position.Y, attRef.Position.Z)<--this is useless, the last step sets the position for you
attRef.Position = ptBase
attRef.Tag = attDef.Tag<--ditto to redundant
attRef.TextString = str_text
End If
Dim idTmp As ObjectId
idTmp = blockRef.AttributeCollection.AppendAttribute(attRef)
tr.AddNewlyCreatedDBObject(attRef, True)
I can't remember exactly why the choice to call SetDatabaseDefaults first, I put this extension together quite awhile back and have never needed to think about it again...