← Inbox

C3D-LEGEND2 · Rebuild legend as a proper table done

4-row grid table: Outfall SSMH (blue circle), SSMH bolted (gray filled), Outfall sewer (green line), 40' easement (cyan line, SAME continuous linetype as sewer). Nothing else touched.

Script file
C3D-LEGEND2.cs
Target
SS_Outfall_260612_SHEET.dwg · model space
Author
claude
Approved
yes · auto-auth
Timeout
60s

C# payload

// Rebuild the LEGEND as a clean table (grid + rows), replacing the deleted one.
// Row symbols match the real layer styles: Outfall SSMH (blue open circle), SSMH bolted (gray filled
// donut), Outfall sewer (green continuous line, matches SEWER_LINE), 40' Sanitary Sewer Easement
// (cyan continuous line, matches SEWER_EASEMENT — same linetype as the sewer line, just color-coded).
// Ambient Tx/ModelSpace globals only.
using System;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Colors;

EnsureLayer("LEGEND", 7);

double ox = 2297500, oy = 1279300;   // draft anchor — same area as before
double rowH = 8, colSymW = 20, colTxtW = 70;
double boxW = colSymW + colTxtW;
int rows = 4;
double boxH = rowH * (rows + 1); // +1 header row

void GridLine(Point3d a, Point3d b)
{
    AddLine(a, b, "LEGEND");
}

// outer box
GridLine(new Point3d(ox, oy, 0), new Point3d(ox+boxW, oy, 0));
GridLine(new Point3d(ox+boxW, oy, 0), new Point3d(ox+boxW, oy+boxH, 0));
GridLine(new Point3d(ox+boxW, oy+boxH, 0), new Point3d(ox, oy+boxH, 0));
GridLine(new Point3d(ox, oy+boxH, 0), new Point3d(ox, oy, 0));

// header divider (under "LEGEND" title row)
GridLine(new Point3d(ox, oy+boxH-rowH, 0), new Point3d(ox+boxW, oy+boxH-rowH, 0));
// column divider (symbol | text), only through the data rows
GridLine(new Point3d(ox+colSymW, oy, 0), new Point3d(ox+colSymW, oy+boxH-rowH, 0));
// row dividers between the 4 data rows
for (int i = 1; i < rows; i++)
{
    double y = oy + rowH * i;
    GridLine(new Point3d(ox, y, 0), new Point3d(ox+boxW, y, 0));
}

AddMText(new Point3d(ox+4, oy+boxH-rowH*0.5-2, 0), "LEGEND", 5, 0, "LEGEND");

double R = 2.0; // legend symbol radius — draft, matches sheet scale roughly
double symX = ox + colSymW/2.0;

// row 4 (top data row): Outfall SSMH
double y4 = oy + rowH*3 + rowH/2.0;
{
    var c = new Circle(new Point3d(symX, y4, 0), Vector3d.ZAxis, R);
    c.Layer = "LEGEND"; c.Color = Color.FromColorIndex(ColorMethod.ByAci, 5);
    ModelSpace.AppendEntity(c); Tx.AddNewlyCreatedDBObject(c, true);
}
AddMText(new Point3d(ox+colSymW+2, y4-1.5, 0), "Outfall SSMH (rim / invert)", 3.5, 0, "LEGEND");

// row 3: SSMH bolted
double y3 = oy + rowH*2 + rowH/2.0;
{
    var c = new Circle(new Point3d(symX, y3, 0), Vector3d.ZAxis, R);
    c.Layer = "LEGEND"; c.Color = Color.FromColorIndex(ColorMethod.ByAci, 8);
    ModelSpace.AppendEntity(c); Tx.AddNewlyCreatedDBObject(c, true);
    var donut = new Polyline();
    donut.AddVertexAt(0, new Point2d(symX - R, y3), 1.0, R, R);
    donut.AddVertexAt(1, new Point2d(symX + R, y3), 1.0, R, R);
    donut.Closed = true; donut.Layer = "LEGEND";
    donut.Color = Color.FromColorIndex(ColorMethod.ByAci, 8);
    ModelSpace.AppendEntity(donut); Tx.AddNewlyCreatedDBObject(donut, true);
}
AddMText(new Point3d(ox+colSymW+2, y3-1.5, 0), "SSMH bolted (no invert)", 3.5, 0, "LEGEND");

// row 2: Outfall sewer — continuous, matches SEWER_LINE color (green/3)
double y2 = oy + rowH*1 + rowH/2.0;
{
    var l = new Line(new Point3d(ox+2, y2, 0), new Point3d(ox+colSymW-2, y2, 0));
    l.Layer = "LEGEND"; l.Color = Color.FromColorIndex(ColorMethod.ByAci, 3);
    ModelSpace.AppendEntity(l); Tx.AddNewlyCreatedDBObject(l, true);
}
AddMText(new Point3d(ox+colSymW+2, y2-1.5, 0), "Outfall sewer", 3.5, 0, "LEGEND");

// row 1: 40' Sanitary Sewer Easement — SAME continuous linetype as sewer line, cyan (matches SEWER_EASEMENT)
double y1 = oy + rowH*0 + rowH/2.0;
{
    var l = new Line(new Point3d(ox+2, y1, 0), new Point3d(ox+colSymW-2, y1, 0));
    l.Layer = "LEGEND"; l.Color = Color.FromColorIndex(ColorMethod.ByAci, 4);
    ModelSpace.AppendEntity(l); Tx.AddNewlyCreatedDBObject(l, true);
}
AddMText(new Point3d(ox+colSymW+2, y1-1.5, 0), "40' Sanitary Sewer Easement", 3.5, 0, "LEGEND");

Log($"legend table rebuilt at ({ox},{oy}), size {boxW}x{boxH}. Both line samples continuous (matches SEWER_LINE/SEWER_EASEMENT linetype), color-coded green/cyan.");
Log("DONE.");

Result

Status
success
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\260613 - 5030 E Lake Pkwy, Stockbridge, GA 30281, USA\SS_Outfall_260612_SHEET.dwg
Message
Executed C3D-LEGEND2 (14 entities touched).
Entities
1838, 1839, 183A, 183B, 183C, 183D, 183E, 183F, 1840, 1841, 1843, 1846, 1848, 184A
Duration
381 ms
Civil 3D
25.0.0.0

Log

legend table rebuilt at (2297500,1279300), size 90x40. Both line samples continuous (matches SEWER_LINE/SEWER_EASEMENT linetype), color-coded green/cyan.
DONE.

Notes

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

No notes yet.