plt打印输出文件空白
最近遇到plt打印输出文件空白的情况,将设计内容复制到新建的文件后,再打印就正常了。不知道大家有没有遇到过这种情况,帮忙指教一二,谢谢!
同时,如果知道复制功能会复制哪些内容,也麻烦说一下,这样我就好针对问题查看两个文件的区别,然后找到问题。
比如复制的内容包括:图纸内选择的图元、图层、文字样式
public static bool AcDbPlotPlt(Extents2d PlotExtent, string sPlotDeviceName, string sSheetStyleName
, string sPlotMediaName, string sPlotPath, PlotRotation pRotation, double dPlotScale)
{
Document doc = Application.DocumentManager.MdiActiveDocument;
doc.LockDocument();
Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("BACKGROUNDPLOT", 0);
Editor ed = doc.Editor;
Database db = doc.Database;
Transaction tr = db.TransactionManager.StartTransaction();
using (tr)
{
// We'll be plotting the current layout 绘制当前布局
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForRead);
Layout acLayout = (Layout)tr.GetObject(btr.LayoutId, OpenMode.ForRead);
//lo.PlotPlotStyles = false;
// We need a PlotInfo object linked to the layout 初始化PlotInfo的对象并与布局关联
PlotInfo acPlInfo = new PlotInfo();
acPlInfo.Layout = btr.LayoutId;
PlotSettings acPlSet = new PlotSettings(acLayout.ModelType); //modeltype 区分布局空间,模型空间
acPlSet.CopyFrom(acLayout);
//如果是布局空间,直接默认打印样式为1:1
if (!acLayout.ModelType)
dPlotScale = 1;
// The PlotSettingsValidator helps create a valid PlotSettings object
PlotSettingsValidator psv = PlotSettingsValidator.Current;
//设置打印样式
if (!string.IsNullOrEmpty(sSheetStyleName))
{
acPlSet.PlotPlotStyles = true;
acPlSet.PrintLineweights = true;
//lo.CurrentStyleSheet = sSheetStyleName;
psv.SetCurrentStyleSheet(acPlSet, sSheetStyleName);
}
//设置打印方向
psv.SetPlotRotation(acPlSet, pRotation);
psv.SetPlotConfigurationName(acPlSet, sPlotDeviceName, sPlotMediaName);
//设置打印尺寸
//设置图纸单位
psv.SetPlotPaperUnits(acPlSet, PlotPaperUnit.Millimeters);
#region<<设置打印比例>>
psv.SetUseStandardScale(acPlSet, true);
if (dPlotScale == 1)
psv.SetStdScaleType(acPlSet, StdScaleType.StdScale1To1);
else if (dPlotScale == 2)
psv.SetStdScaleType(acPlSet, StdScaleType.StdScale1To2);
else if (dPlotScale == 4)
psv.SetStdScaleType(acPlSet, StdScaleType.StdScale1To4);
else if (dPlotScale == 8)
psv.SetStdScaleType(acPlSet, StdScaleType.StdScale1To8);
else if (dPlotScale == 10)
psv.SetStdScaleType(acPlSet, StdScaleType.StdScale1To10);
else if (dPlotScale == 16)
psv.SetStdScaleType(acPlSet, StdScaleType.StdScale1To16);
else if (dPlotScale == 20)
psv.SetStdScaleType(acPlSet, StdScaleType.StdScale1To20);
else if (dPlotScale == 30)
psv.SetStdScaleType(acPlSet, StdScaleType.StdScale1To30);
else if (dPlotScale == 40)
psv.SetStdScaleType(acPlSet, StdScaleType.StdScale1To40);
else if (dPlotScale == 50)
psv.SetStdScaleType(acPlSet, StdScaleType.StdScale1To50);
else if (dPlotScale == 100)
psv.SetStdScaleType(acPlSet, StdScaleType.StdScale1To100);
else if (dPlotScale == 0.5)
psv.SetStdScaleType(acPlSet, StdScaleType.StdScale2To1);
else if (dPlotScale == 0.25)
psv.SetStdScaleType(acPlSet, StdScaleType.StdScale4To1);
else if (dPlotScale == 0.125)
psv.SetStdScaleType(acPlSet, StdScaleType.StdScale8To1);
else if (dPlotScale == 0.1)
psv.SetStdScaleType(acPlSet, StdScaleType.StdScale10To1);
else if (dPlotScale == 0.01)
psv.SetStdScaleType(acPlSet, StdScaleType.StdScale100To1);
else if (dPlotScale == 0)
psv.SetStdScaleType(acPlSet, StdScaleType.ScaleToFit);
else
{
psv.SetUseStandardScale(acPlSet, false);
CustomScale plotScale = new CustomScale(1, dPlotScale);
psv.SetCustomPrintScale(acPlSet, plotScale);
}
#endregion
//设置打印的范围,中心和比例
psv.SetPlotWindowArea(acPlSet, PlotExtent);
// 设置自定义打印偏移
psv.SetPlotOrigin(acPlSet, new Point2d(0, 0));
psv.SetPlotType(acPlSet, Autodesk.AutoCAD.DatabaseServices.PlotType.Window);
acPlInfo.OverrideSettings = acPlSet;
// Validate the plot info
PlotInfoValidator acPlInfoVdr = new PlotInfoValidator();
acPlInfoVdr.MediaMatchingPolicy = MatchingPolicy.MatchEnabled;
acPlInfoVdr.Validate(acPlInfo);
// Check to see if a plot is already in progress
if (PlotFactory.ProcessPlotState == ProcessPlotState.NotPlotting)
{
using (PlotEngine acPlEng = PlotFactory.CreatePublishEngine())
{
// Track the plot progress with a Progress dialog
PlotProgressDialog acPlProgDlg = new PlotProgressDialog(false,
1,
true);
using (acPlProgDlg)
{
// Define the status messages to display when plotting starts
acPlProgDlg.set_PlotMsgString(PlotMessageIndex.DialogTitle,
"Plot Progress");
acPlProgDlg.set_PlotMsgString(PlotMessageIndex.CancelJobButtonMessage,
"Cancel Job");
acPlProgDlg.set_PlotMsgString(PlotMessageIndex.CancelSheetButtonMessage,
"Cancel Sheet");
acPlProgDlg.set_PlotMsgString(PlotMessageIndex.SheetSetProgressCaption,
"Sheet Set Progress");
acPlProgDlg.set_PlotMsgString(PlotMessageIndex.SheetProgressCaption,
"Sheet Progress");
// Set the plot progress range
acPlProgDlg.LowerPlotProgressRange = 0;
acPlProgDlg.UpperPlotProgressRange = 100;
acPlProgDlg.PlotProgressPos = 0;
// Display the Progress dialog
acPlProgDlg.OnBeginPlot();
acPlProgDlg.IsVisible = true;
// Start to plot the layout
acPlEng.BeginPlot(acPlProgDlg, null);
// Define the plot output
acPlEng.BeginDocument(acPlInfo,
doc.Name, null, 1, true, sPlotPath);
// Display information about the current plot
acPlProgDlg.set_PlotMsgString(PlotMessageIndex.Status,
"Plotting: " + doc.Name + " - " +
acLayout.LayoutName);
// Set the sheet progress range
acPlProgDlg.OnBeginSheet();
acPlProgDlg.LowerSheetProgressRange = 0;
acPlProgDlg.UpperSheetProgressRange = 100;
acPlProgDlg.SheetProgressPos = 0;
// Plot the first sheet/layout
PlotPageInfo acPlPageInfo = new PlotPageInfo();
acPlEng.BeginPage(acPlPageInfo, acPlInfo, true, null);
acPlEng.BeginGenerateGraphics(null);
acPlEng.EndGenerateGraphics(null);
// Finish plotting the sheet/layout
acPlEng.EndPage(null);
acPlProgDlg.SheetProgressPos = 100;
acPlProgDlg.OnEndSheet();
// Finish plotting the document
acPlEng.EndDocument(null);
// Finish the plot
acPlProgDlg.PlotProgressPos = 100;
acPlProgDlg.OnEndPlot();
acPlEng.EndPlot(null);
}
}
}
}
return true;
} 这个是需要打印的文件,谢谢各位大侠了! 本帖最后由 WangZewei 于 2015-10-31 17:15 编辑
问题终于解决,根据当前视图的目标坐标进行一下变换就行了。 WangZewei 发表于 2015-10-1 21:49 static/image/common/back.gif
问题终于解决,根据当前视图的目标坐标进行一下变换就行了。
我也遇到类似问题,请教下如何变换? hnzgs 发表于 2015-11-17 17:06 static/image/common/back.gif
我也遇到类似问题,请教下如何变换?
对于视图方向与Z轴平行的情况,先
Point3d ptTarget = Application.GetSystemVariable("TARGET");
然后将打印范围的X和Y分别减去ptTarget的X和Y值即可。 WangZewei 发表于 2015-11-21 09:27 static/image/common/back.gif
对于视图方向与Z轴平行的情况,先
Point3d ptTarget = Application.GetSystemVariable("TARGET");
然后 ...
非常感谢!周一上班去试试 6楼的方法正确,我用该方法解决问题了,多谢! 哪位帮忙继续解答一下,用这个方法解决了大部分文件的问题,但是仍然有文件出会现打印范围偏移。附件中PDF是打印成果,DWG是源文件 这是会偏移的文件
页:
[1]