Hi,
you have right... these parametrs are on wrong order... but I do not think it will some change printer driver... for sure I tested and result is same...it is used AutoCAD PDF (General Documentation).pc3 and in layouts is set DWG to PDF.pc3
i think problem will be in function for multiple layouts print but relly dont know why this function does not respect layout settings -mainly printer driver
function print is here:
using System.Collections.Generic;
using System.IO;
using System.Text;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.PlottingServices;
using Autodesk.AutoCAD.Publishing;
namespace AutoCAD.Command
{
public abstract class PlotToFileConfig
{
private string dsdFile, dwgFile, outputDir, outputFile, plotType;
private int sheetNum;
private IEnumerable<Layout> layouts;
private const string LOG = "publish.log";
public PlotToFileConfig(string outputDir, IEnumerable<Layout> layouts, string plotType, string sourceFilePath)
{
this.dwgFile = sourceFilePath;
this.outputDir = outputDir;
this.dsdFile = Path.ChangeExtension(this.dwgFile, "dsd");
this.layouts = layouts;
this.plotType = plotType;
string ext = plotType == "0" || plotType == "1" ? "dwf" : "pdf";
this.outputFile = Path.Combine(
this.outputDir,
Path.ChangeExtension(Path.GetFileName(this.dwgFile), ext));
}
public void Publish()
{
if (TryCreateDSD())
{
object rememberBACKGROUNDPLOT = Application.GetSystemVariable("BACKGROUNDPLOT");
object rememberHIDEPRECISION = (short)Application.GetSystemVariable("HIDEPRECISION");
object remembertraynotify = (short)Application.GetSystemVariable("traynotify");
try
{
Application.SetSystemVariable("BACKGROUNDPLOT", 0);
Application.SetSystemVariable("HIDEPRECISION", 1);
Application.SetSystemVariable("traynotify", 0);
Publisher publisher = Application.Publisher;
PlotProgressDialog plotDlg = new PlotProgressDialog(false, this.sheetNum, true);
publisher.PublishDsd(this.dsdFile, plotDlg);
File.Delete(this.dsdFile);
}
catch (System.Exception exn)
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
ed.WriteMessage("\nError: {0}\n{1}", exn.Message, exn.StackTrace);
throw;
}
finally
{
Application.SetSystemVariable("BACKGROUNDPLOT", rememberBACKGROUNDPLOT);
Application.SetSystemVariable("HIDEPRECISION", rememberHIDEPRECISION);
Application.SetSystemVariable("traynotify", remembertraynotify);
}
}
}
private bool TryCreateDSD()
{
using (DsdData dsd = new DsdData())
using (DsdEntryCollection dsdEntries = CreateDsdEntryCollection(this.layouts))
{
if (dsdEntries == null || dsdEntries.Count <= 0) return false;
this.sheetNum = dsdEntries.Count;
dsd.SetDsdEntryCollection(dsdEntries);
dsd.SetUnrecognizedData("PwdProtectPublishedDWF", "FALSE");
dsd.SetUnrecognizedData("PromptForPwd", "FALSE");
dsd.NoOfCopies = 1;
dsd.DestinationName = this.outputFile;
dsd.LogFilePath = Path.Combine(this.outputDir, LOG);
PostProcessDSD(dsd);
return true;
}
}
private DsdEntryCollection CreateDsdEntryCollection(IEnumerable<Layout> layouts)
{
DsdEntryCollection entries = new DsdEntryCollection();
foreach (Layout layout in layouts)
{
DsdEntry dsdEntry = new DsdEntry();
dsdEntry.DwgName = this.dwgFile;
dsdEntry.Layout = layout.LayoutName;
dsdEntry.Title = Path.GetFileNameWithoutExtension(this.dwgFile) + "-" + layout.LayoutName;
dsdEntry.Nps = layout.TabOrder.ToString();
entries.Add(dsdEntry);
}
return entries;
}
private void PostProcessDSD(DsdData dsd)
{
string str, newStr;
string tmpFile = Path.Combine(this.outputDir, "temp.dsd");
dsd.WriteDsd(tmpFile);
using (StreamReader reader = new StreamReader(tmpFile, Encoding.Default))
using (StreamWriter writer = new StreamWriter(this.dsdFile, false, Encoding.Default))
{
while (!reader.EndOfStream)
{
str = reader.ReadLine();
if (str.Contains("Has3DDWF"))
{
newStr = "Has3DDWF=0";
}
else if (str.Contains("OriginalSheetPath"))
{
newStr = "OriginalSheetPath=" + this.dwgFile;
}
else if (str.Contains("Type"))
{
newStr = "Type=" + this.plotType;
}
else if (str.Contains("OUT"))
{
newStr = "OUT=" + this.outputDir;
}
else if (str.Contains("IncludeLayer"))
{
newStr = "IncludeLayer=TRUE";
}
else if (str.Contains("PromptForDwfName"))
{
newStr = "PromptForDwfName=FALSE";
}
else if (str.Contains("LogFilePath"))
{
newStr = "LogFilePath=" + Path.Combine(this.outputDir, LOG);
}
else
{
newStr = str;
}
writer.WriteLine(newStr);
}
}
File.Delete(tmpFile);
}
}
public class SingleSheetPdf : PlotToFileConfig
{
public SingleSheetPdf(string outputDir, IEnumerable<Layout> layouts, string sourceFilePath)
: base(outputDir, layouts, "5", sourceFilePath) { }
}
public class MultiSheetsPdf : PlotToFileConfig
{
public MultiSheetsPdf(string outputDir, IEnumerable<Layout> layouts, string sourceFilePath)
: base(outputDir, layouts, "6", sourceFilePath) { }
}
}
...