← Inbox

C3D-0181 · Move the L.L. markers to LAND_LOT_LINE_TEXT and beside the annotation [LL-FIX-LAYER] approved

Moves the two land lot markers and their circles from LAND_LOT_LINE to LAND_LOT_LINE_TEXT, following the drawing FEATURE/FEATURE_TEXT convention where the annotation already lives, and re-centres them on the annotation current Y so they sit beside the text rather than at the line midpoint. Each marker keeps its side of the line. Verifies the move.

Script file
C3D-0181.cs
Target
active document · model space
Author
claude
Approved
yes · test
Timeout
240s

C# payload

// Fix the two land lot markers:
//   1. move them to LAND_LOT_LINE_TEXT - the drawing's convention is FEATURE / FEATURE_TEXT
//      (SEWER_MANHOLE + SEWER_MANHOLE_TEXT, PROJECT_BOUNDARY + PROJECT_BOUNDARY_TEXT), and that
//      layer already holds the APPROXIMATE LAND LOT LINE annotation. The line stays on
//      LAND_LOT_LINE; only its ANNOTATION moves.
//   2. re-centre them on the annotation's Y, since the user has since moved that text - the
//      markers belong beside it, not at the line's midpoint where I first put them.
// Only the entities created by C3D-0179 are touched.
const string OLD = "LAND_LOT_LINE";
const string NEW = "LAND_LOT_LINE_TEXT";
var ms = (BlockTableRecord)Tx.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(Db), OpenMode.ForWrite);
Log("drawing: " + Db.Filename);
EnsureLayer(NEW, 7);

// where is the annotation now?
double ay = 0; bool haveAnno = false;
foreach (ObjectId id in ms) {
    Autodesk.AutoCAD.DatabaseServices.DBObject o;
    try { o = Tx.GetObject(id, OpenMode.ForRead); } catch { continue; }
    string s = null; Point3d p = Point3d.Origin;
    var mt = o as MText;  if (mt != null) { s = mt.Contents; p = mt.Location; }
    var dt = o as DBText; if (dt != null) { s = dt.TextString; p = dt.Position; }
    if (s == null) continue;
    string u = s.ToUpper();
    if (u.IndexOf("APPROXIMATE") < 0 && u.IndexOf("LOT LINE") < 0) continue;
    var ent = (Autodesk.AutoCAD.DatabaseServices.Entity)o;
    Log("annotation [" + o.Handle + "] on " + ent.Layer + String.Format(" at {0:F3},{1:F3}", p.X, p.Y));
    ay = p.Y; haveAnno = true;
}

// the land lot line, for the X to straddle
Line ll = null;
foreach (ObjectId id in ms) {
    var l = Tx.GetObject(id, OpenMode.ForRead) as Line;
    if (l != null && !l.IsErased && l.Layer == OLD) { ll = l; break; }
}
if (ll == null) { Log("ABORT: land lot line not found on " + OLD); return; }
double lineX = (ll.StartPoint.X + ll.EndPoint.X) / 2.0;
if (!haveAnno) { ay = (ll.StartPoint.Y + ll.EndPoint.Y) / 2.0; Log("no annotation found - keeping the line midpoint"); }

// collect what C3D-0179 made: the L.L. texts and their circles, currently on OLD
var texts = new List<ObjectId>();
var circles = new List<ObjectId>();
foreach (ObjectId id in ms) {
    Autodesk.AutoCAD.DatabaseServices.DBObject o;
    try { o = Tx.GetObject(id, OpenMode.ForRead); } catch { continue; }
    var ent = o as Autodesk.AutoCAD.DatabaseServices.Entity;
    if (ent == null || ent.IsErased || ent.Layer != OLD) continue;
    var t = o as MText;
    if (t != null && t.Contents.IndexOf("L.L.") >= 0) { texts.Add(id); continue; }
    if (o is Circle) circles.Add(id);
}
Log("found " + texts.Count + " L.L. labels and " + circles.Count + " circles on " + OLD);
if (texts.Count == 0) { Log("nothing to fix"); return; }

// move each label to the annotation's Y, keeping its side of the line, and take its circles along
double dyShift = 0;
foreach (ObjectId tid in texts) {
    var t = (MText)Tx.GetObject(tid, OpenMode.ForWrite);
    double oldY = t.Location.Y;
    dyShift = ay - oldY;
    var oldLoc = t.Location;
    t.Location = new Point3d(t.Location.X, ay, 0);
    t.Layer = NEW;
    Log(String.Format("  \"{0}\"  {1:F3},{2:F3} -> {3:F3},{4:F3}   layer {5} -> {6}",
        t.Contents.Replace("\n","/"), oldLoc.X, oldLoc.Y, t.Location.X, t.Location.Y, OLD, NEW));

    // its two concentric circles share the same centre
    foreach (ObjectId cid in circles) {
        var c0 = Tx.GetObject(cid, OpenMode.ForRead) as Circle;
        if (c0 == null || c0.IsErased) continue;
        if (Math.Abs(c0.Center.X - oldLoc.X) > 0.01 || Math.Abs(c0.Center.Y - oldY) > 0.01) continue;
        var c = (Circle)Tx.GetObject(cid, OpenMode.ForWrite);
        c.Center = new Point3d(c.Center.X, ay, 0);
        c.Layer = NEW;
    }
}

// verify
int nT = 0, nC = 0, leftOver = 0;
foreach (ObjectId id in ms) {
    Autodesk.AutoCAD.DatabaseServices.DBObject o;
    try { o = Tx.GetObject(id, OpenMode.ForRead); } catch { continue; }
    var ent = o as Autodesk.AutoCAD.DatabaseServices.Entity;
    if (ent == null || ent.IsErased) continue;
    if (ent.Layer == NEW) {
        var t = o as MText;
        if (t != null && t.Contents.IndexOf("L.L.") >= 0) nT++;
        if (o is Circle) nC++;
    }
    if (ent.Layer == OLD && (o is Circle)) leftOver++;
}
Log("");
Log("on " + NEW + ": " + nT + " L.L. labels, " + nC + " circles.  circles still on " + OLD + ": " + leftOver + " (verified)");
Ed.Regen();

Result

Status
success
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\260613 - 5030 E Lake Pkwy, Stockbridge, GA 30281, USA\260612-C-Store Sewer As-Built.dwg
Message
Executed C3D-0181 (0 entities touched).
Entities
Duration
517 ms
Civil 3D
25.0.0.0

Log

drawing: C:\Users\sanja\OneDrive\_SurveyDisco\260613 - 5030 E Lake Pkwy, Stockbridge, GA 30281, USA\260612-C-Store Sewer As-Built.dwg
annotation [2E2E5] on LAND_LOT_LINE_TEXT at 2296402.766,1279819.862
found 2 L.L. labels and 4 circles on LAND_LOT_LINE
  "L.L.\P3"  2296379.028,1279842.843 -> 2296379.028,1279819.862   layer LAND_LOT_LINE -> LAND_LOT_LINE_TEXT
  "L.L.\P4"  2296429.028,1279842.843 -> 2296429.028,1279819.862   layer LAND_LOT_LINE -> LAND_LOT_LINE_TEXT

on LAND_LOT_LINE_TEXT: 2 L.L. labels, 4 circles.  circles still on LAND_LOT_LINE: 0 (verified)

Notes

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

No notes yet.