← Inbox

C3D-0689 · Read: whole-drawing snapshot error

Read-only drawing-snapshot recipe: layers, points, text, dimensions, blocks, Civil objects, layouts. Changes nothing.

Script file
C3D-0689.cs
Target
260714 - 285 Huckaby Rd 22x17.dwg · model space
Author
claude
Approved
yes · auto-auth
Timeout
180s

C# payload

// READ-ONLY WHOLE-DRAWING SNAPSHOT.
//
// The earlier "snapshot" walked only polylines/lines/arcs outside layer 0 - written for a narrow
// linework-bulge diff, not a picture of the document. This reads EVERYTHING so any question about
// the drawing can be answered from one capture. Nothing is modified.
var lt  = (LayerTable)Tx.GetObject(Db.LayerTableId, OpenMode.ForRead);
var bt  = (BlockTable)Tx.GetObject(Db.BlockTableId, OpenMode.ForRead);
var ms  = (BlockTableRecord)Tx.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(Db), OpenMode.ForRead);
Log("=== SNAPSHOT ===");
Log("drawing: " + Db.Filename);

// ---------------------------------------------------------------- layers x types
var perLayer = new Dictionary<string, Dictionary<string,int>>();
Action<string,string> bump = (lay, t) => {
    if (!perLayer.ContainsKey(lay)) perLayer[lay] = new Dictionary<string,int>();
    if (!perLayer[lay].ContainsKey(t)) perLayer[lay][t] = 0;
    perLayer[lay][t]++;
};
int model = 0, paper = 0, blockdef = 0;
foreach (ObjectId btrId in bt) {
    var btr = (BlockTableRecord)Tx.GetObject(btrId, OpenMode.ForRead);
    bool isModel = btr.Name.ToUpper() == "*MODEL_SPACE";
    foreach (ObjectId id in btr) {
        Autodesk.AutoCAD.DatabaseServices.DBObject o;
        try { o = Tx.GetObject(id, OpenMode.ForRead); } catch { continue; }
        var ent = o as Autodesk.AutoCAD.DatabaseServices.Entity;
        if (ent == null) continue;
        if (isModel) model++; else if (btr.IsLayout) paper++; else blockdef++;
        string lay; try { lay = ent.Layer; } catch { continue; }
        bump(lay, o.GetType().Name);
    }
}
Log("");
Log("entities: model=" + model + "  paper=" + paper + "  blockdef=" + blockdef);

int nLayers = 0, nUsed = 0;
foreach (ObjectId lid in lt) { nLayers++; }
Log("");
Log("=== LAYERS IN USE ===");
var lnames = new List<string>(perLayer.Keys);
lnames.Sort();
foreach (var nm in lnames) {
    nUsed++;
    var parts = new List<string>();
    int tot = 0;
    foreach (var kv in perLayer[nm]) { parts.Add(kv.Key + ":" + kv.Value); tot += kv.Value; }
    string state = "";
    try {
        if (lt.Has(nm)) {
            var l = (LayerTableRecord)Tx.GetObject(lt[nm], OpenMode.ForRead);
            state = (l.IsOff ? " OFF" : "") + (l.IsFrozen ? " FROZEN" : "") + (l.IsLocked ? " LOCKED" : "");
        }
    } catch { }
    Log(String.Format("  {0,-34} n={1,-5}{2}  [{3}]", nm, tot, state, String.Join(" ", parts)));
}
Log("  layers total=" + nLayers + "  in use=" + nUsed);

// ---------------------------------------------------------------- points
var byDesc = new Dictionary<string,int>();
int npts = 0;
foreach (ObjectId id in ms) {
    var cp = Tx.GetObject(id, OpenMode.ForRead) as CogoPoint;
    if (cp == null) continue;
    npts++;
    string d = "";
    try { d = (cp.RawDescription ?? "").Trim().ToUpper(); } catch { }
    if (d.Length == 0) d = "<blank>";
    if (!byDesc.ContainsKey(d)) byDesc[d] = 0;
    byDesc[d]++;
}
Log("");
Log("=== COGO POINTS: " + npts + " ===");
var descs = new List<string>(byDesc.Keys); descs.Sort();
foreach (var d in descs) Log(String.Format("  {0,-42} {1}", d, byDesc[d]));

