← Inbox

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

Circle at each SSMH point 7000-7013 (blue open=outfall, gray filled=bolted #7013 only), plus a 4-row legend box. C3D layers per HCWA std.

Script file
C3D-MHOLSYM.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);
            var hatch = new Hatch();
            ms.AppendEntity(hatch); tr.AddNewlyCreatedDBObject(hatch, true);
            hatch.Layer = "SEWER_MANHOLE_EXISTING";
            hatch.Color = Color.FromColorIndex(ColorMethod.ByAci, 8);
            hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID");
            var loop = new ObjectIdCollection(new ObjectId[]{ circ.ObjectId });
            hatch.AppendLoop(HatchLoopTypes.Default, loop);
            hatch.EvaluateHatch(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)
    var c2 = new Circle(new Point3d(ox+8, oy+rowH*2.5, 0), Vector3d.ZAxis, R);
    c2.Layer="LEGEND"; c2.Color=Color.FromColorIndex(ColorMethod.ByAci,8);
    ms.AppendEntity(c2); tr.AddNewlyCreatedDBObject(c2, true);
    var h2 = new Hatch(); ms.AppendEntity(h2); tr.AddNewlyCreatedDBObject(h2, true);
    h2.Layer="LEGEND"; h2.Color=Color.FromColorIndex(ColorMethod.ByAci,8);
    h2.SetHatchPattern(HatchPatternType.PreDefined, "SOLID");
    h2.AppendLoop(HatchLoopTypes.Default, new ObjectIdCollection(new ObjectId[]{ c2.ObjectId }));
    h2.EvaluateHatch(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
418 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.