该需求主要是:
为了对工程设计图纸尺寸进行编号,需要打印整个图纸,打印格式为JPG图片;另外就是将各个尺寸标注数据导出,涉及尺寸的文本、坐标、类型等。
部分代码
var btr = (BlockTableRecord)tr.GetObject(btrId, OpenMode.ForWrite);
var lo = (Layout)tr.GetObject(btr.LayoutId, OpenMode.ForWrite);
// Extmin and Extmax - Returns the extents of Model space.
// Pextmin and Pextmax - Returns the extents of the current Paper space layout.
var startPoint =new Point3d(lo.Limits.MinPoint.X,lo.Limits.MinPoint.Y,0);
var endPoint = new Point3d(lo.Limits.MaxPoint.X, lo.Limits.MaxPoint.Y, 0);
if ( endPoint.X < doc.Database.Pextmax.X ) {
startPoint = doc.Database.Pextmin;
endPoint = doc.Database.Pextmax;
}
else if (endPoint.X < doc.Database.Extmax.X)
{
startPoint = doc.Database.Extmin;
endPoint = doc.Database.Extmax;
}
// Transform from UCS to DCS
var rbFrom = new ResultBuffer(new TypedValue(5003, 1));
var rbTo = new ResultBuffer(new TypedValue(5003, 2));
var firres = new double[] { 0, 0, 0 };
var secres = new double[] { 0, 0, 0 };
// Transform the first point...
acedTrans(
startPoint.ToArray(),
rbFrom.UnmanagedObject,
rbTo.UnmanagedObject,
0,
firres
);
acDoc.Editor.WriteMessage("\n " + layout.Key);
var acLayout = acTrans.GetObject(layout.Value, OpenMode.ForRead) as Layout;
var filterRules = new TypedValue[]{
new TypedValue((int)DxfCode.Operator,"<and"),
new TypedValue((int)DxfCode.LayoutName,layout.Key),
new TypedValue((int)DxfCode.Operator,"and>"),
};//过滤所有曲线
var filter = new SelectionFilter(filterRules);
var selectionResult = editor.SelectAll(filter);
if ( selectionResult.Status != PromptStatus.OK ) {
editor.WriteMessage("Warning:未选择任何元素!\n");
continue;
}
var allFindings = selectionResult.Value.GetObjectIds().Select(x => acTrans.GetObject(x, OpenMode.ForWrite));
if ( allFindings.Count() == 0 ) {
editor.WriteMessage("Warning:" + layout.Key + "下不包含任何元素!\n");
continue;
}
// FeatureControlFrame
var cadDimensions = allFindings
.OfType<Dimension>()
//.OrderByDescending(u => u.TextPosition.Y).ThenBy(u => u.TextPosition.X)
.ToList();
var toleranceFeatureControls = allFindings
.OfType<FeatureControlFrame>()
//.OrderByDescending(u => u.Location.Y).ThenBy(u => u.Location.X)
.ToList();
if ( cadDimensions.Count == 0 && toleranceFeatureControls.Count == 0 ) {
editor.WriteMessage("Warning:" + layout.Key + "下未找到有效尺寸元素!\n");
continue;
}