Insert Block Not Working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
Here is my code to insert the Block in the Currently opened Drawing, it used to work well, when I was using Express version of VB, now i am using VB studio professional, and I am facing this error !dbinsert834@ eNotdatabase,
i get the error in line in red
please help me.
Public Sub InsertDrawing(ByVal dwgName As String, ByVal insPt As AcGe1.Point3d, ByVal s3d As AcGe1.Scale3d, ByVal rot As Double)
Dim blkName As String = Path.GetFileNameWithoutExtension(dwgName)
Using db As Database = AcDb1.HostApplicationServices.WorkingDatabase()
Using tr As Transaction = db.TransactionManager.StartTransaction
Try
Dim id As ObjectId = Nothing
Using bt As BlockTable = tr.GetObject(db.BlockTableId, OpenMode.ForRead, True)
If Not bt.Has(blkName) Then
Using sourceDb As Database = New Autodesk.AutoCAD.DatabaseServices.Database(False, True)
sourceDb.ReadDwgFile(dwgName, FileOpenMode.OpenForReadAndAllShare, True, "")
id = db.Insert(dwgName, sourceDb, False)
Dim blk As BlockTableRecord = tr.GetObject(id, OpenMode.ForWrite, False, True)
blk.Name = blkName
End Using
Else
id = bt.Item(blkName)
End If
End Using
Dim btr As BlockTableRecord = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite, True)
Dim bref As BlockReference = New BlockReference(insPt, id)
bref.ScaleFactors = s3d
bref.Rotation = rot
Dim ObjColl As DBObjectCollection = New DBObjectCollection()
bref.Explode(ObjColl)
For Each acEnt As Entity In ObjColl
btr.AppendEntity(acEnt)
tr.AddNewlyCreatedDBObject(acEnt, True)
Next
PurgeBlockMethod(blkName)
bref.Dispose()
btr.Dispose()
tr.Commit()
Catch ex As Autodesk.AutoCAD.Runtime.Exception
MessageBox.Show(ex.StackTrace)
Finally
'PlineExplode()
End Try
End Using
End Using
End Sub