← Inbox

C3DO-0766 · 261101: Turn 277 on parcel 2185A - rotate about 243 to match polyline 21856 [C3D-TURN277P] done

Rotate the parcel segments of parcel 2185A (17 0091 LL1920) clockwise about point 243 by the same angle polyline 21856 was turned in C3DO-0761 (about 0°29'00"), angle measured from the drawing. Reads back the parcel vertices against 21856.

Script file
C3DO-0766.cs
Target
261101 - 5491 Roswell Rd NE R2.dwg · model space
Author
claude
Approved
yes · auto-auth
Timeout
60s

C# payload

Func<string,ObjectId> oid=hs=>{ ObjectId id; Db.TryGetObjectId(new Handle(Convert.ToInt64(hs,16)),out id); return id; };
Point3d? p243=null; foreach(ObjectId id in CivilDoc.CogoPoints){ var cp=(Autodesk.Civil.DatabaseServices.CogoPoint)Tx.GetObject(id,OpenMode.ForRead); if(cp.PointNumber==243) p243=new Point3d(cp.Easting,cp.Northing,0); }
if(p243==null){ Log("STOP - point 243 not found"); return; }
var P=new Point2d(p243.Value.X,p243.Value.Y);
var par=Tx.GetObject(oid("2185A"),OpenMode.ForRead) as Autodesk.Civil.DatabaseServices.Parcel;
var pl=Tx.GetObject(oid("21856"),OpenMode.ForRead) as Polyline;
if(par==null||pl==null){ Log("STOP - parcel 2185A or polyline 21856 not found"); return; }
var bc=par.BaseCurve; var pv=new List<Point2d>(); for(int i=0;i<(int)bc.EndParam;i++){ var q=bc.GetPointAtParameter(i); pv.Add(new Point2d(q.X,q.Y)); }
// angle = polyline SE now vs parcel SE now, about 243
Point2d pse=pv.OrderBy(q=>q.Y).First(q=>q.GetDistanceTo(P)>1); // parcel SE (lowest non-243 vertex)
foreach(var q in pv) if(q.GetDistanceTo(P)>1 && q.X>2232590 && q.Y<pse.Y+100 && q.Y<1420500) pse=q;
var lse=pl.GetPoint2dAt(3);
double th=Math.Atan2(lse.Y-P.Y,lse.X-P.X)-Math.Atan2(pse.Y-P.Y,pse.X-P.X);
Log("parcel SE "+pse.X.ToString("F4")+","+pse.Y.ToString("F4")+" poly SE "+lse.X.ToString("F4")+","+lse.Y.ToString("F4")+" turn "+(th*180/Math.PI*3600).ToString("F2")+" sec");
if(Math.Abs(th*180/Math.PI*3600)<0.5){ Log("parcel already matches the polyline - nothing to do"); return; }
if(Math.Abs(th*180/Math.PI*3600)>1800){ Log("STOP - turn larger than expected"); return; }
var ms=(BlockTableRecord)Tx.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(Db),OpenMode.ForRead);
int moved=0;
foreach(ObjectId sid in ms){
 if(!(Tx.GetObject(sid,OpenMode.ForRead) is Autodesk.Civil.DatabaseServices.ParcelSegment)) continue;
 var c=Tx.GetObject(sid,OpenMode.ForRead) as Curve; if(c==null) continue;
 Point3d sp,ep; try{ sp=c.GetPointAtParameter(0); ep=c.GetPointAtParameter((int)c.EndParam); }catch(Exception ex){ Log("  seg "+sid.Handle+" endpoints unreadable: "+ex.Message); continue; } var a=new Point2d(sp.X,sp.Y); var b=new Point2d(ep.X,ep.Y);
 bool on=pv.Any(q=>q.GetDistanceTo(a)<0.01)&&pv.Any(q=>q.GetDistanceTo(b)<0.01);
 Log("  seg "+sid.Handle+" "+a.X.ToString("F4")+","+a.Y.ToString("F4")+" -> "+b.X.ToString("F4")+","+b.Y.ToString("F4")+(on?" ON parcel":" not on parcel"));
 if(!on) continue;
 var e=(Autodesk.AutoCAD.DatabaseServices.Entity)Tx.GetObject(sid,OpenMode.ForWrite);
 e.TransformBy(Matrix3d.Rotation(th,Vector3d.ZAxis,p243.Value)); moved++; }
Log("rotated "+moved+" parcel segments");
if(moved==0){ Log("STOP - no segments on the parcel found"); throw new Exception("no segments"); }
var par2=(Autodesk.Civil.DatabaseServices.Parcel)Tx.GetObject(oid("2185A"),OpenMode.ForRead); var bc2=par2.BaseCurve; double worst=0;
for(int i=0;i<(int)bc2.EndParam;i++){ var q=bc2.GetPointAtParameter(i); var q2=new Point2d(q.X,q.Y); double d=1e9; for(int k=0;k<pl.NumberOfVertices;k++) d=Math.Min(d,pl.GetPoint2dAt(k).GetDistanceTo(q2)); if(d>worst) worst=d; Log("  after v"+i+" "+q.X.ToString("F4")+","+q.Y.ToString("F4")+" to poly vertex "+d.ToString("F4")); }
Log("parcel "+par2.Name+" area "+par2.Area.ToString("F2")+" worst vertex gap to 21856 "+worst.ToString("F4")+" (verified)");
Ed.Regen();

Result

Status
success
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\261101 - Project\261101 - 5491 Roswell Rd NE R2.dwg
Message
Executed C3DO-0766 (0 entities touched).
Entities
—
Duration
478 ms
Civil 3D
25.0.0.0

Log

parcel SE 2232597.3379,1420481.7614 poly SE 2232597.5849,1420479.5546 turn -1739.74 sec
  seg 101C9 endpoints unreadable: eInvalidInput
  seg 21859 2232335.8260,1420451.3711 -> 2232335.8260,1420451.3711 ON parcel
rotated 1 parcel segments
  after v0 2232597.5849,1420479.5546 to poly vertex 0.0000
  after v1 2232335.8260,1420451.3711 to poly vertex 0.0000
  after v2 2232331.6151,1420625.3902 to poly vertex 0.0000
  after v3 2232599.0374,1420643.5759 to poly vertex 0.0000
parcel 17 0091 LL1920 area 44753.14 worst vertex gap to 21856 0.0000 (verified)

Notes

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

No notes yet.