// ---------------------------------------------------------------- text
Log("");
Log("=== TEXT (model space) ===");
int ntext = 0;
foreach (ObjectId id in ms) {
    Autodesk.AutoCAD.DatabaseServices.DBObject o;
    try { o = Tx.GetObject(id, OpenMode.ForRead); } catch { continue; }
    string s = null; double h = 0;
    var mt = o as MText;  if (mt != null) { s = mt.Contents; h = mt.TextHeight; }
    var dt = o as DBText; if (dt != null) { s = dt.TextString; h = dt.Height; }
    if (s == null) continue;
    ntext++;
    var ent = (Autodesk.AutoCAD.DatabaseServices.Entity)o;
    Log(String.Format("  [{0}] {1,-18} h={2:F2}  \"{3}\"", o.Handle, ent.Layer, h,
        (s.Length > 70 ? s.Substring(0,70) + "..." : s).Replace("\n", " | ")));
}
Log("  model-space text: " + ntext);

// ---------------------------------------------------------------- dimensions
Log("");
Log("=== DIMENSIONS ===");
int ndim = 0;
foreach (ObjectId id in ms) {
    var dim = Tx.GetObject(id, OpenMode.ForRead) as Dimension;
    if (dim == null) continue;
    ndim++;
    double m = 0; try { m = dim.Measurement; } catch { }
    Log(String.Format("  [{0}] {1,-18} layer={2,-18} measure={3:F4}", dim.Handle, dim.GetType().Name, dim.Layer, m));
}
Log("  dimensions: " + ndim);

// ---------------------------------------------------------------- blocks + attributes
Log("");
Log("=== BLOCK REFERENCES WITH ATTRIBUTES ===");
foreach (ObjectId btrId in bt) {
    var btr = (BlockTableRecord)Tx.GetObject(btrId, OpenMode.ForRead);
    foreach (ObjectId id in btr) {
        var br = Tx.GetObject(id, OpenMode.ForRead) as BlockReference;
        if (br == null || br.AttributeCollection.Count == 0) continue;
        Log("  \"" + br.Name + "\" [" + br.Handle + "] in " + btr.Name);
        foreach (ObjectId aid in br.AttributeCollection) {
            var at = Tx.GetObject(aid, OpenMode.ForRead) as AttributeReference;
            if (at != null) Log(String.Format("      {0,-22} = \"{1}\"", at.Tag, at.TextString));
        }
    }
}

// ---------------------------------------------------------------- civil objects
Log("");
Log("=== CIVIL OBJECTS ===");
var civil = CivilApplication.ActiveDocument;
try {
    foreach (ObjectId sid in civil.GetSiteIds()) {
        var site = (Site)Tx.GetObject(sid, OpenMode.ForRead);
        var pids = site.GetParcelIds();
        if (pids.Count == 0) continue;
        Log("  SITE \"" + site.Name + "\"  parcels=" + pids.Count);
        foreach (ObjectId pid in pids) {
            var p = (Parcel)Tx.GetObject(pid, OpenMode.ForRead);
            Log(String.Format("     \"{0}\" [{1}] area={2:F2} layer={3}", p.Name, p.ObjectId.Handle, p.Area, p.Layer));
        }
    }
} catch (System.Exception ex) { Log("  sites: " + ex.Message); }

int nlbl = 0;
foreach (ObjectId id in ms) {
    var l = Tx.GetObject(id, OpenMode.ForRead) as Autodesk.Civil.DatabaseServices.Label;
    if (l != null) nlbl++;
}
Log("  civil labels=" + nlbl);

// ---------------------------------------------------------------- layouts
Log("");
Log("=== LAYOUTS ===");
var ldict = (DBDictionary)Tx.GetObject(Db.LayoutDictionaryId, OpenMode.ForRead);
foreach (DBDictionaryEntry de in ldict) {
    var lay = (Layout)Tx.GetObject(de.Value, OpenMode.ForRead);
    var lbtr = (BlockTableRecord)Tx.GetObject(lay.BlockTableRecordId, OpenMode.ForRead);
    int cnt = 0, vps = 0;
    foreach (ObjectId x in lbtr) {
        cnt++;
        if (Tx.GetObject(x, OpenMode.ForRead) is Viewport) vps++;
    }
    Log(String.Format("  \"{0}\" tab={1} entities={2} viewports={3} paper={4}",
        lay.LayoutName, lay.TabOrder, cnt, vps, lay.CanonicalMediaName));
}
Log("");
Log("=== SNAPSHOT END ===");

Result

Status
error
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\260714 - 285 Huckaby Rd, Brooks, GA 30205, USA\260714 - 285 Huckaby Rd 22x17.dwg
Message
Compile error: (55,9): error CS8652: The feature 'params collections' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version.; (90,9): error CS8652: The feature 'params collections' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version.; (104,9): error CS8652: The feature 'params collections' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version.; (136,17): error CS8652: The feature 'params collections' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version.; (160,9): error CS8652: The feature 'params collections' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version.
Entities
—
Duration
4844 ms
Civil 3D
26.0.0.0

Notes

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

No notes yet.