Below code shows the procedure to clone the dynamic block with all its properties to same drawing file.
Steps:
Wblock the present dynamic block to new database using “wblock”.
Use “Insert” API to insert the database (generated in step1) with new block name
[CommandMethod("cloneDynamic")]
static public void cloneDynamic() // This method can have any name
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
using (Transaction tr =
db.TransactionManager.StartTransaction())
{
BlockTable tb = tr.GetObject(db.BlockTableId,
OpenMode.ForRead) as BlockTable;
BlockTableRecord dynamic = tr.GetObject(tb["DynamicBlock"],
OpenMode.ForRead) as BlockTableRecord;
Database temDB = db.Wblock(dynamic.ObjectId);
ObjectId copyId = ObjectId.Null;
using (temDB)
{
copyId = db.Insert("DynamicBlockCopy", temDB, true);
}
tr.Commit();
}
}

Leave a Reply to DanielCancel reply