Private Function InBlock(ByVal tr As Transaction, ByVal Name As String, ByVal Path As String, ByVal Scale As Integer, ByVal ip As Point3d) As BlockReference ' tr set outside ' insert block on block layer in separate layout. Dim b As Boolean = False If tr Is Nothing Then tr = CurDb.TransactionManager.StartTransaction() ' just in case b = True ' in which case we need to dispose it in this Function. End If Dim btr As BlockTableRecord Try Dim bt As BlockTable = tr.GetObject(CurDb.BlockTableId, OpenMode.ForRead) Dim blkid As ObjectId If Not bt.Has(Name) Then btr = tr.GetObject(CurDb.CurrentSpaceId, OpenMode.ForWrite) ' not already inserted? Dim db As Database = New Database(False, True) Using db db.ReadDwgFile(Path, System.IO.FileShare.Read, False, "") ' insert dwg blkid = CurDb.Insert(Name, db, True) End Using End If btr = tr.GetObject(CurDb.CurrentSpaceId, OpenMode.ForWrite) If String.IsNullOrEmpty(btr.Name) Then btr.UpgradeOpen() btr.Name = Name btr.DowngradeOpen() End If Dim blk As BlockReference = New BlockReference(ip, blkid) ' insert block blk.SetDatabaseDefaults() blk.Layer = a_Layers.Block blk.ScaleFactors = New Scale3d(Scale, Scale, 1) blk.Rotation = 0 btr.AppendEntity(blk) ' so far so good tr.AddNewlyCreatedDBObject(blk, True) ' add it to transaction Dim btra As BlockTableRecord = blkid.GetObject(OpenMode.ForRead) ' now for attributes For Each objId As ObjectId In btra Dim obj As DBObject = objId.GetObject(OpenMode.ForRead) If TypeOf obj Is AttributeDefinition Then Dim ad As AttributeDefinition = objId.GetObject(OpenMode.ForRead) Dim ar As AttributeReference = New AttributeReference() ar.SetAttributeFromBlock(ad, blk.BlockTransform) ar.Position = ad.Position.TransformBy(blk.BlockTransform) blk.AttributeCollection.AppendAttribute(ar) tr.AddNewlyCreatedDBObject(ar, True) With a_Block.Document For j As Integer = 4 To 19 ' Search Tags If a_Title.Tags(j) = ar.Tag Then ' to find match Select Case j Case 4, 5, 6, 7 : ar.TextString = .Description(j - 4) Case 8 : ar.TextString = .DrawnBy Case 9 : ar.TextString = .Created Case 11 : ar.TextString = a_Job.JobNo Case 10 : ar.TextString = .Number Case 12, 13, 14, 15 : ar.TextString = a_Job.Description(j - 12) Case 16 : ar.TextString = .Revision Case 17, 18 ' Plot Date, Time - not stored Case 19 : ar.TextString = a_Title.ScalesDescription(.Scale) End Select End If Next j End With End If Next AcadEdtr.UpdateScreen() If b Then tr.Commit() ' ie Insert Block is local Return blk Catch ex As Autodesk.AutoCAD.Runtime.Exception If b Then tr.Abort() : tr.Dispose() Return Nothing End Try If b Then tr.Dispose() End Function