增加检验类别的值填写
This commit is contained in:
parent
3e4a925c8c
commit
e53b335205
@ -1604,5 +1604,91 @@ namespace CadParamPluging.Cad
|
||||
|
||||
return $"1:{ratio:F1}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新图纸标题栏中的检验类别 - 查找"检验类别"标题文字并在其下方创建检验类别值文本
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user