明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 686|回复: 1

求助

[复制链接]
发表于 2017-8-11 17:48 | 显示全部楼层 |阅读模式
c#开发插件 出现 错误        5        “Autodesk.AutoCAD.DatabaseServices.MText”不包含“TextStyle”的定义,并且找不到可接受类型为“Autodesk.AutoCAD.DatabaseServices.MText”的第一个参数的扩展方法“TextStyle”(是否缺少 using 指令或程序集引用?)        代码:
//控制文字长度
        [CommandMethod("hg11")]
        public void wztkdbl()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            Database db = HostApplicationServices.WorkingDatabase;
            ed.WriteMessage("\n通过修改文字高宽比控制文字长度");

            //Wch2.FilterType dbmextType = Wch2.FilterType.Text;
            //Wch2.FilterType mtextType = Wch2.FilterType.MText;

            Wch2.FilterType[] Types = new Wch2.FilterType[3];
            Types[0] = Wch2.FilterType.Text;
            Types[1] = Wch2.FilterType.MText;
            Types[2] = Wch2.FilterType.Dimension;
            DBObjectCollection EntityCollection = Wch2.GetS(Types);
            if (EntityCollection == null)
                return;

            PromptDistanceOptions xzkd = new PromptDistanceOptions("\n文字限制宽度");
            PromptDoubleResult kdjg = ed.GetDistance(xzkd);
            if (kdjg.Status != PromptStatus.OK)
                return;
            double k = kdjg.Value;
            using (Transaction tran = db.TransactionManager.StartTransaction())
            {
                foreach (DBObject odb in EntityCollection)
                {
                    ObjectId odbid = odb.Id;
                    Entity ent = tran.GetObject(odbid, OpenMode.ForWrite) as Entity;

                    if (ent is DBText)
                    {
                        DBText dbt = (DBText)ent;
                        TextStyleTableRecord tstr = (TextStyleTableRecord)tran.GetObject(dbt.TextStyle, OpenMode.ForRead);//读取当前字体
                        double zkbl = tstr.XScale;//当前字体高宽比
                        double cd;
                        double jd = dbt.Rotation;
                        int n = 0;
                        do
                        {
                            dbt.WidthFactor = zkbl - 0.01 * n;
                            dbt.Rotation = 0;
                            Extents3d wzd = dbt.GeometricExtents;
                            cd = wzd.MaxPoint.X - wzd.MinPoint.X;
                            n++;
                        } while (cd > k);
                        dbt.Rotation = jd;
                    }
                    if (ent is MText)
                    {
                        MText mtt = (MText)ent;
                        TextStyleTableRecord tstr = (TextStyleTableRecord)tran.GetObject(mtt.TextStyle, OpenMode.ForRead);//读取当前字体
                        double zkbl = tstr.XScale;//当前字体高宽比
                        double zk;
                        string wznr = mtt.Text;
                        int n = 0;
                        do
                        {
                            mtt.Contents = "{\\W" + (zkbl - n * 0.01) + ";" + wznr + "}";
                            zk = mtt.ActualWidth;
                            n++;
                        } while (zk > k);
                    }
                    if (ent is Dimension)
                    {
                        Dimension dim = (Dimension)ent;
                        MText mte = new MText();
                        mte.TextStyle = dim.Dimtxsty;
                        mte.TextHeight = dim.Dimtxt;
                        string str;
                        string str1;
                        string str2;
                        string str3;
                        TextStyleTableRecord tstr = (TextStyleTableRecord)tran.GetObject(mte.TextStyle, OpenMode.ForRead);//读取当前字体
                        double zkbl = tstr.XScale;//当前字体高宽比
                        if (dim.DimensionText != "" && !dim.DimensionText.Contains("<>"))
                        {
                            str = dim.DimensionText;
                            mte.Contents = str;
                            str2 = mte.Text;
                        }
                        else
                        {
                            double bznr = Math.Round(dim.Measurement, dim.Dimdec);
                            str = bznr.ToString();
                            mte.Contents = str;
                            str2 = "<>";
                        }
                        str1 = mte.Text;
                        double zk;
                        int n = 0;
                        do
                        {
                            str3 = "{\\W" + (zkbl - n * 0.01) + ";";
                            mte.Contents = str3 + str1 + "}";
                            zk = mte.ActualWidth;
                            n++;
                        } while (zk > k);
                        dim.DimensionText = str3 + str2 + "}";
                    }
                }



发表于 2017-8-11 18:04 | 显示全部楼层
你好,这个是.net开发CAD用到的,请你在C#开发板块提问吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-3-28 19:09 , Processed in 0.153219 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表