如果,cad文件无略缩图:
AutoCAD2021版本以上,命令行输入"netload "加载此dll插件,然后输入 “lst”,选择文件夹,即可一键实现给dwg增加略缩图。
效果如下:
附部分代码:
namespace 略缩图
{public class 显示略缩图{[CommandMethod("lst")]public void 批量给dwg显示略缩图(){var doc1 = Application.DocumentManager.MdiActiveDocument;var ed = doc1.Editor;// 用户选择文件夹var dialog = new FolderBrowserDialog { Description = "选择DWG文件所在文件夹" };if (dialog.ShowDialog() != DialogResult.OK) return;var folderName = "DWG文件略缩图";// 创建输出目录string outputDir = GetUniqueFolder(dialog.SelectedPath, folderName);Directory.CreateDirectory(outputDir);// 获取所有DWG文件var dwgFiles = Directory.GetFiles(dialog.SelectedPath, "*.dwg");try{foreach (string file in dwgFiles){string newPath = Path.Combine(outputDir, Path.GetFileName(file));//***省略部分代码try{// 打开 DWG 文件var doc = acadApp.Documents.Open(file);// 保存文档doc.SaveAs(newPath);// 关闭文档doc.Close();ed.WriteMessage($"处理完成: {file}\n");}catch (Exception ex){ed.WriteMessage($"处理文件 {file} 时出错: {ex.Message}\n");}}}catch (Exception ex){// 捕获并处理异常MessageBox.Show($"处理过程中出现错误: {ex.Message}");}MessageBox.Show("处理完成");}private string GetUniqueFolder(string basePath,string folderName){int counter = 0;string path;do{path = Path.Combine(basePath, counter == 0 ? folderName : $"{folderName}_{counter++}");counter++;} while (Directory.Exists(path));return path;}}
}