← Inbox

C3D-0423 · Linework: building outline (BLDG COR) -> V-BLDG [C3D-LWBLDG] done

Closed polyline through the BLDG COR points in the 800-5000 group, nearest-neighbor order, new layer V-BLDG. Building, so closed and not curve-fit.

Script file
C3D-0423.cs
Target
281 MARANTHA 2607.dwg · model space
Author
claude
Approved
yes · auto-auth
Timeout
120s

C# payload

// Linework: building outline (BLDG COR) -> V-BLDG
const string LAYER="V-BLDG"; const short COLOR=5; const bool CLOSED=true; const bool CURVE=false;
var civ=Autodesk.Civil.ApplicationServices.CivilApplication.ActiveDocument;
Log("drawing: " + Db.Filename);
var grpNums=new HashSet<uint>();
foreach (ObjectId gid in civ.PointGroups){ var g=(Autodesk.Civil.DatabaseServices.PointGroup)Tx.GetObject(gid,OpenMode.ForRead); if(g.Name.Contains("800")||g.Name.Contains("5000")){ foreach(uint u in g.GetPointNumbers()) grpNums.Add(u); } }
var pts=new List<Point2d>();
foreach (ObjectId id in civ.CogoPoints){
    var p=(Autodesk.Civil.DatabaseServices.CogoPoint)Tx.GetObject(id,OpenMode.ForRead);
    if(!grpNums.Contains((uint)p.PointNumber)) continue;
    string d=(p.RawDescription??"").ToUpper();
    if(d.StartsWith("BLDG")) pts.Add(new Point2d(p.Easting,p.Northing));
}
Log("V-BLDG points: " + pts.Count);
if(pts.Count<2){ Log("not enough"); return; }
double cx=0,cy=0; foreach(var p in pts){cx+=p.X;cy+=p.Y;} cx/=pts.Count; cy/=pts.Count;
int start=0; double best=-1; for(int i=0;i<pts.Count;i++){ double dd=(pts[i].X-cx)*(pts[i].X-cx)+(pts[i].Y-cy)*(pts[i].Y-cy); if(dd>best){best=dd;start=i;} }
var used=new bool[pts.Count]; var order=new List<int>{start}; used[start]=true;
for(int k=1;k<pts.Count;k++){ int cur=order[order.Count-1]; int nn=-1; double nb=double.MaxValue;
    for(int j=0;j<pts.Count;j++){ if(used[j])continue; double dd=(pts[cur].X-pts[j].X)*(pts[cur].X-pts[j].X)+(pts[cur].Y-pts[j].Y)*(pts[cur].Y-pts[j].Y); if(dd<nb){nb=dd;nn=j;} }
    order.Add(nn); used[nn]=true; }
var lt=(LayerTable)Tx.GetObject(Db.LayerTableId,OpenMode.ForWrite);
ObjectId layId; if(lt.Has(LAYER)) layId=lt[LAYER]; else{ var l=new LayerTableRecord(); l.Name=LAYER; l.Color=Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByAci,COLOR); layId=lt.Add(l); Tx.AddNewlyCreatedDBObject(l,true); Log("created layer "+LAYER); }
var pl=new Polyline(); for(int i=0;i<order.Count;i++) pl.AddVertexAt(i,pts[order[i]],0,0,0);
pl.LayerId=layId; if(CLOSED) pl.Closed=true;
if(CURVE){ int last=pl.NumberOfVertices-(CLOSED?0:1);
  for(int i=1;i<pl.NumberOfVertices-1;i++){ var a=pl.GetPoint2dAt(i-1); var b=pl.GetPoint2dAt(i); var c=pl.GetPoint2dAt(i+1);
    double dx1=b.X-a.X,dy1=b.Y-a.Y,dx2=c.X-b.X,dy2=c.Y-b.Y; double cross=dx1*dy2-dy1*dx2; double dot=dx1*dx2+dy1*dy2;
    double ang=System.Math.Atan2(cross,dot); double bulge=System.Math.Tan(ang/4.0); if(System.Math.Abs(bulge)>0.001) pl.SetBulgeAt(i-1,bulge); } }
var ms=(BlockTableRecord)Tx.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(Db),OpenMode.ForWrite);
ms.AppendEntity(pl); Tx.AddNewlyCreatedDBObject(pl,true);
var back=(Polyline)Tx.GetObject(pl.ObjectId,OpenMode.ForRead);
Log(string.Format("drew V-BLDG polyline [{0}]: {1} verts, len {2:F1}, closed {3}", back.Handle, back.NumberOfVertices, back.Length, back.Closed));
Ed.Regen();

Result

Status
success
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\260711 - 281 Maranatha Trail, Lawrenceville, GA 30045, USA\281 MARANTHA 2607.dwg
Message
Executed C3D-0423 (0 entities touched).
Entities
Duration
1356 ms
Civil 3D
25.0.0.0

Log

drawing: C:\Users\sanja\OneDrive\_SurveyDisco\260711 - 281 Maranatha Trail, Lawrenceville, GA 30045, USA\281 MARANTHA 2607.dwg
V-BLDG points: 4
created layer V-BLDG
drew V-BLDG polyline [11B54]: 4 verts, len 164.7, closed True

Notes

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

No notes yet.