diff --git a/MainWindow.xaml b/MainWindow.xaml
index 9708447..7d58398 100644
--- a/MainWindow.xaml
+++ b/MainWindow.xaml
@@ -193,6 +193,23 @@
+
diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs
index bebf957..212048a 100644
--- a/MainWindow.xaml.cs
+++ b/MainWindow.xaml.cs
@@ -1733,6 +1733,88 @@ namespace DwgExtractorManual
}
}
+ ///
+ /// DWG μΆμΆ (Height μ λ ¬) λ²νΌ ν΄λ¦ μ΄λ²€νΈ
+ ///
+ private async void BtnDwgHeightSort_Click(object sender, RoutedEventArgs e)
+ {
+ try
+ {
+ // κ²½λ‘ κ²μ¦
+ string sourceFolder = txtSourceFolder.Text;
+ string resultFolder = txtResultFolder.Text;
+
+ if (string.IsNullOrWhiteSpace(sourceFolder) || !Directory.Exists(sourceFolder))
+ {
+ ShowMessageBox("μ¬λ°λ₯Έ μμ€ ν΄λλ₯Ό μ νν΄μ£ΌμΈμ.", "κ²½λ‘ μ€λ₯", MessageBoxButton.OK, MessageBoxImage.Warning);
+ return;
+ }
+
+ if (string.IsNullOrWhiteSpace(resultFolder) || !Directory.Exists(resultFolder))
+ {
+ ShowMessageBox("μ¬λ°λ₯Έ κ²°κ³Ό μ μ₯ ν΄λλ₯Ό μ νν΄μ£ΌμΈμ.", "κ²½λ‘ μ€λ₯", MessageBoxButton.OK, MessageBoxImage.Warning);
+ return;
+ }
+
+ // 리ν ν΄λ μ°ΎκΈ°
+ var leafFolders = FindLeafFolders(sourceFolder);
+ if (leafFolders.Count == 0)
+ {
+ ShowMessageBox("μ²λ¦¬ν 리ν ν΄λκ° μμ΅λλ€.", "μ 보", MessageBoxButton.OK, MessageBoxImage.Information);
+ return;
+ }
+
+ LogMessage($"π λ°κ²¬λ 리ν ν΄λ: {leafFolders.Count}κ°");
+ foreach (var folder in leafFolders)
+ {
+ LogMessage($" - {folder}");
+ }
+
+ // μ¬μ©μ νμΈ
+ var result = ShowConfirmationDialog(
+ $"μ΄ {leafFolders.Count}κ°μ 리ν ν΄λμμ DWG Height μ λ ¬ μΆμΆμ νμκ² μ΅λκΉ?\n\n" +
+ "κ° ν΄λλ§λ€ DWG νμΌλ³λ‘ μνΈκ° μμ±λκ³ , ν
μ€νΈ λμ΄ μμΌλ‘ μ λ ¬λ Excel νμΌμ΄ μμ±λ©λλ€.",
+ "DWG Height μ λ ¬ μΆμΆ νμΈ");
+
+ if (result != MessageBoxResult.Yes)
+ {
+ return;
+ }
+
+ // UI μν λ³κ²½
+ SetButtonsEnabled(false);
+ progressBar.Value = 0;
+ UpdateStatus("π DWG Height μ λ ¬ μΆμΆ μμ...");
+
+ // μλ μ²λ¦¬ λͺ¨λ νμ±ν
+ isAutoProcessing = true;
+
+ await ProcessLeafFoldersDwgHeightSort(leafFolders, resultFolder);
+
+ ShowMessageBox(
+ $"DWG Height μ λ ¬ μΆμΆμ΄ μλ£λμμ΅λλ€!\n\n" +
+ $"μ²λ¦¬λ ν΄λ: {leafFolders.Count}κ°\n" +
+ $"κ²°κ³Ό μ μ₯ μμΉ: {resultFolder}",
+ "μλ£",
+ MessageBoxButton.OK,
+ MessageBoxImage.Information);
+ }
+ catch (Exception ex)
+ {
+ LogMessage($"β DWG Height μ λ ¬ μΆμΆ μ€ μ€λ₯: {ex.Message}");
+ ShowMessageBox($"DWG Height μ λ ¬ μΆμΆ μ€ μ€λ₯κ° λ°μνμ΅λλ€:\n{ex.Message}", "μ€λ₯", MessageBoxButton.OK, MessageBoxImage.Error);
+ }
+ finally
+ {
+ SetButtonsEnabled(true);
+ progressBar.Value = 0;
+ UpdateStatus("β
μ€λΉ");
+
+ // μλ μ²λ¦¬ λͺ¨λ λΉνμ±ν
+ isAutoProcessing = false;
+ }
+ }
+
///
/// ν΄λμμ 리ν ν΄λλ€(νμ ν΄λκ° μλ ν΄λ)μ μ¬κ·μ μΌλ‘ μ°Ύμ΅λλ€.
///
@@ -1935,6 +2017,114 @@ namespace DwgExtractorManual
UpdateStatus("β
DWG μ μ© μΆμΆ μλ£");
}
+ ///
+ /// DWG Height μ λ ¬ μ²λ¦¬λ₯Ό μν 리ν ν΄λ μ²λ¦¬
+ ///
+ /// μ²λ¦¬ν 리ν ν΄λ λͺ©λ‘
+ /// κ²°κ³Ό μ μ₯ κΈ°λ³Έ ν΄λ
+ private async Task ProcessLeafFoldersDwgHeightSort(List leafFolders, string resultBaseFolder)
+ {
+ int totalFolders = leafFolders.Count;
+ LogMessage($"π DWG Height μ λ ¬ μΆμΆ μμ: {totalFolders}κ° ν΄λ");
+
+ try
+ {
+ // λͺ¨λ ν΄λμ DWG νμΌμ μμ§
+ var allDwgFiles = new List<(string filePath, string folderName)>();
+
+ for (int i = 0; i < leafFolders.Count; i++)
+ {
+ string leafFolder = leafFolders[i];
+ progressBar.Value = (double)(i + 1) / totalFolders * 50; // 첫 50%λ νμΌ μμ§μ©
+
+ LogMessage($"π [{i + 1}/{totalFolders}] ν΄λ μ€μΊ μ€: {leafFolder}");
+
+ var dwgFiles = Directory.GetFiles(leafFolder, "*.dwg", SearchOption.TopDirectoryOnly);
+ string folderName = Path.GetFileName(leafFolder);
+
+ foreach (var dwgFile in dwgFiles)
+ {
+ allDwgFiles.Add((dwgFile, folderName));
+ }
+
+ LogMessage($"π [{i + 1}/{totalFolders}] λ°κ²¬λ DWG νμΌ: {dwgFiles.Length}κ°");
+
+ // UI μλ΅μ±μ μν μ보
+ await Task.Yield();
+ }
+
+ LogMessage($"π μ΄ λ°κ²¬λ DWG νμΌ: {allDwgFiles.Count}κ°");
+
+ if (allDwgFiles.Count > 0)
+ {
+ // λ¨μΌ Excel νμΌμ λͺ¨λ DWG νμΌ μ²λ¦¬
+ LogMessage("π λ¨μΌ Height μ λ ¬ Excel νμΌ μμ± μ€...");
+ await ProcessAllFilesDwgHeightSort(allDwgFiles, resultBaseFolder);
+ LogMessage("β
Height μ λ ¬ Excel νμΌ μμ± μλ£");
+ }
+ else
+ {
+ LogMessage("β οΈ μ²λ¦¬ν DWG νμΌμ΄ μμ΅λλ€.");
+ }
+
+ progressBar.Value = 100;
+ }
+ catch (Exception ex)
+ {
+ LogMessage($"β DWG Height μ λ ¬ μΆμΆ μ€ μ€λ₯: {ex.Message}");
+ throw;
+ }
+
+ LogMessage($"π DWG Height μ λ ¬ μΆμΆ μλ£! μ΄ {totalFolders}κ° ν΄λ μ²λ¦¬λ¨");
+ UpdateStatus("β
DWG Height μ λ ¬ μΆμΆ μλ£");
+ }
+
+ ///
+ /// λͺ¨λ DWG νμΌμ λ¨μΌ Excel νμΌμμ Height μ λ ¬νμ¬ μ²λ¦¬ν©λλ€.
+ ///
+ /// λͺ¨λ DWG νμΌ μ 보 (νμΌκ²½λ‘, ν΄λλͺ
)
+ /// κ²°κ³Ό ν΄λ
+ private async Task ProcessAllFilesDwgHeightSort(List<(string filePath, string folderName)> allDwgFiles, string resultFolder)
+ {
+ ExportExcel exportExcel = null;
+ try
+ {
+ LogMessage($"π μ΄ DWG νμΌ μ: {allDwgFiles.Count}κ°");
+ LogMessage($"π μΆλ ₯ λͺ¨λ: Excel (Height μ λ ¬)");
+ LogMessage($"πΎ κ²°κ³Ό ν΄λ: {resultFolder}");
+
+ LogMessage("π Excel Height μ λ ¬ λ΄λ³΄λ΄κΈ° λͺ¨λλ‘ μμν©λλ€...");
+ LogMessage("π Excel μ ν리μΌμ΄μ
μ μ΄κΈ°νν©λλ€...");
+
+ exportExcel = new ExportExcel();
+
+ // UI μλ΅μ±μ μν μ보
+ await Task.Yield();
+
+ // Height μ λ ¬λ Excel νμΌ μμ±
+ LogMessage("π Height μ λ ¬ Excel νμΌ μμ± μ€...");
+
+ // λ¨μΌ νμμ€ν¬νλ‘ νμΌλͺ
μμ±
+ string timestamp = DateTime.Now.ToString("yyyyMMdd_HHmmss");
+ string savePath = Path.Combine(resultFolder, $"{timestamp}_AllDWG_HeightSorted.xlsx");
+
+ exportExcel.ExportAllDwgToExcelHeightSorted(allDwgFiles, savePath);
+
+ LogMessage("β
Height μ λ ¬ Excel νμΌ μμ± μλ£");
+ LogMessage($"π μ μ₯λ νμΌ: {Path.GetFileName(savePath)}");
+ }
+ catch (Exception ex)
+ {
+ LogMessage($"β DWG Height μ λ ¬ μ²λ¦¬ μ€ μΉλͺ
μ μ€λ₯: {ex.Message}");
+ throw;
+ }
+ finally
+ {
+ exportExcel?.Dispose();
+ exportExcel = null;
+ }
+ }
+
///
/// μ§μ λ ν΄λμμ DWG νμΌλ€λ§ μ²λ¦¬ν©λλ€.
///
@@ -2044,6 +2234,104 @@ namespace DwgExtractorManual
}
}
+ ///
+ /// μ§μ λ ν΄λμμ DWG νμΌλ€μ Height μ λ ¬νμ¬ μ²λ¦¬ν©λλ€.
+ ///
+ /// μ²λ¦¬ν ν΄λ κ²½λ‘
+ private async Task ProcessFilesDwgHeightSort(string sourceFolderPath)
+ {
+ ExportExcel exportExcel = null;
+ try
+ {
+ string resultFolder = txtResultFolder.Text;
+
+ if (!Directory.Exists(sourceFolderPath))
+ {
+ LogMessage($"β μμ€ ν΄λκ° μ‘΄μ¬νμ§ μμ΅λλ€: {sourceFolderPath}");
+ return;
+ }
+
+ var dwgFiles = Directory.GetFiles(sourceFolderPath, "*.dwg", SearchOption.TopDirectoryOnly);
+
+ if (dwgFiles.Length == 0)
+ {
+ LogMessage($"π μ²λ¦¬ν DWG νμΌμ΄ μμ΅λλ€: {sourceFolderPath}");
+ return;
+ }
+
+ LogMessage($"π μ²λ¦¬ν DWG νμΌ μ: {dwgFiles.Length}κ°");
+ LogMessage($"π μΆλ ₯ λͺ¨λ: Excel (Height μ λ ¬)");
+ LogMessage($"π μμ€ ν΄λ: {sourceFolderPath}");
+ LogMessage($"πΎ κ²°κ³Ό ν΄λ: {resultFolder}");
+
+ LogMessage("π Excel Height μ λ ¬ λ΄λ³΄λ΄κΈ° λͺ¨λλ‘ μμν©λλ€...");
+ LogMessage("π Excel μ ν리μΌμ΄μ
μ μ΄κΈ°νν©λλ€...");
+
+ exportExcel = new ExportExcel();
+
+ // UI μλ΅μ±μ μν μ보
+ await Task.Yield();
+
+ // Height μ λ ¬λ Excel νμΌ μμ±
+ LogMessage("π Height μ λ ¬ Excel νμΌ μμ± μ€...");
+ exportExcel.ExportDwgToExcelHeightSorted(dwgFiles, resultFolder);
+
+ LogMessage("β
Height μ λ ¬ Excel νμΌ μμ± μλ£");
+ }
+ catch (Exception ex)
+ {
+ LogMessage($"β DWG Height μ λ ¬ μ²λ¦¬ μ€ μΉλͺ
μ μ€λ₯: {ex.Message}");
+ throw;
+ }
+ finally
+ {
+ exportExcel?.Dispose();
+ exportExcel = null;
+ }
+ }
+
+ ///
+ /// DWG Height μ λ ¬ Excel νμΌμ λͺ©ν κ²½λ‘λ‘ μ΄λ¦ λ³κ²½
+ ///
+ /// κ²°κ³Ό ν΄λ
+ /// 리ν ν΄λ κ²½λ‘
+ private async Task RenameDwgHeightSortExcelFile(string resultFolder, string leafFolderPath)
+ {
+ try
+ {
+ // μ΅μ *_HeightSorted.xlsx νμΌ μ°ΎκΈ°
+ var excelFiles = Directory.GetFiles(resultFolder, "*_HeightSorted.xlsx")
+ .Where(f => !Path.GetFileName(f).StartsWith("~$"))
+ .OrderByDescending(f => File.GetCreationTime(f))
+ .ToList();
+
+ if (excelFiles.Any())
+ {
+ string latestFile = excelFiles.First();
+
+ // 리ν ν΄λ κ²½λ‘λ₯Ό κΈ°λ°μΌλ‘ νμΌλͺ
μμ±
+ string relativePath = Path.GetRelativePath(txtSourceFolder.Text, leafFolderPath);
+ string safePath = relativePath.Replace('\\', '_').Replace('/', '_').Replace(':', '_');
+ string targetFileName = $"{safePath}_HeightSorted.xlsx";
+ string targetPath = Path.Combine(resultFolder, targetFileName);
+
+ // λͺ©ν νμΌμ΄ μ΄λ―Έ μ‘΄μ¬νλ©΄ μμ
+ if (File.Exists(targetPath))
+ {
+ File.Delete(targetPath);
+ }
+
+ // νμΌ μ΄λ¦ λ³κ²½
+ File.Move(latestFile, targetPath);
+ LogMessage($"π Height μ λ ¬ Excel νμΌ μ΄λ¦ λ³κ²½λ¨: {targetFileName}");
+ }
+ }
+ catch (Exception ex)
+ {
+ LogMessage($"β οΈ Height μ λ ¬ Excel νμΌ μ΄λ¦ λ³κ²½ μ€ν¨: {ex.Message}");
+ }
+ }
+
///
/// μ΅μ Excel νμΌμ λͺ©ν κ²½λ‘λ‘ μ΄λ¦ λ³κ²½
///
diff --git a/Models/ExportExcel.cs b/Models/ExportExcel.cs
index bd69ac5..c3a2e33 100644
--- a/Models/ExportExcel.cs
+++ b/Models/ExportExcel.cs
@@ -329,6 +329,7 @@ namespace DwgExtractorManual.Models
titleBlockSheet.Cells[titleBlockCurrentRow, 5] = attRef.TextString;
titleBlockSheet.Cells[titleBlockCurrentRow, 6] = database.Filename;
titleBlockSheet.Cells[titleBlockCurrentRow, 7] = Path.GetFileName(database.Filename);
+
titleBlockCurrentRow++;
var tag = attRef.Tag;
@@ -373,6 +374,7 @@ namespace DwgExtractorManual.Models
textEntitiesSheet.Cells[textEntitiesCurrentRow, 3] = dbText.TextString; // Text
textEntitiesSheet.Cells[textEntitiesCurrentRow, 4] = database.Filename; // Path
textEntitiesSheet.Cells[textEntitiesCurrentRow, 5] = Path.GetFileName(database.Filename); // FileName
+
textEntitiesCurrentRow++;
}
// MText μν°ν° μΆμΆ (λ³λ μνΈ)
@@ -383,6 +385,7 @@ namespace DwgExtractorManual.Models
textEntitiesSheet.Cells[textEntitiesCurrentRow, 3] = mText.Contents; // Text
textEntitiesSheet.Cells[textEntitiesCurrentRow, 4] = database.Filename; // Path
textEntitiesSheet.Cells[textEntitiesCurrentRow, 5] = Path.GetFileName(database.Filename); // FileName
+
textEntitiesCurrentRow++;
}
}
@@ -1532,6 +1535,392 @@ namespace DwgExtractorManual.Models
}
}
+ ///
+ /// DWG νμΌλ€μ μ²λ¦¬νμ¬ κ° νμΌλ³λ‘ μνΈλ₯Ό μμ±νκ³ Height μμΌλ‘ μ λ ¬λ Excel νμΌμ μμ±ν©λλ€.
+ ///
+ /// μ²λ¦¬ν DWG νμΌ κ²½λ‘ λ°°μ΄
+ /// κ²°κ³Ό νμΌ μ μ₯ ν΄λ
+ public void ExportDwgToExcelHeightSorted(string[] dwgFiles, string resultFolder)
+ {
+ try
+ {
+ Debug.WriteLine($"[DEBUG] Height μ λ ¬ Excel μμ± μμ: {dwgFiles.Length}κ° νμΌ");
+
+ string timestamp = DateTime.Now.ToString("yyyyMMdd_HHmmss");
+ string savePath = Path.Combine(resultFolder, $"{timestamp}_HeightSorted.xlsx");
+
+ // μλ‘μ΄ Excel μν¬λΆ μμ±
+ if (excelApplication == null)
+ {
+ excelApplication = new Excel.Application();
+ excelApplication.Visible = false;
+ }
+
+ var heightSortedWorkbook = excelApplication.Workbooks.Add();
+
+ Debug.WriteLine($"[DEBUG] DWG νμΌ μ²λ¦¬ μμ");
+
+ bool firstSheetProcessed = false;
+
+ foreach (string dwgFile in dwgFiles)
+ {
+ if (!File.Exists(dwgFile))
+ {
+ Debug.WriteLine($"[DEBUG] νμΌμ΄ μ‘΄μ¬νμ§ μμ: {dwgFile}");
+ continue;
+ }
+
+ string fileName = Path.GetFileNameWithoutExtension(dwgFile);
+ Debug.WriteLine($"[DEBUG] μ²λ¦¬ μ€μΈ νμΌ: {fileName}");
+
+ try
+ {
+ Excel.Worksheet worksheet;
+ if (!firstSheetProcessed)
+ {
+ // 첫 λ²μ§Έ νμΌμ κΈ°λ³Έ μνΈ μ¬μ©
+ worksheet = (Excel.Worksheet)heightSortedWorkbook.Worksheets[1];
+ firstSheetProcessed = true;
+ }
+ else
+ {
+ // μ΄ν νμΌλ€μ μ μνΈ μμ±
+ worksheet = (Excel.Worksheet)heightSortedWorkbook.Worksheets.Add();
+ }
+ worksheet.Name = GetValidSheetName(fileName);
+
+ // ν€λ μ€μ
+ worksheet.Cells[1, 1] = "Height";
+ worksheet.Cells[1, 2] = "Type";
+ worksheet.Cells[1, 3] = "Layer";
+ worksheet.Cells[1, 4] = "Tag";
+ worksheet.Cells[1, 5] = "FileName";
+ worksheet.Cells[1, 6] = "Text";
+
+ // ν€λ μ€νμΌ μ μ©
+ var headerRange = worksheet.Range["A1:F1"];
+ headerRange.Font.Bold = true;
+ headerRange.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.LightBlue);
+
+ // DWG νμΌμμ ν
μ€νΈ μν°ν° μΆμΆ
+ var textEntities = ExtractTextEntitiesWithHeight(dwgFile);
+
+ // Height μμΌλ‘ λ΄λ¦Όμ°¨μ μ λ ¬
+ var sortedEntities = textEntities.OrderByDescending(entity => entity.Height).ToList();
+
+ Debug.WriteLine($"[DEBUG] {fileName}: {sortedEntities.Count}κ° ν
μ€νΈ μν°ν° μΆμΆλ¨");
+
+ // λ°μ΄ν° μ
λ ₯
+ int row = 2;
+ foreach (var entity in sortedEntities)
+ {
+ worksheet.Cells[row, 1] = entity.Height;
+ worksheet.Cells[row, 2] = entity.Type;
+ worksheet.Cells[row, 3] = entity.Layer;
+ worksheet.Cells[row, 4] = entity.Tag;
+ worksheet.Cells[row, 5] = fileName;
+ worksheet.Cells[row, 6] = entity.Text;
+ row++;
+ }
+
+ // μ»¬λΌ μλ ν¬κΈ° μ‘°μ
+ worksheet.Columns.AutoFit();
+
+ Debug.WriteLine($"[DEBUG] {fileName} μνΈ μλ£: {sortedEntities.Count}κ° ν");
+ }
+ catch (System.Exception ex)
+ {
+ Debug.WriteLine($"β {fileName} μ²λ¦¬ μ€ μ€λ₯: {ex.Message}");
+ continue;
+ }
+ }
+
+ // DWG νμΌμ΄ νλλ μμλ€λ©΄ κΈ°λ³Έ μνΈμ λ©μμ§ μΆκ°
+ if (!firstSheetProcessed)
+ {
+ var defaultSheet = (Excel.Worksheet)heightSortedWorkbook.Worksheets[1];
+ defaultSheet.Name = "No_DWG_Files";
+ defaultSheet.Cells[1, 1] = "No DWG files found in this folder";
+ Debug.WriteLine("[DEBUG] DWG νμΌμ΄ μμ΄ κΈ°λ³Έ λ©μμ§ μνΈ μμ±");
+ }
+
+ // νμΌ μ μ₯
+ string directory = Path.GetDirectoryName(savePath);
+ if (!string.IsNullOrEmpty(directory) && !Directory.Exists(directory))
+ {
+ Directory.CreateDirectory(directory);
+ }
+
+ heightSortedWorkbook.SaveAs(savePath,
+ FileFormat: Excel.XlFileFormat.xlOpenXMLWorkbook,
+ AccessMode: Excel.XlSaveAsAccessMode.xlNoChange);
+
+ Debug.WriteLine($"β
Height μ λ ¬ Excel νμΌ μ μ₯ μλ£: {Path.GetFileName(savePath)}");
+
+ // μν¬λΆ μ 리
+ heightSortedWorkbook.Close(false);
+ ReleaseComObject(heightSortedWorkbook);
+
+ GC.Collect();
+ GC.WaitForPendingFinalizers();
+ }
+ catch (System.Exception ex)
+ {
+ Debug.WriteLine($"β Height μ λ ¬ Excel μμ± μ€ μ€λ₯: {ex.Message}");
+ Debug.WriteLine($" μ€ν νΈλ μ΄μ€: {ex.StackTrace}");
+ throw;
+ }
+ }
+
+ ///
+ /// DWG νμΌμμ ν
μ€νΈ μν°ν°λ€μ μΆμΆνμ¬ Height μ 보μ ν¨κ» λ°νν©λλ€.
+ ///
+ /// DWG νμΌ κ²½λ‘
+ /// ν
μ€νΈ μν°ν° μ 보 리μ€νΈ
+ private List ExtractTextEntitiesWithHeight(string filePath)
+ {
+ var textEntities = new List();
+
+ try
+ {
+ using (var database = new Database(false, true))
+ {
+ database.ReadDwgFile(filePath, FileOpenMode.OpenForReadAndWriteNoShare, false, null);
+
+ using (var tran = database.TransactionManager.StartTransaction())
+ {
+ var bt = tran.GetObject(database.BlockTableId, OpenMode.ForRead) as BlockTable;
+ using (var btr = tran.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead) as BlockTableRecord)
+ {
+ foreach (ObjectId entId in btr)
+ {
+ using (var ent = tran.GetObject(entId, OpenMode.ForRead) as Entity)
+ {
+ string layerName = GetLayerName(ent.LayerId, tran, database);
+
+ // AttributeReference μ²λ¦¬
+ if (ent is BlockReference blr)
+ {
+ foreach (ObjectId attId in blr.AttributeCollection)
+ {
+ using (var attRef = tran.GetObject(attId, OpenMode.ForRead) as AttributeReference)
+ {
+ if (attRef != null && !string.IsNullOrWhiteSpace(attRef.TextString))
+ {
+ textEntities.Add(new TextEntityInfo
+ {
+ Height = attRef.Height,
+ Type = "AttRef",
+ Layer = layerName,
+ Tag = attRef.Tag,
+ Text = attRef.TextString
+ });
+ }
+ }
+ }
+ }
+ // DBText μ²λ¦¬
+ else if (ent is DBText dbText)
+ {
+ textEntities.Add(new TextEntityInfo
+ {
+ Height = dbText.Height,
+ Type = "DBText",
+ Layer = layerName,
+ Tag = "",
+ Text = dbText.TextString
+ });
+ }
+ // MText μ²λ¦¬
+ else if (ent is MText mText)
+ {
+ textEntities.Add(new TextEntityInfo
+ {
+ Height = mText.Height,
+ Type = "MText",
+ Layer = layerName,
+ Tag = "",
+ Text = mText.Contents
+ });
+ }
+ }
+ }
+ }
+
+ tran.Commit();
+ }
+ }
+ }
+ catch (System.Exception ex)
+ {
+ Debug.WriteLine($"β ν
μ€νΈ μν°ν° μΆμΆ μ€ μ€λ₯ ({Path.GetFileName(filePath)}): {ex.Message}");
+ }
+
+ return textEntities;
+ }
+
+ ///
+ /// λͺ¨λ DWG νμΌλ€μ νλμ Excel νμΌλ‘ μ²λ¦¬νμ¬ κ° νμΌλ³λ‘ μνΈλ₯Ό μμ±νκ³ Height μμΌλ‘ μ λ ¬ν©λλ€.
+ ///
+ /// μ²λ¦¬ν DWG νμΌ λ¦¬μ€νΈ (νμΌκ²½λ‘, ν΄λλͺ
)
+ /// κ²°κ³Ό Excel νμΌ μ μ₯ κ²½λ‘
+ public void ExportAllDwgToExcelHeightSorted(List<(string filePath, string folderName)> allDwgFiles, string savePath)
+ {
+ try
+ {
+ Debug.WriteLine($"[DEBUG] λ¨μΌ Excel νμΌλ‘ Height μ λ ¬ μμ± μμ: {allDwgFiles.Count}κ° νμΌ");
+
+ // μλ‘μ΄ Excel μν¬λΆ μμ±
+ if (excelApplication == null)
+ {
+ excelApplication = new Excel.Application();
+ excelApplication.Visible = false;
+ }
+
+ var heightSortedWorkbook = excelApplication.Workbooks.Add();
+
+ Debug.WriteLine($"[DEBUG] DWG νμΌ μ²λ¦¬ μμ");
+
+ bool firstSheetProcessed = false;
+
+ foreach (var (filePath, folderName) in allDwgFiles)
+ {
+ if (!File.Exists(filePath))
+ {
+ Debug.WriteLine($"[DEBUG] νμΌμ΄ μ‘΄μ¬νμ§ μμ: {filePath}");
+ continue;
+ }
+
+ string fileName = Path.GetFileNameWithoutExtension(filePath);
+ Debug.WriteLine($"[DEBUG] μ²λ¦¬ μ€μΈ νμΌ: {fileName} (ν΄λ: {folderName})");
+
+ try
+ {
+ Excel.Worksheet worksheet;
+ if (!firstSheetProcessed)
+ {
+ // 첫 λ²μ§Έ νμΌμ κΈ°λ³Έ μνΈ μ¬μ©
+ worksheet = (Excel.Worksheet)heightSortedWorkbook.Worksheets[1];
+ firstSheetProcessed = true;
+ }
+ else
+ {
+ // μ΄ν νμΌλ€μ μ μνΈ μμ±
+ worksheet = (Excel.Worksheet)heightSortedWorkbook.Worksheets.Add();
+ }
+ worksheet.Name = GetValidSheetName(fileName);
+
+ // ν€λ μ€μ
+ worksheet.Cells[1, 1] = "Height";
+ worksheet.Cells[1, 2] = "Type";
+ worksheet.Cells[1, 3] = "Layer";
+ worksheet.Cells[1, 4] = "Tag";
+ worksheet.Cells[1, 5] = "FileName";
+ worksheet.Cells[1, 6] = "Text";
+
+ // ν€λ μ€νμΌ μ μ©
+ var headerRange = worksheet.Range["A1:F1"];
+ headerRange.Font.Bold = true;
+ headerRange.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.LightBlue);
+
+ // DWG νμΌμμ ν
μ€νΈ μν°ν° μΆμΆ
+ var textEntities = ExtractTextEntitiesWithHeight(filePath);
+
+ // Height μμΌλ‘ λ΄λ¦Όμ°¨μ μ λ ¬
+ var sortedEntities = textEntities.OrderByDescending(entity => entity.Height).ToList();
+
+ Debug.WriteLine($"[DEBUG] {fileName}: {sortedEntities.Count}κ° ν
μ€νΈ μν°ν° μΆμΆλ¨");
+
+ // λ°μ΄ν° μ
λ ₯
+ int row = 2;
+ foreach (var entity in sortedEntities)
+ {
+ worksheet.Cells[row, 1] = entity.Height;
+ worksheet.Cells[row, 2] = entity.Type;
+ worksheet.Cells[row, 3] = entity.Layer;
+ worksheet.Cells[row, 4] = entity.Tag;
+ worksheet.Cells[row, 5] = fileName;
+ worksheet.Cells[row, 6] = entity.Text;
+ row++;
+ }
+
+ // μ»¬λΌ μλ ν¬κΈ° μ‘°μ
+ worksheet.Columns.AutoFit();
+
+ Debug.WriteLine($"[DEBUG] {fileName} μνΈ μλ£: {sortedEntities.Count}κ° ν");
+ }
+ catch (System.Exception ex)
+ {
+ Debug.WriteLine($"β {fileName} μ²λ¦¬ μ€ μ€λ₯: {ex.Message}");
+ continue;
+ }
+ }
+
+ // DWG νμΌμ΄ νλλ μμλ€λ©΄ κΈ°λ³Έ μνΈμ λ©μμ§ μΆκ°
+ if (!firstSheetProcessed)
+ {
+ var defaultSheet = (Excel.Worksheet)heightSortedWorkbook.Worksheets[1];
+ defaultSheet.Name = "No_DWG_Files";
+ defaultSheet.Cells[1, 1] = "No DWG files found in any folder";
+ Debug.WriteLine("[DEBUG] DWG νμΌμ΄ μμ΄ κΈ°λ³Έ λ©μμ§ μνΈ μμ±");
+ }
+
+ // νμΌ μ μ₯
+ string directory = Path.GetDirectoryName(savePath);
+ if (!string.IsNullOrEmpty(directory) && !Directory.Exists(directory))
+ {
+ Directory.CreateDirectory(directory);
+ }
+
+ heightSortedWorkbook.SaveAs(savePath,
+ FileFormat: Excel.XlFileFormat.xlOpenXMLWorkbook,
+ AccessMode: Excel.XlSaveAsAccessMode.xlNoChange);
+
+ Debug.WriteLine($"β
λ¨μΌ Height μ λ ¬ Excel νμΌ μ μ₯ μλ£: {Path.GetFileName(savePath)}");
+
+ // μν¬λΆ μ 리
+ heightSortedWorkbook.Close(false);
+ ReleaseComObject(heightSortedWorkbook);
+
+ GC.Collect();
+ GC.WaitForPendingFinalizers();
+ }
+ catch (System.Exception ex)
+ {
+ Debug.WriteLine($"β λ¨μΌ Height μ λ ¬ Excel μμ± μ€ μ€λ₯: {ex.Message}");
+ Debug.WriteLine($" μ€ν νΈλ μ΄μ€: {ex.StackTrace}");
+ throw;
+ }
+ }
+
+ ///
+ /// Excel μνΈλͺ
μΌλ‘ μ¬μ©ν μ μλ μ ν¨ν μ΄λ¦μ μμ±ν©λλ€.
+ ///
+ /// μλ³Έ νμΌλͺ
+ /// μ ν¨ν μνΈλͺ
+ private string GetValidSheetName(string originalName)
+ {
+ if (string.IsNullOrEmpty(originalName))
+ return "Sheet";
+
+ // Excel μνΈλͺ
μμ νμ©λμ§ μλ λ¬Έμ μ κ±°
+ string validName = originalName;
+ char[] invalidChars = { '\\', '/', '?', '*', '[', ']', ':' };
+
+ foreach (char c in invalidChars)
+ {
+ validName = validName.Replace(c, '_');
+ }
+
+ // 31μλ‘ μ ν (Excel μνΈλͺ
μ΅λ κΈΈμ΄)
+ if (validName.Length > 31)
+ {
+ validName = validName.Substring(0, 31);
+ }
+
+ return validName;
+ }
+
public void Dispose()
{
try
@@ -1571,4 +1960,16 @@ namespace DwgExtractorManual.Models
}
}
}
+
+ ///
+ /// ν
μ€νΈ μν°ν° μ 보λ₯Ό λ΄λ ν΄λμ€
+ ///
+ public class TextEntityInfo
+ {
+ public double Height { get; set; }
+ public string Type { get; set; }
+ public string Layer { get; set; }
+ public string Tag { get; set; }
+ public string Text { get; set; }
+ }
}