← Inbox

C3D-0031 · Length label on each sewer line [SEW-LEN] done

Adds a length label to each of the 14 sewer lines on SEWER_LINE_TEXT, at the midpoint, rotated to the line and offset to the upper side. Lengths read from the geometry.

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

C# payload

// Length label on every sewer line -> SEWER_LINE_TEXT.
//
// HCWA: text describing a sewer line goes on SEWER_LINE_TEXT, never on SEWER_LINE itself.
// One label per line, showing the length to 2dp, placed at the midpoint, rotated to the line
// and nudged 2.0ft to the upper side so it sits just off the pipe. Rotation is flipped 180
// where it would otherwise read upside-down.
// Lengths are the lines' own measured lengths read from the drawing, not from any table.
// 14 lines, 1448.33 ft total.
//
// Host owns Tx; host regens after commit.
const string LAYER = "SEWER_LINE_TEXT";
const double H = 3.0;

var ms = (BlockTableRecord)Tx.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(Db), OpenMode.ForWrite);
EnsureLayer(LAYER, 3);

    {
        var mt = new MText {
            Location   = new Point3d(2296649.980, 1280052.074, 0.0),
            Contents   = @"12.07'",
            TextHeight = H,
            Rotation   = -4.714212,
            Attachment = AttachmentPoint.BottomCenter,
        };
        mt.Layer = LAYER;
        ms.AppendEntity(mt);
        Tx.AddNewlyCreatedDBObject(mt, true);
        Log("  line 2E95F  12.07 ft");
    }
    {
        var mt = new MText {
            Location   = new Point3d(2296445.580, 1279954.487, 0.0),
            Contents   = @"131.42'",
            TextHeight = H,
            Rotation   = -0.015789,
            Attachment = AttachmentPoint.BottomCenter,
        };
        mt.Layer = LAYER;
        ms.AppendEntity(mt);
        Tx.AddNewlyCreatedDBObject(mt, true);
        Log("  line 2EC86  131.42 ft");
    }
    {
        var mt = new MText {
            Location   = new Point3d(2296556.525, 1280000.230, 0.0),
            Contents   = @"133.04'",
            TextHeight = H,
            Rotation   = 0.792605,
            Attachment = AttachmentPoint.BottomCenter,
        };
        mt.Layer = LAYER;
        ms.AppendEntity(mt);
        Tx.AddNewlyCreatedDBObject(mt, true);
        Log("  line 2EC87  133.04 ft");
    }
    {
        var mt = new MText {
            Location   = new Point3d(2296577.530, 1280051.474, 0.0),
            Contents   = @"55.11'",
            TextHeight = H,
            Rotation   = -0.119565,
            Attachment = AttachmentPoint.BottomCenter,
        };
        mt.Layer = LAYER;
        ms.AppendEntity(mt);
        Tx.AddNewlyCreatedDBObject(mt, true);
        Log("  line 2EC88  55.11 ft");
    }
    {
        var mt = new MText {
            Location   = new Point3d(2296647.808, 1280048.051, 0.0),
            Contents   = @"86.31'",
            TextHeight = H,
            Rotation   = -0.003487,
            Attachment = AttachmentPoint.BottomCenter,
        };
        mt.Layer = LAYER;
        ms.AppendEntity(mt);
        Tx.AddNewlyCreatedDBObject(mt, true);
        Log("  line 2EC89  86.31 ft");
    }
    {
        var mt = new MText {
            Location   = new Point3d(2296703.842, 1280037.092, 0.0),
            Contents   = @"30.96'",
            TextHeight = H,
            Rotation   = -0.728088,
            Attachment = AttachmentPoint.BottomCenter,
        };
        mt.Layer = LAYER;
        ms.AppendEntity(mt);
        Tx.AddNewlyCreatedDBObject(mt, true);
        Log("  line 2EC8A  30.96 ft");
    }
    {
        var mt = new MText {
            Location   = new Point3d(2296769.598, 1280062.342, 0.0),
            Contents   = @"133.45'",
            TextHeight = H,
            Rotation   = 0.558332,
            Attachment = AttachmentPoint.BottomCenter,
        };
        mt.Layer = LAYER;
        ms.AppendEntity(mt);
        Tx.AddNewlyCreatedDBObject(mt, true);
        Log("  line 2EC8B  133.45 ft");
    }
    {
        var mt = new MText {
            Location   = new Point3d(2296854.507, 1280066.385, 0.0),
            Contents   = @"80.39'",
            TextHeight = H,
            Rotation   = -0.876410,
            Attachment = AttachmentPoint.BottomCenter,
        };
        mt.Layer = LAYER;
        ms.AppendEntity(mt);
        Tx.AddNewlyCreatedDBObject(mt, true);
        Log("  line 2EC8C  80.39 ft");
    }
    {
        var mt = new MText {
            Location   = new Point3d(2296931.107, 1279974.545, 0.0),
            Contents   = @"158.80'",
            TextHeight = H,
            Rotation   = -0.875236,
            Attachment = AttachmentPoint.BottomCenter,
        };
        mt.Layer = LAYER;
        ms.AppendEntity(mt);
        Tx.AddNewlyCreatedDBObject(mt, true);
        Log("  line 2EC8D  158.80 ft");
    }
    {
        var mt = new MText {
            Location   = new Point3d(2297116.512, 1279795.277, 0.0),
            Contents   = @"358.92'",
            TextHeight = H,
            Rotation   = -0.721503,
            Attachment = AttachmentPoint.BottomCenter,
        };
        mt.Layer = LAYER;
        ms.AppendEntity(mt);
        Tx.AddNewlyCreatedDBObject(mt, true);
        Log("  line 2EC8E  358.92 ft");
    }
    {
        var mt = new MText {
            Location   = new Point3d(2297261.424, 1279636.961, 0.0),
            Contents   = @"79.84'",
            TextHeight = H,
            Rotation   = -1.329162,
            Attachment = AttachmentPoint.BottomCenter,
        };
        mt.Layer = LAYER;
        ms.AppendEntity(mt);
        Tx.AddNewlyCreatedDBObject(mt, true);
        Log("  line 2EC8F  79.84 ft");
    }
    {
        var mt = new MText {
            Location   = new Point3d(2297345.727, 1279610.232, 0.0),
            Contents   = @"155.36'",
            TextHeight = H,
            Rotation   = 0.135922,
            Attachment = AttachmentPoint.BottomCenter,
        };
        mt.Layer = LAYER;
        ms.AppendEntity(mt);
        Tx.AddNewlyCreatedDBObject(mt, true);
        Log("  line 2EC90  155.36 ft");
    }
    {
        var mt = new MText {
            Location   = new Point3d(2297425.827, 1279609.228, 0.0),
            Contents   = @"19.53'",
            TextHeight = H,
            Rotation   = -1.481337,
            Attachment = AttachmentPoint.BottomCenter,
        };
        mt.Layer = LAYER;
        ms.AppendEntity(mt);
        Tx.AddNewlyCreatedDBObject(mt, true);
        Log("  line 2EC91  19.53 ft");
    }
    {
        var mt = new MText {
            Location   = new Point3d(2296689.563, 1280050.461, 0.0),
            Contents   = @"8.66'",
            TextHeight = H,
            Rotation   = -0.841381,
            Attachment = AttachmentPoint.BottomCenter,
        };
        mt.Layer = LAYER;
        ms.AppendEntity(mt);
        Tx.AddNewlyCreatedDBObject(mt, true);
        Log("  line 2EC92  8.66 ft");
    }

int n = 0;
foreach (ObjectId id in ms) {
    var e = Tx.GetObject(id, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Entity;
    if (e != null && e.Layer == LAYER && e is MText) n++;
}
Log("SEWER_LINE_TEXT now holds " + n + " length label(s) (verified)");

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-0031 (0 entities touched).
Entities
Duration
444 ms
Civil 3D
25.0.0.0

Log

  line 2E95F  12.07 ft
  line 2EC86  131.42 ft
  line 2EC87  133.04 ft
  line 2EC88  55.11 ft
  line 2EC89  86.31 ft
  line 2EC8A  30.96 ft
  line 2EC8B  133.45 ft
  line 2EC8C  80.39 ft
  line 2EC8D  158.80 ft
  line 2EC8E  358.92 ft
  line 2EC8F  79.84 ft
  line 2EC90  155.36 ft
  line 2EC91  19.53 ft
  line 2EC92  8.66 ft
SEWER_LINE_TEXT now holds 14 length label(s) (verified)

Notes

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

No notes yet.