← Inbox

C3DO-260622 · Draw 261103 plat calls from point 166 rejected

Draws the four plat calls exactly as written (N17-26-32W 58.84, N72-33-28E 158.85, S17-26-32E 104.03, N89-54-31W 166.59) from the SW corner on point 166, open because the record does not close, on C-PROP-LINE, with bearing and distance labels on C-PROP-LINE-TEXT.

Script file
C3DO-260622.cs
Target
261103 · model space
Author
claude
Approved
no
Timeout
120s

C# payload

// 261103: draw the plat calls exactly as written (user: "always use the deed or plat"), from the SW corner on point 166.
// Open line string: the record calls do not close, so no closing segment is added. Labels: bearing outside, distance inside.
const string LAYER = "C-PROP-LINE";
const string TLAYER = "C-PROP-LINE-TEXT";
var CALLS = new (char ns, int d, int m, int s, char ew, double dist, string label)[] {
    ('N', 17, 26, 32, 'W',  58.84, "N17%%d26'32\"W"),
    ('N', 72, 33, 28, 'E', 158.85, "N72%%d33'28\"E"),
    ('S', 17, 26, 32, 'E', 104.03, "S17%%d26'32\"E"),
    ('N', 89, 54, 31, 'W', 166.59, "N89%%d54'31\"W"),
};
var ms = (BlockTableRecord)Tx.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(Db), OpenMode.ForRead);
CogoPoint p166 = null;
foreach (ObjectId id in ms) { var cp = Tx.GetObject(id, OpenMode.ForRead) as CogoPoint; if (cp != null && cp.PointNumber == 166) p166 = cp; }
if (p166 == null) throw new System.Exception("point 166 not found");
var start = new Point2d(p166.Easting, p166.Northing);
Log("anchor: point 166 \"" + p166.RawDescription + "\" E=" + start.X.ToString("F3") + " N=" + start.Y.ToString("F3"));
// idempotent: skip if a polyline on the layer already starts at point 166
foreach (ObjectId id in ms) {
    var ex = Tx.GetObject(id, OpenMode.ForRead) as Polyline;
    if (ex != null && ex.Layer == LAYER && ex.NumberOfVertices == 5 && ex.GetPoint2dAt(0).GetDistanceTo(start) < 0.001) { Log("already drawn: " + ex.Handle + " - nothing changed"); return; }
}
EnsureLayer(LAYER); EnsureLayer(TLAYER);
double r = Math.PI / 180.0;
var pts = new List<Point2d> { start };
foreach (var c in CALLS) {
    double a = (c.d + c.m / 60.0 + c.s / 3600.0) * r;
    double dn = c.dist * Math.Cos(a) * (c.ns == 'N' ? 1 : -1);
    double de = c.dist * Math.Sin(a) * (c.ew == 'E' ? 1 : -1);
    var last = pts[pts.Count - 1];
    pts.Add(new Point2d(last.X + de, last.Y + dn));
}
var pl = new Polyline();
for (int i = 0; i < pts.Count; i++) pl.AddVertexAt(i, pts[i], 0, 0, 0);
pl.Closed = false;
Append(pl, LAYER);
var miss = pts[pts.Count - 1] - start;
Log("polyline " + pl.Handle + " on " + LAYER + ", length " + pl.Length.ToString("F2") + "', misclosure " + miss.Length.ToString("F3") + "' (dE " + miss.X.ToString("F3") + ", dN " + miss.Y.ToString("F3") + ")");
string[] names = { "SW (pt 166)", "NW", "NE", "SE", "end of 4th call" };
for (int i = 0; i < pts.Count; i++) Log("  " + names[i] + ": E=" + pts[i].X.ToString("F3") + " N=" + pts[i].Y.ToString("F3"));
// labels: traverse runs clockwise, so outside is the left side of travel
for (int i = 0; i < CALLS.Length; i++) {
    var a = pts[i]; var b = pts[i + 1];
    var dir = (b - a).GetNormal();
    var left = new Vector2d(-dir.Y, dir.X);
    var mid = new Point2d((a.X + b.X) / 2, (a.Y + b.Y) / 2);
    double ang = Math.Atan2(dir.Y, dir.X);
    if (ang > Math.PI / 2 || ang <= -Math.PI / 2) ang += Math.PI;
    for (int k = 0; k < 2; k++) {
        var at = mid + left * (k == 0 ? 3.0 : -3.0);
        var t = new MText();
        t.TextHeight = 3.0;
        t.Attachment = AttachmentPoint.MiddleCenter;
        t.Location = new Point3d(at.X, at.Y, 0);
        t.Rotation = ang;
        t.Contents = k == 0 ? CALLS[i].label : CALLS[i].dist.ToString("F2") + "'";
        Append(t, TLAYER);
    }
}
Log("labels: " + (CALLS.Length * 2) + " on " + TLAYER);
Ed.Regen();

Notes

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

No notes yet.