This is probably not the best but in a hurry and might give you a idea.
[CommandMethod("CopyDynamicBlock")]
public void CopyDynamicBlock()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptEntityOptions peo = new PromptEntityOptions("\nSelect Block");
peo.SetRejectMessage("\nNot a Block Reference");
peo.AddAllowedClass(typeof(BlockReference), true);
using (Transaction trx = db.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)trx.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord modelSpace = (BlockTableRecord)trx.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead);
ObjectIdCollection ids = new ObjectIdCollection();
ids.Add(ed.GetEntity(peo).ObjectId);
IdMapping map = new IdMapping();
db.DeepCloneObjects(ids, modelSpace.ObjectId, map, false);
BlockReference newBref = null;
BlockTableRecord blockBtr = null;
foreach (IdPair pair in map)
{
if (pair.Value.ObjectClass == RXClass.GetClass(typeof(BlockReference)))
{
newBref = (BlockReference)trx.GetObject(pair.Value, OpenMode.ForWrite);
newBref.Position = ed.GetPoint("\nSelect Point").Value;
blockBtr = (BlockTableRecord)trx.GetObject(newBref.BlockTableRecord, OpenMode.ForRead);
}
}
foreach (ObjectId id in blockBtr)
{
if (id.ObjectClass == RXClass.GetClass(typeof(AttributeDefinition)))
{
AttributeDefinition attDef = (AttributeDefinition)trx.GetObject(id, OpenMode.ForRead);
foreach (ObjectId refId in newBref.AttributeCollection)
{
AttributeReference attRef = (AttributeReference)trx.GetObject(refId, OpenMode.ForWrite);
if (attRef.Tag == attDef.Tag)
{
attRef.Position = attDef.Position;
attRef.SetAttributeFromBlock(newBref.BlockTransform);
}
}
}
}
trx.Commit();
}
}