Perhaps this will help.
Joe
...
<CommandMethod("IBFF")>
_
Public Shared Sub
InsertBlockFromFile()
'get an
editor object
Dim ed As Editor =
Application.DocumentManager.MdiActiveDocument.Editor
'ask for
block name from user
Dim
BlockNameOptions As PromptStringOptions = New PromptStringOptions("Enter block
name")
'no spaces allowed with
block names
BlockNameOptions.AllowSpaces =
False
'get the
input
Dim BlockNameResult As
PromptResult = ed.GetString(BlockNameOptions)
'check
for valid input
If
(BlockNameResult.Status = PromptStatus.OK)
Then
'get
the working
database
Dim dwg As Database =
ed.Document.Database
'start a
transaction
Dim ta As Transaction = dwg.TransactionManager.StartTransaction
size=2>
Try
'create temporary database to read in
block
Dim dbDwg As New
Database()
'read the file from
disk
dbDwg.ReadDwgFile("C:\Drawing2.dwg", IO.FileShare.Read, True,
"")
'insert it into the current
database
dwg.Insert(BlockNameResult.StringResult.ToString, dbDwg,
False)
'dispose of temporary database
object
dbDwg.Dispose()
size=2>
'open the block table for
read
Dim BlockTable As BlockTable = ta.GetObject(dwg.BlockTableId,
OpenMode.ForRead)
size=2>
'see if the block table record
exists
If (BlockTable.Has(BlockNameResult.StringResult) = True)
Then
'prompt user for insertion
point
Dim PromptPointOptions As PromptPointOptions = New PromptPointOptions("Select
insertion
point")
'get user to select the insertion
point
Dim PromptPointResult As PromptPointResult =
ed.GetPoint(PromptPointOptions)
size=2>
'user selected a valid
point
If (PromptPointResult.Status = PromptStatus.OK)
Then
'fix up the point to be a Point3D
object
Dim Point3D As New Point3d(PromptPointResult.Value.X, PromptPointResult.Value.Y,
PromptPointResult.Value.Z)
size=2>
'insert the block at the insertion
point
Dim BlockRef As BlockReference = New BlockReference(Point3D,
BlockTable.Item(BlockNameResult.StringResult))
size=2>
'add block reference to the current
space
Dim CurrentSpace As BlockTableRecord = ta.GetObject(dwg.CurrentSpaceId,
OpenMode.ForWrite)
size=2>
'add the block reference to the current
space
CurrentSpace.AppendEntity(BlockRef)
size=2>
'tell the
transaction
ta.AddNewlyCreatedDBObject(BlockRef, True)
size=2>
'commit transaction to
database
ta.Commit()
size=2>
End If
size=2>
Else
MsgBox("Block " & BlockNameResult.StringResult.ToString & " does not
exists")
size=2>
End If
size=2> Catch
ex As
Exception
MsgBox(ex.Message)
size=2>
Finally
size=2>
'always dispose of
transaction
ta.Dispose()
size=2> End
Try
End If
End Sub
<JoshLund> wrote in message
news:6107709@discussion.autodesk.com...
Good evening, Does anyone have a code
snippet that shows how to insert a drawing (as a block) into the current
drawing? I searched this forum for a few samples and only found partial
functions, too little for me to turn into a working function or even understand
what I should attempt to do. I have a drawing on my hard drive and I want to
insert it into my current drawing. It seems simple enough but I'm not getting
it. Any suggestions? Thanks, Josh Windows XP SP2 VS 2005 SP1 AutoCAD Civil 3D
2009 SP2