Hehehe...but it's finding it AGAIN when you know you've "seen it somewhere".
It seems like we're the only 2 interested in this Kerry. For the sake of completeness,
here is a cleaned up implementation that should be easier to follow:
[CommandMethod("IPS", CommandFlags.NoTileMode)]
static public void ImportPageSetupCommand( )
{
Database dwtDb = null;
// Get a pointer to the current doc's dbase...
Document doc = acadApp.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Transaction dwtDbTr = null;
// Objectid collection to hold the pagesetups we're going to clone...
ObjectIdCollection psIds = new ObjectIdCollection();
IdMapping psIdMap = null;
try
{
dwtDb = new Database(false, true);
dwtDb.ReadDwgFile(@"C:\Temp\Plot.dwt", System.IO.FileShare.ReadWrite, false, null);
// Kick off the transaction on the template dbase...
dwtDbTr = dwtDb.TransactionManager.StartTransaction();
DBDictionary dwtDbPsDict = dwtDbTr.GetObject(dwtDb.PlotSettingsDictionaryId, OpenMode.ForRead) as DBDictionary;
foreach (System.Collections.DictionaryEntry psDbPs in dwtDbPsDict)
psIds.Add((ObjectId)psDbPs.Value);
if (psIds.Count == 0)
return;
dwtDbTr.Commit();
// Got id's, so clone 'em
psIdMap = db.WblockCloneObjects(psIds, db.PlotSettingsDictionaryId, DuplicateRecordCloning.Ignore, false);
RenameAnonymousPageSetups(psIdMap);
}
finally
{
if (dwtDbTr != null)
dwtDbTr.Dispose();
if (dwtDb != null)
dwtDb.Dispose();
}
return;
}
static void RenameAnonymousPageSetups(IdMapping plotSettingsIdMap)
{
Database db = plotSettingsIdMap.DestinationDatabase;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
DBDictionary psDict = tr.GetObject(db.PlotSettingsDictionaryId, OpenMode.ForWrite, false) as DBDictionary;
if (psDict == null)
return;
foreach (IdPair psIdPair in plotSettingsIdMap)
{
ObjectId id = psIdPair.Value;
PlotSettings ps = tr.GetObject(id, OpenMode.ForWrite, false) as PlotSettings;
if (ps == null)
continue;
if (psDict.Contains(ps.PlotSettingsName))
{
ObjectId existingPsId = psDict.GetAt(ps.PlotSettingsName);
if (existingPsId != ObjectId.Null)
psDict.Remove(existingPsId);
}
string anonymousName = psDict.NameAt(id);
psDict.SetName(anonymousName, ps.PlotSettingsName);
}
tr.Commit();
}
}
Cheers,
Glenn.