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
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
id = bt.Item(blkName)
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()
For Each acEnt As Entity In ObjColl
Catch ex As Autodesk.AutoCAD.Runtime.Exception
My guess is that the blkname it's not a valid block name, because it has "\" in the name. try getting just the blockname from dwgname without the file path in it.
This should not change because the VB version, maybe between AutoCAD versions or the file permission.
Can you quick try the last parameter as TRUE? Use as FALSE is not a easy way, check out the help file.
Dim id As ObjectId = Nothing is it true in VB.NET. because in C# ObjectId is a struct thus a ValueType descendant so must be initialized like
ObjectId id = ObjectId.Null;
i am just asking because i am not very good at VB.NET.
and did you try the overload of ReadDwgFile like this
Access a broad range of knowledge to help get the most out of your products and services.
Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.
Upgrading to a 2015 product? Make sure to check these out 1st!