I've actually got the file extension in the filename, but I'll try adding
more error trapping.
I also noticed that you dispose of things like the bref and db, which I
wasn't doing. I'll add that stuff too.
Thanks very much for your help. I really appreciate that you would take the
time.
-Carlos
wrote in message news:4927502@discussion.autodesk.com...
I converted your code to VB because I know and needed then got rid of error
by specifying file extension.
You'll probably want to add more testing to check that the file exists or
error trapping around FindFile part to prevent error.
Good luck.
_
Sub altBlkInsert()
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim fname As String = "c:\MyBlockFile.dwg"
HostApplicationServices.Current.FindFile(fname, doc.Database,
FindFileHint.Default)
' Using
Dim db As Database = New Database(False, False)
Try
db.ReadDwgFile(fname, System.IO.FileShare.Read, True, Nothing)
' Using
Dim t As Transaction = doc.TransactionManager.StartTransaction
Try
Dim idBTR As ObjectId = doc.Database.Insert("MyBlockFile", db,
False)
Dim bt As BlockTable =
CType(t.GetObject(doc.Database.BlockTableId, OpenMode.ForRead), BlockTable)
Dim btr As BlockTableRecord =
CType(t.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite),
BlockTableRecord)
Dim origin As Point3d = New Point3d(0, 0, 0)
' Using
Dim bref As BlockReference = New BlockReference(origin, idBTR)
Try
btr.AppendEntity(bref)
t.TransactionManager.AddNewlyCreatedDBObject(bref, True)
Finally
CType(bref, IDisposable).Dispose()
End Try
t.Commit()
t.Dispose()
Finally
CType(t, IDisposable).Dispose()
End Try
Finally
CType(db, IDisposable).Dispose()
End Try
End Sub