代码之家  ›  专栏  ›  技术社区  ›  A51

基于内容和坐标在CAD中堆叠文本

  •  0
  • A51  · 技术社区  · 7 年前

    请参阅所附图片,显示我需要如何在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

    1 回复  |  直到 7 年前
        1
  •  0
  •   mavios    7 年前

    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();
                }
            }
        }