← Inbox

C3D-0315 · 260714 Huckaby: power line linetype to match the recorded plat running

Creates a POWER_LINE linetype - dashed with a repeating W glyph, ----W----W---- - matching Book 32 Page 175, built the same way the drawings existing GAS_LINE pattern is (3-dash linetype whose middle element carries text). Assigns it to layer SS-V-TRANSMISSION CENTER LINE and sets the 4 transmission lines to ByLayer at scale 1.0 (LTSCALE is 40). Verifies the linetype dashes, the layer assignment and each entity on read-back.

Script file
C3D-0315.cs
Target
260714 - 285 Huckaby Rd R142.dwg · model space
Author
claude
Approved
yes · auto-auth
Timeout
60s

C# payload

// Make the transmission lines read like the recorded plat (Book 32 Page 175): a dashed line with
// a repeating W glyph -  ----W----W----W----
//
// The drawing has GAS_LINE (----GAS----GAS----) which is exactly this pattern with different
// text, so the same construction works: a 3-dash linetype where the middle "dash" is a shape/text
// element carrying the letter.
//
// Built with LinetypeTableRecord: dash 0 = the line segment, dash 1 = the embedded text (length 0,
// with a style + offset + scale), dash 2 = the gap. This is the documented way to make a
// text-bearing linetype in the .NET API - no .lin file needed.
//
// Sizing: LTSCALE is 40, so pattern lengths here are in drawing units BEFORE that multiplier.
// A 0.5 unit dash x 40 = 20 ft on the ground, which matches the plat's spacing at 1"=100'.
const string LTNAME = "POWER_LINE";
const string LAYER  = "SS-V-TRANSMISSION CENTER LINE";

Log("drawing: " + Db.Filename);

// ---- a text style for the glyph (reuse an existing simple one)
var tst = (TextStyleTable)Tx.GetObject(Db.TextStyleTableId, OpenMode.ForRead);
ObjectId styleId = tst.Has("Standard") ? tst["Standard"] : Db.Textstyle;
Log("glyph style: " + ((TextStyleTableRecord)Tx.GetObject(styleId, OpenMode.ForRead)).Name);

// ---- create (or rebuild) the linetype
var ltt = (LinetypeTable)Tx.GetObject(Db.LinetypeTableId, OpenMode.ForWrite);
ObjectId ltId;
if (ltt.Has(LTNAME)) {
    ltId = ltt[LTNAME];
    Log("linetype " + LTNAME + " already present - reusing");
} else {
    var rec = new LinetypeTableRecord();
    rec.Name = LTNAME;
    rec.Comments = "Power line ----W----W----W----W----";
    rec.PatternLength = 0.9;
    rec.NumDashes = 3;

    // 0: the drawn segment
    rec.SetDashLengthAt(0, 0.5);

    // 1: the W glyph - zero-length text element
    rec.SetDashLengthAt(1, -0.2);
    rec.SetShapeStyleAt(1, styleId);
    rec.SetShapeNumberAt(1, 0);
    rec.SetTextAt(1, "W");
    rec.SetShapeScaleAt(1, 0.2);
    rec.SetShapeOffsetAt(1, new Vector2d(-0.1, -0.1));
    rec.SetShapeRotationAt(1, 0.0);
    rec.SetShapeIsUcsOrientedAt(1, false);

    // 2: the gap after the glyph
    rec.SetDashLengthAt(2, -0.2);

    ltId = ltt.Add(rec);
    Tx.AddNewlyCreatedDBObject(rec, true);
    Log("created linetype " + LTNAME);
}

// ---- verify the linetype came out as intended
{
    var r = (LinetypeTableRecord)Tx.GetObject(ltId, OpenMode.ForRead);
    Log(string.Format("  {0}: dashes={1} patternLength={2:F3} \"{3}\"", r.Name, r.NumDashes, r.PatternLength, r.Comments));
    for (int i = 0; i < r.NumDashes; i++) {
        string txt = "";
        try { txt = r.TextAt(i); } catch { }
        Log(string.Format("     dash{0} len={1,6:F3} text=\"{2}\"", i, r.DashLengthAt(i), txt));
    }
}

// ---- put the layer on it so everything on that layer picks it up
var lt = (LayerTable)Tx.GetObject(Db.LayerTableId, OpenMode.ForRead);
if (!lt.Has(LAYER)) { Log("layer missing: " + LAYER); return; }
var ltr = (LayerTableRecord)Tx.GetObject(lt[LAYER], OpenMode.ForWrite);
ltr.LinetypeObjectId = ltId;
{
    var back = (LayerTableRecord)Tx.GetObject(lt[LAYER], OpenMode.ForRead);
    var used = (LinetypeTableRecord)Tx.GetObject(back.LinetypeObjectId, OpenMode.ForRead);
    Log("layer " + back.Name + " linetype -> " + used.Name + " (verified)");
}

// ---- make sure each transmission line is ByLayer, and give it a scale that reads at 1"=100'
var ms = (BlockTableRecord)Tx.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(Db), OpenMode.ForWrite);
int n = 0;
foreach (ObjectId id in ms) {
    var ent = Tx.GetObject(id, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Entity;
    if (ent == null || !ent.Layer.Equals(LAYER, StringComparison.OrdinalIgnoreCase)) continue;
    var w = (Autodesk.AutoCAD.DatabaseServices.Entity)Tx.GetObject(id, OpenMode.ForWrite);
    w.LinetypeId = Db.ByLayerLinetype;
    w.LinetypeScale = 1.0;
    n++;
    var back = (Autodesk.AutoCAD.DatabaseServices.Entity)Tx.GetObject(id, OpenMode.ForRead);
    var bl = (LinetypeTableRecord)Tx.GetObject(back.LinetypeId, OpenMode.ForRead);
    Log(string.Format("  [{0}] ltype={1} ltscale={2:F2} (verified)", back.Handle, bl.Name, back.LinetypeScale));
}
Log("");
Log(string.Format("linetype {0} applied via layer {1}; {2} entities set ByLayer. LTSCALE={3}",
    LTNAME, LAYER, n, Db.Ltscale));
Ed.Regen();

Notes

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

No notes yet.