← Inbox

C3D-MHOLSYM2 · Place manhole symbols (14) + legend v2 error

Same as C3D-MHOLSYM but replaces the crashing Hatch with a wide-polyline donut for the filled bolted symbol. 13 blue open circles (outfall) + 1 gray filled (bolted #7013) + 4-row legend.

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

C# payload

// Place manhole symbols at the 14 SSMH points (7000-7013) + a legend block.
// #7013 = SSMH bolted (gray filled circle) on SEWER_MANHOLE_EXISTING.
// #7000-7012 = Outfall SSMH (blue open circle) on SEWER_MANHOLE.
// Circle radius chosen small (real-world feet); adjust later if too big/small on the sheet.
// Legend: 4-row box (Outfall SSMH, SSMH bolted, Outfall sewer line sample, 40' easement sample).
using System;
using System.Collections.Generic;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Colors;
using Autodesk.Civil.ApplicationServices;
using Autodesk.Civil.DatabaseServices;

var db = Db;
const double R = 1.0; // circle radius, feet — draft, adjustable
int bolted=0, outfall=0;

using (var tr = db.TransactionManager.StartTransaction())
{
    var ms = (BlockTableRecord)tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForWrite);
    var cdoc = CivilDocument.GetCivilDocument(db);
    foreach (ObjectId id in cdoc.CogoPoints)
    {
        var cp = tr.GetObject(id, OpenMode.ForRead) as CogoPoint;
        if (cp == null) continue;
        int n = (int)cp.PointNumber;
        if (n < 7000 || n > 7013) continue;

        var center = new Point3d(cp.Easting, cp.Northing, 0);
        var circ = new Circle(center, Vector3d.ZAxis, R);

        if (n == 7013)
        {
            circ.Layer = "SEWER_MANHOLE_EXISTING";
            circ.Color = Color.FromColorIndex(ColorMethod.ByAci, 8); // gray
            ms.AppendEntity(circ); tr.AddNewlyCreatedDBObject(circ, true);
            // filled look via a donut (wide polyline ring) instead of Hatch — simpler, reliable
            var donut = new Polyline();
            donut.AddVertexAt(0, new Point2d(center.X - R, center.Y), R, R, 0);
            donut.AddVertexAt(1, new Point2d(center.X + R, center.Y), R, R, 0);
            donut.Closed = true;
            donut.ConstantWidth = R; // ring width = radius -> reads as filled disc
            donut.Layer = "SEWER_MANHOLE_EXISTING";
            donut.Color = Color.FromColorIndex(ColorMethod.ByAci, 8);
            ms.AppendEntity(donut); tr.AddNewlyCreatedDBObject(donut, true);
            bolted++;
        }
        else
        {
            circ.Layer = "SEWER_MANHOLE";
            circ.Color = Color.FromColorIndex(ColorMethod.ByAci, 5); // blue, open (no fill)
            ms.AppendEntity(circ); tr.AddNewlyCreatedDBObject(circ, true);
            outfall++;
        }
    }
    tr.Commit();
}
Log($"placed manhole symbols: outfall(blue open)={outfall}, bolted(gray filled)={bolted}");

// legend block — simple box with 4 sample rows, placed at a fixed offset from drawing extents
using (var tr = db.TransactionManager.StartTransaction())
{
    var ms = (BlockTableRecord)tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForWrite);
    // anchor near the first outfall point found, offset so it doesn't overlap the drawing
    double ox = 2297500, oy = 1279300; // draft placement; user can move
    double rowH = 8, boxW = 90;

    EnsureLayer("LEGEND", 7);
    void Txt(string s, Point3d p, double h) { AddMText(p, s, h, 0, "LEGEND"); }

    // box outline
    var pl = new Polyline();
    pl.AddVertexAt(0, new Point2d(ox, oy), 0,0,0);
    pl.AddVertexAt(1, new Point2d(ox+boxW, oy), 0,0,0);
    pl.AddVertexAt(2, new Point2d(ox+boxW, oy+rowH*5), 0,0,0);
    pl.AddVertexAt(3, new Point2d(ox, oy+rowH*5), 0,0,0);
    pl.Closed = true; pl.Layer = "LEGEND";
    ms.AppendEntity(pl); tr.AddNewlyCreatedDBObject(pl, true);

    Txt("LEGEND", new Point3d(ox+4, oy+rowH*4.5, 0), 5);

    // row 1: outfall SSMH (blue open circle)
    var c1 = new Circle(new Point3d(ox+8, oy+rowH*3.5, 0), Vector3d.ZAxis, R);
    c1.Layer="LEGEND"; c1.Color=Color.FromColorIndex(ColorMethod.ByAci,5);
    ms.AppendEntity(c1); tr.AddNewlyCreatedDBObject(c1, true);
    Txt("Outfall SSMH (rim / invert)", new Point3d(ox+16, oy+rowH*3.5-1.5, 0), 3.5);

    // row 2: bolted SSMH (gray filled circle) — donut ring instead of Hatch
    var legendCenter2 = new Point2d(ox+8, oy+rowH*2.5);
    var d2 = new Polyline();
    d2.AddVertexAt(0, new Point2d(legendCenter2.X - R, legendCenter2.Y), R, R, 0);
    d2.AddVertexAt(1, new Point2d(legendCenter2.X + R, legendCenter2.Y), R, R, 0);
    d2.Closed = true; d2.ConstantWidth = R;
    d2.Layer="LEGEND"; d2.Color=Color.FromColorIndex(ColorMethod.ByAci,8);
    ms.AppendEntity(d2); tr.AddNewlyCreatedDBObject(d2, true);
    Txt("SSMH bolted (no invert)", new Point3d(ox+16, oy+rowH*2.5-1.5, 0), 3.5);

    // row 3: outfall sewer line sample (red)
    var l3 = new Line(new Point3d(ox+4, oy+rowH*1.5, 0), new Point3d(ox+12, oy+rowH*1.5, 0));
    l3.Layer="LEGEND"; l3.Color=Color.FromColorIndex(ColorMethod.ByAci,1); l3.LineWeight=LineWeight.LineWeight035;
    ms.AppendEntity(l3); tr.AddNewlyCreatedDBObject(l3, true);
    Txt("Outfall sewer", new Point3d(ox+16, oy+rowH*1.5-1.5, 0), 3.5);

    // row 4: 40' sanitary sewer easement sample (dashed cyan)
    var l4 = new Line(new Point3d(ox+4, oy+rowH*0.5, 0), new Point3d(ox+12, oy+rowH*0.5, 0));
    l4.Layer="LEGEND"; l4.Color=Color.FromColorIndex(ColorMethod.ByAci,4);
    ms.AppendEntity(l4); tr.AddNewlyCreatedDBObject(l4, true);
    Txt("40' Sanitary Sewer Easement", new Point3d(ox+16, oy+rowH*0.5-1.5, 0), 3.5);

    tr.Commit();
}
Log("legend placed near (2297500,1279300) — DRAFT position, move as needed.");
Log("DONE.");

Result

Status
error
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\260613 - 5030 E Lake Pkwy, Stockbridge, GA 30281, USA\SS_Outfall_260612_SHEET.dwg
Message
Operation is not valid due to the current state of the object.
Entities
Duration
390 ms
Civil 3D
25.0.0.0

Log

placed manhole symbols: outfall(blue open)=13, bolted(gray filled)=1

Notes

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

No notes yet.