← Inbox

C3D-READA2 · Find A polyline (user-added) + A bearings (read-only) done

Locate the closed polyline the user added for TRACT A + its ParcelSegmentLabel bearings.

Script file
C3D-READA2.cs
Target
active document · model space
Author
claude
Approved
yes · claude (read-only)
Timeout
60s

C# payload

// READ-ONLY: find TRACT A's real boundary polyline (user just added it) + its bearing labels.
// Look for a closed Polyline near A centroid (2166741,1330610) on any SS-BOUNDARY/boundary layer.
// Then list ParcelSegmentLabels whose location sits on that polyline (A's bearings) vs B's.
using System;
using System.Linq;
using System.Collections.Generic;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.Civil.DatabaseServices;

var db = Db;
var Acen = new Point2d(2166741.9, 1330610.1);

using (var tr = db.TransactionManager.StartTransaction())
{
    var ms=(BlockTableRecord)tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db),OpenMode.ForRead);
    // closed polylines near A, with their layer + perimeter + centroid
    Log("CLOSED POLYLINES near TRACT A:");
    var aSamples=new List<Point2d>();
    string bestLayer=null; ObjectId bestId=ObjectId.Null; double bestD=9e9;
    foreach(ObjectId id in ms){
        var e=tr.GetObject(id,OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Entity;
        if(!(e is Polyline pl)) continue;
        Point2d c; try{ var ex=e.GeometricExtents; c=new Point2d((ex.MinPoint.X+ex.MaxPoint.X)/2,(ex.MinPoint.Y+ex.MaxPoint.Y)/2);}catch{continue;}
        double d=c.GetDistanceTo(Acen);
        if(d>200) continue;
        Log($"  '{e.Layer}' verts={pl.NumberOfVertices} closed={pl.Closed} len={pl.Length:0.0} center=({c.X:0.0},{c.Y:0.0}) d={d:0} h={e.Handle}");
        if(pl.Closed && pl.Length>400 && d<bestD){ bestD=d; bestLayer=e.Layer; bestId=id; }
    }
    Log($"BEST A boundary candidate: layer='{bestLayer}' id={bestId} d={bestD:0}");
    if(bestId!=ObjectId.Null){
        var pl=(Polyline)tr.GetObject(bestId,OpenMode.ForRead);
        for(int i=0;i<pl.NumberOfVertices;i++){ var v=pl.GetPoint3dAt(i); aSamples.Add(new Point2d(v.X,v.Y)); }
    }

    // bearings on A vs elsewhere: nearest to A polyline verts within 40'
    if(aSamples.Count>0){
        double dA(Point2d p)=>aSamples.Min(q=>p.GetDistanceTo(q));
        var aB=new List<string>();
        foreach(ObjectId id in ms){ var e=tr.GetObject(id,OpenMode.ForRead);
            if(!(e is ParcelSegmentLabel ps)) continue;
            Point2d loc; try{loc=new Point2d(ps.LabelLocation.X,ps.LabelLocation.Y);}catch{continue;}
            if(dA(loc)<=40) aB.Add($"{ps.Handle}@{ps.Layer}");
        }
        Log($"TRACT A bearings ({aB.Count}): {string.Join(", ", aB)}");
    }
    tr.Commit();
}

Result

Status
success
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\260619 - 3625 Stonewall Tell Rd, Atlanta, GA 30349, USA\260619 - 3625 Stonewall Tell Rd.dwg
Message
Executed C3D-READA2 (0 entities touched).
Entities
Duration
416 ms
Civil 3D
25.0.0.0

Log

CLOSED POLYLINES near TRACT A:
  'SS-V-ROAD-CURB' verts=3 closed=False len=85.4 center=(2166884.1,1330646.2) d=147 h=20B8F
  'SS-V-ROAD-CNTR' verts=19 closed=False len=1237.1 center=(2166766.2,1330413.4) d=198 h=20B93
  'SS-V-BLDG-OTLN' verts=7 closed=True len=201.4 center=(2166682.4,1330533.7) d=97 h=20C73
  'SS-V-ROAD-CURB' verts=4 closed=True len=38.2 center=(2166671.0,1330556.9) d=89 h=20C74
  'SS-V-ROAD-CURB' verts=6 closed=False len=16.0 center=(2166665.0,1330558.0) d=93 h=20C75
  'SS-V-ROAD-EPVM' verts=12 closed=True len=347.3 center=(2166741.4,1330473.0) d=137 h=20C7C
  'SS-V-ROAD-CURB' verts=3 closed=False len=106.7 center=(2166767.7,1330414.5) d=197 h=20C88
  'SS-V-ROAD-CURB' verts=4 closed=True len=104.7 center=(2166712.2,1330425.0) d=187 h=20CAE
  'SS-HERO TRACT A' verts=4 closed=True len=192.0 center=(2166737.1,1330606.9) d=6 h=216AA
  'SS-BOUNDARY TRACT A' verts=5 closed=False len=840.1 center=(2166741.9,1330610.1) d=0 h=216AD
BEST A boundary candidate: layer='' id=(0) d=9000000000

Notes

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

No notes yet.