Try this code for the same drawing
Public Sub ApplyAttributes(db As Database, tr As Transaction, bref As BlockReference)
Dim btrec As BlockTableRecord = TryCast(tr.GetObject(bref.BlockTableRecord, OpenMode.ForRead), BlockTableRecord)
If btrec.HasAttributeDefinitions Then
Dim atcoll As Autodesk.AutoCAD.DatabaseServices.AttributeCollection = bref.AttributeCollection
For Each subid As ObjectId In btrec
Dim ent As Entity = DirectCast(subid.GetObject(OpenMode.ForRead), Entity)
Dim attDef As AttributeDefinition = TryCast(ent, AttributeDefinition)
If attDef IsNot Nothing Then
Dim attRef As New AttributeReference()
attRef.SetDatabaseDefaults()
attRef.SetAttributeFromBlock(attDef, bref.BlockTransform)
attRef.Position = attDef.Position.TransformBy(bref.BlockTransform)
attRef.Tag = attDef.Tag
attRef.TextString = attDef.TextString
attRef.AdjustAlignment(db)
atcoll.AppendAttribute(attRef)
tr.AddNewlyCreatedDBObject(attRef, True)
End If
Next
End If
End Sub
Public Sub TestInsert()
Dim blkname As String = "MYBLOCK" ''<-- change to your needs
Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
Dim db As Database = doc.Database
Try
Using docloc As DocumentLock = doc.LockDocument
Using tr As Transaction = db.TransactionManager.StartTransaction
Dim bt As BlockTable = tr.GetObject(db.BlockTableId, OpenMode.ForRead)
If Not bt.Has(blkname) Then
MsgBox("Block does not exists")
Return
End If
Dim pto As PromptPointOptions = New PromptPointOptions(vbLf + "Pick a block insertion point: ")
Dim ptres As PromptPointResult = ed.GetPoint(pto)
Dim ipt As Point3d
If ptres.Status <> PromptStatus.Cancel Then
ipt = ptres.Value
End If
Dim btr As BlockTableRecord = DirectCast(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite, False), BlockTableRecord)
Dim blk As BlockTableRecord = DirectCast(tr.GetObject(bt(blkname), OpenMode.ForRead, False), BlockTableRecord)
Dim bref As New BlockReference(ipt, blk.ObjectId)
bref.BlockUnit = UnitsValue.Millimeters''<-- change to your needs
bref.Rotation = 0
bref.ScaleFactors = New Scale3d(1.0) ''<-- change to your needs
btr.AppendEntity(bref)
tr.AddNewlyCreatedDBObject(bref, True)
ApplyAttributes(db, tr, bref)
ed.Regen()
tr.Commit()
End Using
End Using
Catch ex As System.Exception
MsgBox(ex.Message)
End Try
End Sub
~'J'~
_____________________________________
C6309D9E0751D165D0934D0621DFF27919