Using the WblockCloneObjects() method, its possible to copy a particular block from a drawing in to the other drawing. The C# code snippet that shows how to use WblockCloneObjects to copy a specific block "test" from the drawing available at "C:\TEMP\test.dwg".
[CommandMethod("InsertBlock")]
static public void InsertBlock() // This method can have any name
{
Document doc = Application.DocumentManager.MdiActiveDocument;
using(Database OpenDb = new Database(false, true))
{
OpenDb.ReadDwgFile("c:\\temp\\test.dwg",
System.IO.FileShare.ReadWrite, true, "");
ObjectIdCollection ids = new ObjectIdCollection();
using (Transaction tr =
OpenDb.TransactionManager.StartTransaction())
{
//For example, Get the block by name "TEST"
BlockTable bt;
bt = (BlockTable)tr.GetObject(OpenDb.BlockTableId
, OpenMode.ForRead);
if (bt.Has("TEST"))
{
ids.Add(bt["TEST"]);
}
tr.Commit();
}
//if found, add the block
if (ids.Count != 0)
{
//get the current drawing database
Database destdb = doc.Database;
IdMapping iMap = new IdMapping();
destdb.WblockCloneObjects(ids, destdb.BlockTableId
,iMap,DuplicateRecordCloning.Ignore, false);
}
}
}