如果,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;}}
}
?