← Inbox

C3D-0129 · Fix the duplicate DWY polyline and the repeated vertex [LW-FIX] done

Erases 20AE1 on X-DRIV-CONC, an exact duplicate created when a post timed out locally after the ticket had already run, and removes the repeated consecutive vertex from 20ADC on SS-V-ROAD-CURB. Both targeted by handle and type-checked before being touched, then the whole linework set is re-verified.

Script file
C3D-0129.cs
Target
active document · model space
Author
claude
Approved
yes · reviewer
Timeout
180s

C# payload

// Fix two defects in the linework I just drew:
//   1. 20AE1 on X-DRIV-CONC is an exact duplicate of 20AE0 - the DWY ticket ran twice when a
//      post timed out locally after it had already been created and approved. Erase 20AE1.
//   2. 20ADC on SS-V-ROAD-CURB has a duplicate consecutive vertex (point 275 repeated) from my
//      chunk-overlap when splitting at the 12-vertex cap. Remove the repeated vertex.
// Both targeted by handle and verified before being touched.
var ms = (BlockTableRecord)Tx.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(Db), OpenMode.ForRead);
Log("drawing: " + Db.Filename);

Func<string, ObjectId> find = h => {
    foreach (ObjectId id in ms) {
        Autodesk.AutoCAD.DatabaseServices.DBObject o;
        try { o = Tx.GetObject(id, OpenMode.ForRead); } catch { continue; }
        if (o.Handle.ToString() == h) return id;
    }
    return ObjectId.Null;
};

// (1) erase the duplicate DWY polyline
var dupId = find("20AE1");
if (dupId.IsNull) Log("20AE1 not found - nothing to erase");
else {
    var pl = Tx.GetObject(dupId, OpenMode.ForRead) as Polyline;
    if (pl == null || pl.Layer != "X-DRIV-CONC") Log("ABORT(1): 20AE1 is not a Polyline on X-DRIV-CONC");
    else {
        Log(String.Format("erasing duplicate [20AE1] verts={0} len={1:F2}", pl.NumberOfVertices, pl.Length));
        Tx.GetObject(dupId, OpenMode.ForWrite).Erase();
    }
}

// (2) strip the repeated vertex
var badId = find("20ADC");
if (badId.IsNull) Log("20ADC not found");
else {
    var pl = Tx.GetObject(badId, OpenMode.ForRead) as Polyline;
    if (pl == null || pl.Layer != "SS-V-ROAD-CURB") Log("ABORT(2): 20ADC is not a Polyline on SS-V-ROAD-CURB");
    else {
        int removed = 0;
        var w = (Polyline)Tx.GetObject(badId, OpenMode.ForWrite);
        for (int i = w.NumberOfVertices - 1; i > 0; i--) {
            var a = w.GetPoint2dAt(i - 1); var b = w.GetPoint2dAt(i);
            if (Math.Abs(a.X - b.X) < 0.001 && Math.Abs(a.Y - b.Y) < 0.001) { w.RemoveVertexAt(i); removed++; }
        }
        Log(String.Format("[20ADC] removed {0} duplicate vertex/vertices -> verts={1} len={2:F2}",
            removed, w.NumberOfVertices, w.Length));
    }
}

// verify
Log("");
var seen = new Dictionary<string,int>();
int dupVerts = 0, total = 0;
string[] LAYERS = { "SS-V-ROAD-CURB", "SS-V-ROAD-CNTR", "V-STRC-WALL", "X-DRIV-CONC", "SS-V-ROAD-EPVM" };
var want = new HashSet<string>(LAYERS);
foreach (ObjectId id in ms) {
    var pl = Tx.GetObject(id, OpenMode.ForRead) as Polyline;
    if (pl == null || pl.IsErased || !want.Contains(pl.Layer)) continue;
    total++;
    var key = new System.Text.StringBuilder(pl.Layer + "|");
    for (int i = 0; i < pl.NumberOfVertices; i++) {
        var v = pl.GetPoint2dAt(i);
        key.Append(String.Format("{0:F2},{1:F2};", v.X, v.Y));
        if (i > 0) { var u = pl.GetPoint2dAt(i-1);
            if (Math.Abs(u.X-v.X) < 0.001 && Math.Abs(u.Y-v.Y) < 0.001) dupVerts++; }
    }
    string k = key.ToString();
    if (!seen.ContainsKey(k)) seen[k] = 0;
    seen[k]++;
}
int dupPolys = 0;
foreach (var kv in seen) if (kv.Value > 1) dupPolys++;
Log("polylines=" + total + "  identical duplicates=" + dupPolys + "  duplicate vertices=" + dupVerts + " (verified)");
Ed.Regen();

Result

Status
success
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\260802 - 4082 Sweetbriar Ln, Forest Park, GA 30297, USA\260802 - 4082 Sweetbriar Ln.dwg
Message
Executed C3D-0129 (0 entities touched).
Entities
Duration
511 ms
Civil 3D
25.0.0.0

Log

drawing: C:\Users\sanja\OneDrive\_SurveyDisco\260802 - 4082 Sweetbriar Ln, Forest Park, GA 30297, USA\260802 - 4082 Sweetbriar Ln.dwg
erasing duplicate [20AE1] verts=5 len=54.09
[20ADC] removed 1 duplicate vertex/vertices -> verts=8 len=46.36

polylines=15  identical duplicates=0  duplicate vertices=0 (verified)

Notes

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

No notes yet.