This sample code demonstrates how to use WblockCloneObjects to copy objects between DWG Databases – a set of dimstyles in this case. It also (quite arbitrarily) demonstrates a little know function for retrieving the most recently used dimstyles – GetDimRecentStyleList (or at least I’d not come across this function before ).
As an aside, a common mistake many people make when cloning DBObjects is to call their clone function. This must be used with care because it makes a shallow copy of the object. Depending what you’re doing with the clone, its usually best to wblockclone or deepclone instead.
[CommandMethod("ImportStyles")]
static public void importStyles()
{
Database db = new Database(false, false);
db.ReadDwgFile("C:\\Styles.dwg", System.IO.FileShare.Read, true, "");
// Get up to 6 most recently used styles
ObjectIdCollection dimStyles = db.GetDimRecentStyleList();
Database destDb =
Application.DocumentManager.MdiActiveDocument.Database;
ObjectId destDictId = destDb.DimStyleTableId;
IdMapping iMap = new IdMapping();
// Replace any existing styles
destDb.WblockCloneObjects(dimStyles, destDictId, iMap,
DuplicateRecordCloning.Replace, false);
}
