AutoCAD.NET 二次开发(二) 自动替换缺失字体

此次的目的是为了避免每次都要手动的去替换字体,减少麻烦...

参考文章:http://hi.baidu.com/kakanimo/item/e36168dcd0cb764bddf9be5f

基本上是复制了下卡卡尼莫的代码,就搞定了

对其代码有一处修改就是 documentCreateStarted 方法,try ...catch 里面,先行对Application.DocumentManager.MdiActiveDocument是否为空进行了次判断,以避免异常的出现。

同时,修改了那几个类似于属性声明的类,改为了成员变量,应该不需要那么麻烦的声明..

转载于:https://www.cnblogs.com/loveclumsybaby/archive/2012/08/21/2649271.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
AutoCAD .NET中,可以使用以下步骤来判断是否缺失字体: 1. 获取当前文档中的字体列表。可以通过访问ActiveDocument对象的TextStyleTable属性来获取字体表。 2. 遍历字体列表,获取每个字体的名称。 3. 使用System.Drawing.Text.InstalledFontCollection类来获取系统中所有已安装的字体列表。 4. 对比已安装的字体列表和AutoCAD文档中使用的字体列表,判断是否存在缺失字体。 以下是一个简单的示例代码来实现上述步骤: ```csharp using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.ApplicationServices; using System; using System.Collections.Generic; using System.Drawing.Text; [assembly: CommandClass(typeof(AutoCADPlugin.CheckFont))] namespace AutoCADPlugin { public class CheckFont { [CommandMethod("CheckMissingFonts")] public void CheckMissingFonts() { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; TextStyleTable textStyleTable = db.TextStyleTableId.GetObject(OpenMode.ForRead) as TextStyleTable; // 获取AutoCAD文档中的字体列表 List<string> docFontList = new List<string>(); foreach (ObjectId textStyleId in textStyleTable) { TextStyle textStyle = textStyleId.GetObject(OpenMode.ForRead) as TextStyle; docFontList.Add(textStyle.Font); } // 获取系统中已安装的字体列表 List<string> installedFonts = new List<string>(); InstalledFontCollection fontCollection = new InstalledFontCollection(); foreach (FontFamily font in fontCollection.Families) { installedFonts.Add(font.Name); } // 比较已安装字体和文档字体,判断是否缺失字体 List<string> missingFonts = new List<string>(); foreach (string font in docFontList) { if (!installedFonts.Contains(font)) { missingFonts.Add(font); } } if (missingFonts.Count > 0) { string missingFontNames = string.Join(", ", missingFonts); Console.WriteLine("缺失字体:{0}", missingFontNames); } else { Console.WriteLine("没有缺失字体。"); } } } } ``` 运行上述代码时,会输出缺失字体名称。如果输出为空,则表示没有缺失字体

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值