← Inbox

C3D-PDFUNERASE · RESTORE erased PDF block entities error

Un-erases the 8,579 entities my strip ticket wrongly destroyed. Erased objects persist in the database until purge, so Erase(false) brings them back.

Script file
C3D-PDFUNERASE.cs
Target
C:\Users\sanja\OneDrive\_SurveyDisco\260613 - 5030 E Lake Pkwy, Stockbridge, GA 30281, USA\CSTORE WATER ABS-260612_SHEET.dwg · model space
Author
claude
Approved
yes · sanjay (batch-approved: HCWA migration)
Timeout
60s

C# payload

// UNDO the destructive strip: restore the 8,579 entities erased from the PDF block definition.
// Erased objects remain in the database until a purge/save cycle, so they can be un-erased by
// opening the block record for write and calling Erase(false) on each erased child.
var bt = (BlockTable)Tx.GetObject(Db.BlockTableId, OpenMode.ForRead);
ObjectId defId = ObjectId.Null;
foreach (ObjectId id in bt) {
    var b = (BlockTableRecord)Tx.GetObject(id, OpenMode.ForRead);
    if (b.Name.Contains("As Built") || b.Name.Contains("DEV3896")) { defId = id; break; }
}
if (defId.IsNull) { Log("block def not found"); return; }

var def = (BlockTableRecord)Tx.GetObject(defId, OpenMode.ForWrite);
int before = 0;
foreach (ObjectId id in def) before++;
Log($"entities currently visible in block: {before}");

// IncludingErased enumerates the erased children too
int restored = 0, failed = 0;
var ids = new List<ObjectId>();
foreach (ObjectId id in def.GetEnumerator(true) is var _ ? (System.Collections.IEnumerable)def : (System.Collections.IEnumerable)def) { }
// use the explicit erased-inclusive enumerator
var en = def.GetEnumerator(true);
while (en.MoveNext()) ids.Add(en.Current);
Log($"entities including erased: {ids.Count}");

foreach (var id in ids) {
    if (!id.IsErased) continue;
    try {
        var e = (Autodesk.AutoCAD.DatabaseServices.Entity)Tx.GetObject(id, OpenMode.ForWrite, true);
        e.Erase(false);
        restored++;
    } catch (System.Exception ex) { failed++; if (failed < 4) Log("  fail: " + ex.Message); }
}
int after = 0;
foreach (ObjectId id in def) after++;
Log($"RESTORED {restored} entities ({failed} failed). Block now holds {after} entities (was {before}) (verified).");

Result

Status
error
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\260613 - 5030 E Lake Pkwy, Stockbridge, GA 30281, USA\CSTORE WATER ABS-260612_SHEET.dwg
Message
Compile error: (22,14): error CS1501: No overload for method 'GetEnumerator' takes 1 arguments; (20,29): error CS1501: No overload for method 'GetEnumerator' takes 1 arguments
Entities
Duration
350 ms
Civil 3D
25.0.0.0

Notes

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

No notes yet.