I thought I would throw this in for you when you double click the the picture it will prompt you to click for a insertion point, and insert the drawing in the picture as a block. I thought I saw a post by you that you wanted to mimic the insert command.
There are three constructors for the Database.Insert
Here is what the docs say about the constructor I am using
This function mimics the AutoCAD INSERT command. First a new block table record is created in the database executing this function. This new block table record is given the name pointed to by blockName. Then, all the Model Space entities in the database pointed to by dataBase are copied into the new block table record.
The preserveSourceDatabase argument determines whether the source database dataBase is left intact. The default value of the argument is true. In that case, objects from the source database are copied to the destination database, and the source database is not changed. If the caller passes false for this argument, objects from the source database could be physically moved into the destination database. The latter runs faster, but it leaves the source database dependent on the destination database. The caller should make sure that the source database is deleted either immediately, or at least before the destination database is deleted.
Returns the object ID for the new block table record created by this function.
Here is the added code to last post I did
Code:
Imports System.IO
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.ApplicationServices.Application
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Runtime
Imports System.Drawing
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Geometry
Public Class Form1
Private Shared folderName As String = ""
Private Shared filename As String = ""
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Fbd.ShowDialog = Windows.Forms.DialogResult.OK Then
folderName = Fbd.SelectedPath
lstbxFiles.Items.Clear()
For Each fName In Directory.GetFiles(folderName, "*.dwg")
Me.lstbxFiles.Items.Add(Path.GetFileNameWithoutExtension(fName))
Next
End If
End Sub
Private Sub lstbxFiles_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstbxFiles.SelectedIndexChanged
Dim db As Database = New Database(False, False)
filename = lstbxFiles.SelectedItem.ToString()
db.ReadDwgFile(folderName & "\" & filename & ".dwg", FileOpenMode.OpenForReadAndReadShare, False, "")
Dim tmbNail As Bitmap = db.ThumbnailBitmap
picBox.Image = tmbNail
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub picBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picBox.Click
Dim fname As String = folderName & "\" & filename & ".dwg"
Dim ObjId As ObjectId
Dim db As Database = HostApplicationServices.WorkingDatabase()
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Using trans As Transaction = db.TransactionManager.StartTransaction
Dim bt As BlockTable = db.BlockTableId.GetObject(OpenMode.ForRead)
Dim btr As BlockTableRecord = bt(BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite)
Using dbInsert As New Database(False, True)
dbInsert.ReadDwgFile(fname, IO.FileShare.Read, True, "")
ObjId = db.Insert(Path.GetFileNameWithoutExtension(fname), dbInsert, True)
End Using
Dim ppo As New PromptPointOptions("Insertion Point")
Dim ppr As PromptPointResult
ppr = ed.GetPoint(ppo)
If ppr.Status <> PromptStatus.OK Then
ed.WriteMessage(vbCrLf & "You decided to QUIT!")
Exit Sub
End If
Dim insertPt As Point3d = ppr.Value
Dim bref As New BlockReference(insertPt, ObjId)
btr.AppendEntity(bref)
trans.AddNewlyCreatedDBObject(bref, True)
trans.Commit()
End Using
End Sub
End Class