1

我有一些有趣的任务。在其中一张图中,我有一个 MText 字段。所以,我的插件需要知道如何从这张图和其他图中准确地获取该字段。有什么属性或smth,我可以用什么来确定不同图纸上的多行文本字段?

4

1 回答 1

3

我想这可能是你正在寻找的......

    using Autodesk.AutoCAD.ApplicationServices;
    using Autodesk.AutoCAD.DatabaseServices;
    using Autodesk.AutoCAD.Runtime;
    using AcApplication = Autodesk.AutoCAD.ApplicationServices.Application;


    public static Document acDoc {
        get {
            return Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
        }
    }

    public static MText getMTextObj(string TextYouNeed)
    {
        var ed = acDoc.Editor;
        var selMText = new TypedValue[1];
        selMText.SetValue(new TypedValue(0,"MTEXT"),0);
        var MTextObjs = ed.SelectAll(new SelectionFilter(selMText));

        using (var Transaction = acDoc.Database.TransactionManager.StartTransaction()) {
            foreach (ObjectId MTextObjId in MTextObjs.Value.GetObjectIds()) {
                var current_MTextObj = Transaction.GetObject(MTextObjId,OpenMode.ForWrite) as MText;
                if(current_MTextObj.Text.Equals(TextYouNeed))
                    // return current_MTextObj;
                    // or
                    // do somehting else 
            }
        }
        Transaction.Commit(); // if you change something.
    }
于 2013-07-01T19:39:25.923 回答