C3D-0326 · 260714 Huckaby R2: flip the reversed power lines so the Ps read upright done
Complex-linetype text reads along the lines direction, so a line drawn right-to-left shows its Ps upside down. Reverses any SS-V-POWER-CL line whose direction points into the left half-plane by swapping StartPoint/EndPoint - identical geometry, nothing moves on the sheet, only the direction changes. Logs each lines bearing before and after and verifies the length is unchanged.
C# payload
// Text in a complex linetype reads along the line's DIRECTION, so a line drawn right-to-left
// shows its P's upside down. Flip any power centreline whose start point is east of its end
// point (i.e. bearing pointing into the western half) so every line runs left-to-right.
//
// Reversing a Line is just swapping StartPoint/EndPoint - the geometry is identical, only the
// direction changes, so nothing moves on the sheet.
const string LAYER = "SS-V-POWER-CL";
Log("drawing: " + Db.Filename);
var ms = (BlockTableRecord)Tx.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(Db), OpenMode.ForWrite);
var ids = new List<ObjectId>();
foreach (ObjectId id in ms) {
var e = Tx.GetObject(id, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Entity;
if (e == null || e.IsErased) continue;
if (e.Layer.Equals(LAYER, StringComparison.OrdinalIgnoreCase) && e is Line) ids.Add(id);
}
Log("power centrelines: " + ids.Count);
int flipped = 0;
foreach (var id in ids) {
var ln = (Line)Tx.GetObject(id, OpenMode.ForRead);
var a = ln.StartPoint; var b = ln.EndPoint;
double dx = b.X - a.X, dy = b.Y - a.Y;
double bearing = Math.Atan2(dy, dx) * 180.0 / Math.PI;
// text is upside down when the direction points into the left half-plane
bool backwards = dx < 0 || (Math.Abs(dx) < 1e-9 && dy < 0);
Log(string.Format("[{0}] ({1:F1},{2:F1})->({3:F1},{4:F1}) dx={5:+0.0;-0.0} bearing={6:F1} deg {7}",
ln.Handle, a.X, a.Y, b.X, b.Y, dx, bearing, backwards ? "BACKWARDS - flipping" : "ok"));
if (!backwards) continue;
var w = (Line)Tx.GetObject(id, OpenMode.ForWrite);
w.StartPoint = b;
w.EndPoint = a;
flipped++;
var back = (Line)Tx.GetObject(id, OpenMode.ForRead);
double ndx = back.EndPoint.X - back.StartPoint.X;
double nb = Math.Atan2(back.EndPoint.Y - back.StartPoint.Y, ndx) * 180.0 / Math.PI;
Log(string.Format(" -> ({0:F1},{1:F1})->({2:F1},{3:F1}) bearing={4:F1} deg len={5:F1} (verified)",
back.StartPoint.X, back.StartPoint.Y, back.EndPoint.X, back.EndPoint.Y, nb, back.Length));
}
Log("");
Log(string.Format("flipped {0} of {1} lines; all now run left-to-right so the P's read upright", flipped, ids.Count));
Ed.Regen();
Result
Log
drawing: C:\Users\sanja\OneDrive\_SurveyDisco\260714 - 285 Huckaby Rd, Brooks, GA 30205, USA\260714 - 285 Huckaby Rd R2.dwg
power centrelines: 4
[20C9D] (2204490.0,1206692.3)->(2203658.5,1207011.5) dx=-831.5 bearing=159.0 deg BACKWARDS - flipping
-> (2203658.5,1207011.5)->(2204490.0,1206692.3) bearing=-21.0 deg len=893.0 (verified)
[20C9E] (2203300.2,1207078.4)->(2203658.5,1207011.5) dx=+358.3 bearing=-10.6 deg ok
[20CA9] (2206381.7,1207400.1)->(2204867.8,1207381.5) dx=-1513.9 bearing=-179.3 deg BACKWARDS - flipping
-> (2204867.8,1207381.5)->(2206381.7,1207400.1) bearing=0.7 deg len=1514.6 (verified)
[20CB1] (2204867.8,1207381.5)->(2203298.4,1207370.3) dx=-1569.5 bearing=-179.6 deg BACKWARDS - flipping
-> (2203298.4,1207370.3)->(2204867.8,1207381.5) bearing=0.4 deg len=1569.6 (verified)
flipped 3 of 4 lines; all now run left-to-right so the P's read uprightNotes
What worked, what didn't, job-specific gotchas — flagged notes feed the recipes.
No notes yet.