← Inbox

C3D-0470 · Build 22X17 layout: create + clone source paperspace 260904 done

CreateLayout 22X17, then WblockClone the SS_BLOCK_22X17.dwg 22X17 paperspace entities (title block etc.) into it.

Script file
C3D-0470.cs
Target
260904 - 920 W Sandtown Rd SW.dwg · model space
Author
claude
Approved
yes · auto-auth
Timeout
60s

C# payload


string path=@"C:\Users\sanja\OneDrive\_SurveyDisco\SS_BLOCK_22X17.dwg";
// 1) create the destination layout (valid empty paperspace)
var lmgr=LayoutManager.Current;
string dest="22X17";
if(lmgr.GetLayoutId(dest).IsNull) lmgr.CreateLayout(dest);
var destLay=(Layout)Tx.GetObject(lmgr.GetLayoutId(dest),OpenMode.ForRead);
ObjectId destPs=destLay.BlockTableRecordId;
// 2) side-open source, gather its 22X17 paperspace entity ids
using(var src=new Database(false,true)){
    src.ReadDwgFile(path,System.IO.FileShare.Read,true,null);
    var ids=new ObjectIdCollection();
    ObjectId srcPs=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"){ var lay=(Layout)stx.GetObject((ObjectId)de.Value,OpenMode.ForRead); srcPs=lay.BlockTableRecordId; } }
        var ps=(BlockTableRecord)stx.GetObject(srcPs,OpenMode.ForRead);
        foreach(ObjectId eid in ps){ var ent=stx.GetObject(eid,OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Entity; if(ent==null) continue; if(ent is Viewport vp && vp.Number==1) continue; ids.Add(eid); }
        stx.Commit();
    }
    Log("source 22X17 entities to clone: "+ids.Count);
    // 3) clone them into the dest paperspace
    var map=new IdMapping();
    src.WblockCloneObjects(ids, destPs, map, DuplicateRecordCloning.Replace, false);
    Log("cloned into 22X17 paperspace");
}
lmgr.CurrentLayout=dest;
Ed.Regen();

Result

Status
success
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\260711 - 281 Maranatha Trail, Lawrenceville, GA 30045, USA\260711 - 281 Maranatha Trail R2.dwg
Message
Executed C3D-0470 (0 entities touched).
Entities
Duration
1159 ms
Civil 3D
25.0.0.0

Log

source 22X17 entities to clone: 5
cloned into 22X17 paperspace

Notes

What worked, what didn't, job-specific gotchas — flagged notes feed the recipes.

No notes yet.