← Inbox

C3D-PIPETYPE · Add pipe types under grade labels done

6 pipe-type texts 7ft under their distance/grade labels: 60' PVC/20' DIP, 60' DIP/100' PVC, PVC, DIP, PVC, PVC. Same style, horizontal.

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

C# payload

// Add pipe-type text UNDER each distance/grade label (7' below, same style/height, horizontal).
// Matched by the grade label's exact text on SEWER_LINE_TEXT. Idempotent.
using System;
using System.Collections.Generic;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;

var types = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
    ["80' 15.8%"] = "60' PVC / 20' DIP",
    ["159' 12.4%"] = "60' DIP / 100' PVC",
    ["359' 1.1%"] = "PVC",
    ["80' 0.6%"] = "DIP",
    ["155' 0.7%"] = "PVC",
    ["20' 0.8%"] = "PVC",
};

// existing text on the layer (for idempotency by position + finding the grade labels)
var labels = new List<DBText>();
var positions = new List<Point3d>();
foreach (ObjectId id in ModelSpace)
{
    var e = Tx.GetObject(id, OpenMode.ForRead);
    if (e is DBText t && string.Equals(t.Layer, "SEWER_LINE_TEXT", StringComparison.OrdinalIgnoreCase))
    {
        labels.Add(t);
        positions.Add(t.Position);
    }
}

int added = 0;
foreach (var t in labels)
{
    if (!types.TryGetValue(t.TextString, out var pipeType)) continue;
    var target = new Point3d(t.Position.X, t.Position.Y - 7.0, t.Position.Z);
    bool occupied = false;
    foreach (var p in positions) if (p.DistanceTo(target) < 1.0) { occupied = true; break; }
    if (occupied) { Log($"  skip under '{t.TextString}' (text already there)"); continue; }

    var clone = (DBText)t.Clone();
    clone.TextString = pipeType;
    clone.Position = target;
    if (clone.Justify != AttachmentPoint.BaseLeft)
        clone.AlignmentPoint = new Point3d(t.AlignmentPoint.X, t.AlignmentPoint.Y - 7.0, t.AlignmentPoint.Z);
    clone.Rotation = 0;
    ModelSpace.AppendEntity(clone);
    Tx.AddNewlyCreatedDBObject(clone, true);
    positions.Add(target);
    Log($"  + '{pipeType}' under '{t.TextString}'");
    added++;
}
Log($"DONE. {added} pipe-type labels added on SEWER_LINE_TEXT.");

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

Log

  + '60' PVC / 20' DIP' under '80' 15.8%'
  + '60' DIP / 100' PVC' under '159' 12.4%'
  + 'PVC' under '359' 1.1%'
  + 'DIP' under '80' 0.6%'
  + 'PVC' under '155' 0.7%'
  + 'PVC' under '20' 0.8%'
DONE. 6 pipe-type labels added on SEWER_LINE_TEXT.

Notes

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

No notes yet.