C3D-0468 · Clone 22X17 layout from source into 260904 error
WblockClone the 22X17 paperspace BTR from SS_BLOCK_22X17.dwg and register it as layout 22X17 (with the title block already on it).
C# payload
string path=@"C:\Users\sanja\OneDrive\_SurveyDisco\SS_BLOCK_22X17.dwg";
using(var src=new Database(false,true)){
src.ReadDwgFile(path,System.IO.FileShare.Read,true,null);
ObjectId srcLayoutId=ObjectId.Null, srcBtrId=ObjectId.Null;
using(var stx=src.TransactionManager.StartTransaction()){
var lm=(DBDictionary)stx.GetObject(src.LayoutDictionaryId,OpenMode.ForRead);
foreach(System.Collections.DictionaryEntry de in lm){ if(((string)de.Key)=="22X17"){ srcLayoutId=(ObjectId)de.Value; var lay=(Layout)stx.GetObject(srcLayoutId,OpenMode.ForRead); srcBtrId=lay.BlockTableRecordId; } }
stx.Commit();
}
if(srcBtrId.IsNull){ Log("no 22X17 layout in source"); return; }
// wblock-clone the paperspace BTR into this db's block table
var ids=new ObjectIdCollection(); ids.Add(srcBtrId);
var map=new IdMapping();
Db.WblockCloneObjects(ids, Db.BlockTableId, map, DuplicateRecordCloning.Replace, false);
// find the cloned BTR
ObjectId newBtr=map[srcBtrId].Value;
Log("cloned paperspace BTR null? "+newBtr.IsNull);
// create a Layout dict entry pointing at it, named 22X17
var lmgr=LayoutManager.Current;
string dest="22X17"; int i=2; while(!lmgr.GetLayoutId(dest).IsNull){ dest="22X17-"+i; i++; }
// Create a fresh layout then swap its BTR? Instead: build Layout object
var layoutDict=(DBDictionary)Tx.GetObject(Db.LayoutDictionaryId,OpenMode.ForWrite);
var newLayout=new Layout();
newLayout.LayoutName=dest;
var newLayId=layoutDict.SetAt(dest, newLayout);
Tx.AddNewlyCreatedDBObject(newLayout,true);
newLayout.AddToLayoutDictionary(Db, newBtr);
var btr=(BlockTableRecord)Tx.GetObject(newBtr,OpenMode.ForWrite);
btr.LayoutId=newLayId;
Log("created layout "+dest);
lmgr.CurrentLayout=dest;
}
Ed.Regen();
Result
Log
cloned paperspace BTR null? False created layout 22X17
Notes
What worked, what didn't, job-specific gotchas — flagged notes feed the recipes.
No notes yet.