From e53b3352054f3c7ca169a660c11c401cfd4ebe51 Mon Sep 17 00:00:00 2001 From: sladro Date: Thu, 18 Dec 2025 15:41:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=A3=80=E9=AA=8C=E7=B1=BB?= =?UTF-8?q?=E5=88=AB=E7=9A=84=E5=80=BC=E5=A1=AB=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cad/TemplateDrawingService.cs | 86 +++++++++++++++++++++++++++++++++++ UI/ParamDrawingPanel.cs | 20 ++++++++ 2 files changed, 106 insertions(+) diff --git a/Cad/TemplateDrawingService.cs b/Cad/TemplateDrawingService.cs index f75cfbf..2b98a26 100644 --- a/Cad/TemplateDrawingService.cs +++ b/Cad/TemplateDrawingService.cs @@ -1604,5 +1604,91 @@ namespace CadParamPluging.Cad return $"1:{ratio:F1}"; } + + /// + /// 更新图纸标题栏中的检验类别 - 查找"检验类别"标题文字并在其下方创建检验类别值文本 + /// + public static bool UpdateInspectionCategoryAttribute(CadContext ctx, string layoutName, bool scanModelSpace, string inspectionCategory) + { + if (ctx == null || string.IsNullOrWhiteSpace(inspectionCategory)) + { + return false; + } + + var db = ctx.Database; + var tr = ctx.Transaction; + + var bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead); + var ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); + + Point3d? labelPos = null; + double textHeight = 2.5; + string textStyle = "STANDARD"; + + foreach (ObjectId id in ms) + { + var ent = tr.GetObject(id, OpenMode.ForRead, false) as Entity; + if (ent == null) + { + continue; + } + + if (ent is DBText dbText) + { + var content = dbText.TextString?.Trim() ?? string.Empty; + var contentNoSpace = content.Replace(" ", "").Replace(" ", ""); + if (contentNoSpace == "检验类别") + { + labelPos = dbText.Position; + textHeight = dbText.Height; + textStyle = dbText.TextStyleName ?? "STANDARD"; + break; + } + } + else if (ent is MText mText) + { + var content = mText.Contents?.Trim() ?? string.Empty; + var contentNoSpace = content.Replace(" ", "").Replace(" ", ""); + if (contentNoSpace == "检验类别") + { + labelPos = mText.Location; + textHeight = mText.TextHeight; + textStyle = mText.TextStyleName ?? "STANDARD"; + break; + } + } + } + + if (!labelPos.HasValue) + { + return false; + } + + var valuePos = new Point3d( + labelPos.Value.X, + labelPos.Value.Y - textHeight * 2.5, + labelPos.Value.Z + ); + + var newText = new DBText + { + Position = valuePos, + TextString = inspectionCategory, + Height = textHeight, + ColorIndex = 7, + Layer = "0" + }; + + var textStyleTbl = (TextStyleTable)tr.GetObject(db.TextStyleTableId, OpenMode.ForRead); + if (textStyleTbl.Has(textStyle)) + { + newText.TextStyleId = textStyleTbl[textStyle]; + } + + ms.AppendEntity(newText); + tr.AddNewlyCreatedDBObject(newText, true); + + return true; + } } } diff --git a/UI/ParamDrawingPanel.cs b/UI/ParamDrawingPanel.cs index e4f84a3..7f712fa 100644 --- a/UI/ParamDrawingPanel.cs +++ b/UI/ParamDrawingPanel.cs @@ -689,6 +689,26 @@ namespace CadParamPluging.UI AppendLog("未找到标题栏中的'比例'文字,无法更新比例"); } + // 更新标题栏中的检验类别 + var inspectionCategory = bag.GetString("InspectionCategory"); + if (!string.IsNullOrWhiteSpace(inspectionCategory)) + { + var categoryUpdated = TemplateDrawingService.UpdateInspectionCategoryAttribute( + ctx, + _selectedTemplate.LayoutName, + _selectedModelWindow.HasValue, + inspectionCategory + ); + if (categoryUpdated) + { + AppendLog($"已更新标题栏检验类别: {inspectionCategory}"); + } + else + { + AppendLog("未找到标题栏中的'检验类别'文字,无法更新检验类别"); + } + } + ctx.Commit(); }