public static double anglefromxpos(Point3d pt1, Point3d pt2)
{
CoordinateSystem3d systemd = Application.DocumentManager.MdiActiveDocument.Editor.CurrentUserCoordinateSystem.CoordinateSystem3d;
Plane plane
= new Plane
(systemd
.Origin, systemd
.Xaxis, systemd
.Yaxis); Vector3d vectord = (Vector3d)(pt2 - pt1);
return vectord.AngleOnPlane(plane);
}
private void swaptext()
{
using (help.AcadDocumentLock)
{
using (var t = help.StartTransaction)
{
try
{
MText tx1 = (MText)ids[0].GetObject(OpenMode.ForRead);
MText tx2 = (MText)ids[1].GetObject(OpenMode.ForRead);
string conts1 = tx1.Contents;
string conts2 = tx2.Contents;
Point3d pos1 = tx1.Location;
Point3d pos2 = tx2.Location;
if ((tx1.Contents.Contains("TWO")) && (anglefromxpos(pos1,pos2) < 3.14159) && (pos1.Y > pos2.Y))
{
tx1.Contents = conts2;
tx2.Contents = conts1;
}
if ((tx2.Contents.Contains("TWO")) && (anglefromxpos(pos2, pos1) < 3.14159) && (pos2.Y > pos1.Y))
{
tx2.Contents = conts1;
tx1.Contents = conts2;
}
ids.Clear();
}
catch (System.Exception ex)
{
help.AcadDocument.Editor.WriteMessage("Error: ==>\n{0}\nTrace: ==>\n{1}", ex.Message, ex.StackTrace);
}
t.Commit();
}
}
}