hi all,
found the solution for this problem..
after reading the block to new database, change the layer name of the block to the current layer name in the parent database. (create a layer with the same name in the new database). then after inserting block to parent database and after creating the block reference and append it. then do a blockrefernce.ExplodetoOwnerSpace.
here is the code
// Creating the new database for reading the block
Database dbNew = new Database();
using (Transaction transNew = dbNew.TransactionManager.StartTransaction())
{
// Reading the selected scheme block in to a new database
dbNew.ReadDwgFile(sDwgFileName, FileOpenMode.OpenForReadAndAllShare, true, "");
BlockTableRecord btrNew = (BlockTableRecord)transNew.GetObject(dbNew.CurrentSpaceId, OpenMode.ForWrite);
LayerTable lt=(LayerTable)transNew.GetObject(dbNew.LayerTableId,OpenMode.ForWrite);
// Checking whether the current layer name in the original database exists in the new database, Adding the layer if it doesnt exists
if (lt.Has(currentLayerName) == false)
{
LayerTableRecord ltrNew = new LayerTableRecord();
ltrNew.Name = currentLayerName;
lt.Add(ltrNew);
transNew.AddNewlyCreatedDBObject(ltrNew, true);
}
// Changing layer of all objects to current layer.
foreach (ObjectId idNew in btrNew)
{
Entity objNew = (Entity)transNew.GetObject(idNew, OpenMode.ForWrite);
objNew.Layer = currentLayerName;
}
transNew.Commit();
}
// Inserting block to the current database
blockId = db.Insert(sBlockName, dbNew, true);
}
using (Transaction trans1 = doc.TransactionManager.StartTransaction())
{
BlockTableRecord btr = (BlockTableRecord)trans1.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
BlockReference blkRef = new BlockReference(new Point3d(0, 0, 0), blockId);
blkRef.LayerId = db.Clayer;
btr.AppendEntity(blkRef);
trans1.AddNewlyCreatedDBObject(blkRef, true);
blkRef.LayerId = db.Clayer;
// Exploding the block
blkRef.ExplodeToOwnerSpace();
blkRef.Erase();
trans1.Commit();
}