Hi!
I'm trying to plot a two-page document to PDF and DWF.
The first page should be plotted from model-space, the second page should be plotted from a paper-space layout I create earlier with LayoutManager.Current.CreateLayout(name).
Creating the layout works just fine, as well as printing the first page.
When it comes to print the second page, I run into errors.
The line "infoValidatorLegende.Validate(infoLegende);" throws an exception "eLayoutNotCurrent".
The current layout when I run "Exportieren" is the model-space.
I wouldn't mind setting the paper-space layout to the current layout, but it doesn't work.
When I try to set the layout to current using
LayoutManager.Current.CurrentLayout = legendeLayoutName;
I get another exception complaining about illegally writing to protected memory.
Below you'll find my code that does the plotting.
Can anyone please help me?
I need to get this fixed quickly.
Best Regards
Christian Nitschkowski
public void Exportieren(Document dokument, string dateiName, string plotterName, bool istQuerformat, string legendeLayoutName)
{
Database db = dokument.Database;
Transaction trans = db.TransactionManager.StartTransaction();
try
{
DBDictionary layoutDict = (DBDictionary)trans.GetObject(db.LayoutDictionaryId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead);
PlotInfo infoModell = new PlotInfo();
PlotInfo infoLegende = null;
LayoutManager lMan = LayoutManager.Current;
// Hier wird das Modell-Layout zum Plotten gewählt
{
BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead);
BlockTableRecord btrModell = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead);
infoModell.Layout = btrModell.LayoutId;
}
if (legendeLayoutName.Length > 0)
{
infoLegende = new PlotInfo();
infoLegende.Layout = lMan.GetLayoutId(legendeLayoutName);
}
// Setze Settings für den Modellbereich
PlotSettings plotSettingsModell = new PlotSettings(true);
PlotSettingsValidator settingsValidator = PlotSettingsValidator.Current;
settingsValidator.SetPlotConfigurationName(plotSettingsModell, plotterName, _plotStilName);
settingsValidator.RefreshLists(plotSettingsModell);
settingsValidator.SetPlotCentered(plotSettingsModell, true);
settingsValidator.SetPlotType(plotSettingsModell, Autodesk.AutoCAD.DatabaseServices.PlotType.Extents);
if (istQuerformat)
{
settingsValidator.SetPlotRotation(plotSettingsModell, PlotRotation.Degrees090);
}
else
{
settingsValidator.SetPlotRotation(plotSettingsModell, PlotRotation.Degrees000);
}
infoModell.OverrideSettings = plotSettingsModell;
// Setze Settings für den Papierbereich "Legende"
if (infoLegende != null)
{
PlotSettings plotSettingsLegende = new PlotSettings(false);
settingsValidator.SetPlotConfigurationName(plotSettingsLegende, plotterName, _plotStilName);
settingsValidator.SetPlotType(plotSettingsLegende, Autodesk.AutoCAD.DatabaseServices.PlotType.Layout);
infoLegende.OverrideSettings = plotSettingsLegende;
}
PlotInfoValidator infoValidatorModell = new PlotInfoValidator();
infoValidatorModell.Validate(infoModell);
if (infoLegende != null)
{
PlotInfoValidator infoValidatorLegende = new PlotInfoValidator();
infoValidatorLegende.Validate(infoLegende);
}
PlotProgressDialog dialog = new PlotProgressDialog(false, 1, true);
dialog.set_PlotMsgString(PlotMessageIndex.DialogTitle, "Plotte ...");
dialog.set_PlotMsgString(PlotMessageIndex.CancelJobButtonMessage, "Plot abbrechen");
dialog.set_PlotMsgString(PlotMessageIndex.CancelSheetButtonMessage, "Seite abbrechen");
dialog.set_PlotMsgString(PlotMessageIndex.SheetSetProgressCaption, "Fortschritt Plott");
dialog.set_PlotMsgString(PlotMessageIndex.SheetProgressCaption, "Fortschritt Seite");
dialog.LowerPlotProgressRange = 0;
dialog.UpperPlotProgressRange = 100;
dialog.IsVisible = true;
PlotPageInfo pageInfo = new PlotPageInfo();
PlotPageInfo pageInfoLegende = new PlotPageInfo();
Object parms = null;
PlotEngine engine = PlotFactory.CreatePublishEngine();
engine.BeginPlot(dialog, parms);
engine.BeginDocument(infoModell, dokument.Name, parms, 1, true, dateiName);
engine.BeginPage(pageInfo, infoModell, false, parms);
engine.BeginGenerateGraphics(parms);
engine.EndGenerateGraphics(parms);
engine.EndPage(parms);
if (infoLegende != null)
{
engine.BeginPage(pageInfoLegende, infoLegende, true, parms);
engine.BeginGenerateGraphics(parms);
engine.EndGenerateGraphics(parms);
engine.EndPage(parms);
}
engine.EndDocument(parms);
engine.EndPlot(parms);
engine.Destroy();
engine = null;
dialog.Destroy();
}
catch (System.Exception ex)
{
throw new BearbeitungException(BearbeitenFehler.Export, string.Format("Fehler beim Export in Datei {0}", dateiName), ex);
}
finally
{
trans.Dispose();
}
}