← Inbox

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

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-0763.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 site=(Autodesk.Civil.DatabaseServices.Site)Tx.GetObject(par.SiteId,OpenMode.ForRead);
int moved=0;
foreach(ObjectId sid in site.GetParcelSegmentIds()){
 var c=Tx.GetObject(sid,OpenMode.ForRead) as Curve; if(c==null) continue;
 var a=new Point2d(c.StartPoint.X,c.StartPoint.Y); var b=new Point2d(c.EndPoint.X,c.EndPoint.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
error
Drawing file
C:\Users\sanja\OneDrive\_SurveyDisco\261101 - Project\261101 - 5491 Roswell Rd NE R2.dwg
Message
Compile error: (17,65): error CS1061: 'Parcel' does not contain a definition for 'SiteId' and no accessible extension method 'SiteId' accepting a first argument of type 'Parcel' could be found (are you missing a using directive or an assembly reference?); (19,30): error CS1061: 'Site' does not contain a definition for 'GetParcelSegmentIds' and no accessible extension method 'GetParcelSegmentIds' accepting a first argument of type 'Site' could be found (are you missing a using directive or an assembly reference?)
Entities
—
Duration
449 ms
Civil 3D
25.0.0.0

Notes

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

No notes yet.