修改线宽
This commit is contained in:
parent
8f51b53f5b
commit
7bc3a7732a
@ -57,13 +57,13 @@ namespace CadParamPluging.Cad
|
||||
case Role.OutlineBold:
|
||||
return new LayerSpec { LayerName = "粗实线", DefaultLinetypeName = "Continuous", DefaultLineWeight = LineWeight.LineWeight050, DefaultColorIndex = 7 };
|
||||
case Role.PartContour:
|
||||
return new LayerSpec { LayerName = "双点划线", DefaultLinetypeName = "PHANTOM", DefaultLineWeight = LineWeight.LineWeight025, DefaultColorIndex = 7 };
|
||||
return new LayerSpec { LayerName = "双点划线", DefaultLinetypeName = "PHANTOM", DefaultLineWeight = LineWeight.LineWeight015, DefaultColorIndex = 7 };
|
||||
case Role.Centerline:
|
||||
return new LayerSpec { LayerName = "中心线", DefaultLinetypeName = "CENTER", DefaultLineWeight = LineWeight.LineWeight025, DefaultColorIndex = 7 };
|
||||
return new LayerSpec { LayerName = "中心线", DefaultLinetypeName = "Continuous", DefaultLineWeight = LineWeight.LineWeight015, DefaultColorIndex = 7 };
|
||||
case Role.Hidden:
|
||||
return new LayerSpec { LayerName = "虚线", DefaultLinetypeName = "DASHED", DefaultLineWeight = LineWeight.LineWeight025, DefaultColorIndex = 7 };
|
||||
case Role.Hatch:
|
||||
return new LayerSpec { LayerName = "剖面线", DefaultLinetypeName = "Continuous", DefaultLineWeight = LineWeight.LineWeight018, DefaultColorIndex = 4 };
|
||||
return new LayerSpec { LayerName = "剖面线", DefaultLinetypeName = "Continuous", DefaultLineWeight = LineWeight.LineWeight015, DefaultColorIndex = 4 };
|
||||
case Role.Dimension:
|
||||
return new LayerSpec { LayerName = "尺寸标注", DefaultLinetypeName = "Continuous", DefaultLineWeight = LineWeight.LineWeight018, DefaultColorIndex = 7 };
|
||||
case Role.Text:
|
||||
@ -98,6 +98,18 @@ namespace CadParamPluging.Cad
|
||||
existingLayer.IsOff = false;
|
||||
existingLayer.IsFrozen = false;
|
||||
existingLayer.IsLocked = false;
|
||||
|
||||
existingLayer.Color = Color.FromColorIndex(ColorMethod.ByAci, colorIndex);
|
||||
existingLayer.LineWeight = lineWeight;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(linetypeName))
|
||||
{
|
||||
var lt = (LinetypeTable)_tr.GetObject(_db.LinetypeTableId, OpenMode.ForRead);
|
||||
if (lt.Has(linetypeName))
|
||||
{
|
||||
existingLayer.LinetypeObjectId = lt[linetypeName];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
|
||||
@ -958,9 +958,144 @@ namespace CadParamPluging.Cad
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Keep the template's white frame but enforce the desired lineweight.
|
||||
ApplyWhiteFrameLineWeight(ctx, LineWeight.LineWeight050);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static int ApplyWhiteFrameLineWeight(CadContext ctx, LineWeight lineWeight)
|
||||
{
|
||||
if (ctx == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
var db = ctx.Database;
|
||||
var tr = ctx.Transaction;
|
||||
|
||||
var frameExtents = ComputeWhiteFrameExtents(ctx);
|
||||
if (!frameExtents.HasValue)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
var frame = frameExtents.Value;
|
||||
var w = frame.MaxPoint.X - frame.MinPoint.X;
|
||||
var h = frame.MaxPoint.Y - frame.MinPoint.Y;
|
||||
var tol = Math.Max(w, h) * 0.01; // 1%
|
||||
|
||||
var bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
|
||||
var ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
|
||||
|
||||
var updated = 0;
|
||||
foreach (ObjectId id in ms)
|
||||
{
|
||||
var ent = tr.GetObject(id, OpenMode.ForWrite, false) as Entity;
|
||||
if (ent == null || ent.IsErased)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!(ent is Line) && !(ent is Polyline))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!IsWhiteColor(ent, tr))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!IsOnFrameBoundary(ent, frame, tol))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
try { ent.LineWeight = lineWeight; } catch { }
|
||||
|
||||
try
|
||||
{
|
||||
var layer = tr.GetObject(ent.LayerId, OpenMode.ForWrite) as LayerTableRecord;
|
||||
if (layer != null)
|
||||
{
|
||||
layer.LineWeight = lineWeight;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
|
||||
updated++;
|
||||
}
|
||||
|
||||
return updated;
|
||||
}
|
||||
|
||||
private static bool IsOnFrameBoundary(Entity ent, Extents3d frame, double tol)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ent is Line line)
|
||||
{
|
||||
var sp = line.StartPoint;
|
||||
var ep = line.EndPoint;
|
||||
|
||||
var minX = Math.Min(sp.X, ep.X);
|
||||
var maxX = Math.Max(sp.X, ep.X);
|
||||
var minY = Math.Min(sp.Y, ep.Y);
|
||||
var maxY = Math.Max(sp.Y, ep.Y);
|
||||
|
||||
var isHorizontal = Math.Abs(sp.Y - ep.Y) <= tol;
|
||||
if (isHorizontal)
|
||||
{
|
||||
var y = (sp.Y + ep.Y) / 2.0;
|
||||
var onTop = Math.Abs(y - frame.MaxPoint.Y) <= tol;
|
||||
var onBottom = Math.Abs(y - frame.MinPoint.Y) <= tol;
|
||||
if ((onTop || onBottom)
|
||||
&& minX <= frame.MinPoint.X + tol
|
||||
&& maxX >= frame.MaxPoint.X - tol)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
var isVertical = Math.Abs(sp.X - ep.X) <= tol;
|
||||
if (isVertical)
|
||||
{
|
||||
var x = (sp.X + ep.X) / 2.0;
|
||||
var onLeft = Math.Abs(x - frame.MinPoint.X) <= tol;
|
||||
var onRight = Math.Abs(x - frame.MaxPoint.X) <= tol;
|
||||
if ((onLeft || onRight)
|
||||
&& minY <= frame.MinPoint.Y + tol
|
||||
&& maxY >= frame.MaxPoint.Y - tol)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
var ext = ent.GeometricExtents;
|
||||
var matchX = Math.Abs(ext.MinPoint.X - frame.MinPoint.X) <= tol && Math.Abs(ext.MaxPoint.X - frame.MaxPoint.X) <= tol;
|
||||
var matchY = Math.Abs(ext.MinPoint.Y - frame.MinPoint.Y) <= tol && Math.Abs(ext.MaxPoint.Y - frame.MaxPoint.Y) <= tol;
|
||||
return matchX && matchY;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除模板中残留的“尺寸占位符”文本(例如 (Φ*)),避免与新生成的真实尺寸标注混淆。
|
||||
/// </summary>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user