← Inbox

C3D-0076 · Restore the two N/A slope labels I overwrote, fix 2EC8E length [REPAIR-LABELS] done

C3D-0075 treated any label without a percent sign as a length label, so the N/A slope labels on 2EC87 and 2EC88 were overwritten with the line length. Restores handles 2EF5E and 2EF5F to N/A and rewrites the 2EC8E length label that was skipped. Targets by handle, verifies each before writing.

Script file
C3D-0076.cs
Target
260612 · model space
Author
claude
Approved
yes · reviewer
Timeout
180s

C# payload

// Repair my own bad rewrite in C3D-0075.
//
// BUG: I treated "any label without a % is a length label". "N/A" has no %, so the N/A SLOPE
// labels on 2EC87 and 2EC88 got overwritten with the line length. Those two lines now show their
// length twice and have no slope label.
//
// Fix: 2EF5E and 2EF5F are addressed BY HANDLE (not by any heuristic) and set back to "N/A".
// Also 2EC8E's length label was skipped last run and is still stale - rewrite it from the line.
//
// Handles come from the C3D-0075 run log; each is verified to be the expected MText on
// SEWER_LINE_TEXT before it is touched, and aborts if it is not what is expected.
var ms = (BlockTableRecord)Tx.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(Db), OpenMode.ForRead);

Func<string, MText> byHandle = h => {
    foreach (ObjectId id in ms) {
        var o = Tx.GetObject(id, OpenMode.ForRead);
        if (o.Handle.ToString() == h) return o as MText;
    }
    return null;
};

// 1) restore the two N/A slope labels I clobbered
string[] restore = new string[] { "2EF5E", "2EF5F" };
foreach (string h in restore) {
    var mt = byHandle(h);
    if (mt == null) { Log("  MISSING " + h + " - skipped"); continue; }
    if (mt.Layer != "SEWER_LINE_TEXT") { Log("  " + h + " not on SEWER_LINE_TEXT - skipped"); continue; }
    string cur = mt.Contents.Trim();
    if (cur == "N/A") { Log("  " + h + " already N/A"); continue; }
    var w = (MText)Tx.GetObject(mt.ObjectId, OpenMode.ForWrite);
    w.Contents = "N/A";
    Log("  [" + h + "] restored slope label  " + cur + " -> N/A");
}

// 2) 2EC8E's length label was missed last run
Line target = null;
foreach (ObjectId id in ms) {
    var o = Tx.GetObject(id, OpenMode.ForRead);
    if (o.Handle.ToString() != "2EC8E") continue;
    target = o as Line;
    break;
}
if (target == null) { Log("  2EC8E not found"); }
else {
    string want = target.Length.ToString("F2") + "'";
    // find the length label nearest that line's midpoint that is not a % label
    double mx = (target.StartPoint.X + target.EndPoint.X) / 2.0;
    double my = (target.StartPoint.Y + target.EndPoint.Y) / 2.0;
    MText best = null; double bd = 1e18;
    foreach (ObjectId id in ms) {
        var mt = Tx.GetObject(id, OpenMode.ForRead) as MText;
        if (mt == null || mt.Layer != "SEWER_LINE_TEXT") continue;
        string c = mt.Contents.Trim();
        if (c.IndexOf('%') >= 0 || c == "N/A") continue;
        double d = Math.Sqrt(Math.Pow(mt.Location.X - mx, 2) + Math.Pow(mt.Location.Y - my, 2));
        if (d < bd) { bd = d; best = mt; }
    }
    if (best == null || bd > 40.0) Log("  no length label found near 2EC8E (nearest " + bd.ToString("F1") + "ft)");
    else if (best.Contents.Trim() == want) Log("  2EC8E length already " + want);
    else {
        string was = best.Contents.Trim();
        var w = (MText)Tx.GetObject(best.ObjectId, OpenMode.ForWrite);
        w.Contents = want;
        Log("  [" + best.Handle + "] 2EC8E  length " + was + " -> " + want);
    }
}

// verify
Log("");
int na = 0, pct = 0, len = 0;
foreach (ObjectId id in ms) {
    var mt = Tx.GetObject(id, OpenMode.ForRead) as MText;
    if (mt == null || mt.Layer != "SEWER_LINE_TEXT") continue;
    string c = mt.Contents.Trim();
    if (c == "N/A") na++; else if (c.IndexOf('%') >= 0) pct++; else len++;
}
Log("SEWER_LINE_TEXT now: " + len + " length, " + pct + " slope, " + na + " N/A (verified)");
Ed.Regen();

Result

Status
success
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\260613 - 5030 E Lake Pkwy, Stockbridge, GA 30281, USA\260612 - CSTORE WATER ABS 30.dwg
Message
Executed C3D-0076 (0 entities touched).
Entities
Duration
793 ms
Civil 3D
25.0.0.0

Log

  [2EF5E] restored slope label  133.21' -> N/A
  [2EF5F] restored slope label  55.14' -> N/A
  2EC8E length already 359.02'

SEWER_LINE_TEXT now: 14 length, 11 slope, 2 N/A (verified)

Notes

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

No notes yet.