根据文本包含的内容和坐标在 CAD 中堆叠文本

Stack text in CAD based on what it contains and coordinates

请参阅显示我需要如何在 CAD 中堆叠文本的附图。我尝试过的一切都无法解释所有情况。

基本上,我正在使用文本的坐标来尝试确定如何正确排列它。任何帮助将不胜感激。我的作品如下:

       private void swaptext()
    {
        using (ac.AcadDocumentLock)
        {
            using (var t = ac.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")) && (pos1.X < pos2.X))
                    {
                            tx1.Contents = conts2;
                            tx2.Contents = conts1;
                    }

                    else if ((tx1.Contents.Contains("TWO")) && (pos1.Y < pos2.Y))
                    {

                            tx2.Contents = conts1;
                            tx1.Contents = conts2;
                    }


                    ids.Clear();
                }
                catch (System.Exception ex)
                {
                 ac.AcadDocument.Editor.WriteMessage("Error: ==>\n{0}\nTrace: ==>\n{1}", ex.Message, ex.StackTrace);
                }
                t.Commit();
            }
        }
    }

Stacking Text

如果你只是将文字旋转回0度,那么你可以只比较哪个文字的Y坐标更高。那个应该包含 "ONE"

这个词
private void swaptext()
    {
        using (ac.AcadDocumentLock)
        {
            using (var t = ac.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;
                    Extents3d Ex1 = tx1.GeometricExtents;
                    Extents3d Ex2 = tx2.GeometricExtents;
                    Point3d pos1 = Ex1.MaxPoint.RotateBy(-tx1.Rotation, tx1.Normal, tx1.Location);
                    Point3d pos2 = Ex2.MaxPoint.RotateBy(-tx2.Rotation, tx2.Normal, tx2.Location);

                    if ((tx1.Contents.Contains("TWO")) && (pos1.Y > pos2.Y))
                    {
                        tx1.Contents = conts2;
                        tx2.Contents = conts1;
                    }
                    else
                        if ((tx2.Contents.Contains("TWO")) && (pos2.Y > pos1.Y))
                        {
                            tx1.Contents = conts2;
                            tx2.Contents = conts1;
                        }

                    ids.Clear();
                }
                catch (System.Exception ex)
                {
                    ac.AcadDocument.Editor.WriteMessage("Error: ==>\n{0}\nTrace: ==>\n{1}", ex.Message, ex.StackTrace);
                }
                t.Commit();
            }
        }
    }