- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everyone!
I've got an exiting problem while trying to batch pdf export.
My task is quite simple: first, look through the drawing (all the lists and model space) and find all dynamic blocks with effective name "SheetGOST", case it's a drawing frame; second, export areas surrounded by those frames to pdf page by page. I've decided that plotting areas via "DWG To PDF.pc3" would be the easiest way.
Practically all the steps made: I get collection of blocks, I know howto print one of them to pdf, and it,s working correctly. The problem is, when I try to plot all the areas in cycle, in output pdf I get num of pages according to num of lists, and only the last area from the list. Test document contains 24 blocks on 3 lists, I get 3 page pdf with 7th, 22th and 24th frame printed..
I ran out of the ideas where I went wrong =(
The code is:
[CommandMethod("PlotToPdf")]
static public void MultiSheetPlot()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
Transaction tr = db.TransactionManager.StartTransaction();
using (tr)
{
List<GostBlk> BlocksToPlot = new List<GostBlk>();
List<Layout> LayList = new List<Layout>();
GetGostStampCollection(db, ed, tr, ref BlocksToPlot, ref LayList);
ed.WriteMessage("\nThe number of GOST stamps found: " + BlocksToPlot.Count + "\n\n");
if (BlocksToPlot.Count < 1) return;
if (PlotFactory.ProcessPlotState == ProcessPlotState.NotPlotting)
{
PlotEngine pe = PlotFactory.CreatePublishEngine();
using (pe)
{
PlotProgressDialog ppd = new PlotProgressDialog(false, BlocksToPlot.Count, true);
using (ppd)
{
int numSheet = 1;
ppd.set_PlotMsgString(PlotMessageIndex.DialogTitle, "Custom Plot Progress");
ppd.set_PlotMsgString(PlotMessageIndex.CancelJobButtonMessage, "Cancel Job");
ppd.set_PlotMsgString(PlotMessageIndex.CancelSheetButtonMessage, "Cancel Sheet");
ppd.set_PlotMsgString(PlotMessageIndex.SheetSetProgressCaption, "Sheet Set Progress");
ppd.set_PlotMsgString(PlotMessageIndex.SheetProgressCaption, "Sheet Progress");
ppd.LowerPlotProgressRange = 0;
ppd.UpperPlotProgressRange = 100;
ppd.PlotProgressPos = 0;
ppd.OnBeginPlot();
ppd.IsVisible = true;
pe.BeginPlot(ppd, null);
foreach (GostBlk gblk in BlocksToPlot)
{
ppd.StatusMsgString = "Plotting block " + numSheet.ToString() + " of " + BlocksToPlot.Count.ToString();
ppd.OnBeginSheet();
ppd.LowerSheetProgressRange = 0;
ppd.UpperSheetProgressRange = 100;
ppd.SheetProgressPos = 0;
PlotInfoValidator piv = new PlotInfoValidator();
piv.MediaMatchingPolicy = MatchingPolicy.MatchEnabled;
PlotPageInfo ppi = new PlotPageInfo();
PlotInfo pi = new PlotInfo();
BlockReference blk = gblk.BlockRef;
Layout lo = gblk.LayoutRef;
Extents3d ext = (Extents3d)blk.Bounds;
Point3d first = ext.MaxPoint;
Point3d second = ext.MinPoint;
ResultBuffer rbFrom = new ResultBuffer(new TypedValue(5003, 1)), rbTo = new ResultBuffer(new TypedValue(5003, 2));
double[] firres = new double[] { 0, 0, 0 };
double[] secres = new double[] { 0, 0, 0 };
acedTrans(first.ToArray(), rbFrom.UnmanagedObject, rbTo.UnmanagedObject, 0, firres);
acedTrans(second.ToArray(), rbFrom.UnmanagedObject, rbTo.UnmanagedObject, 0, secres);
Extents2d window = new Extents2d(firres[0], firres[1], secres[0], secres[1]);
// We need a PlotSettings object based on the layout settings which we then customize
PlotSettings ps = new PlotSettings(lo.ModelType);
LayoutManager.Current.CurrentLayout = lo.LayoutName;
pi.Layout = lo.Id;
ps.CopyFrom(lo);
// The PlotSettingsValidator helps create a valid PlotSettings object
PlotSettingsValidator psv = PlotSettingsValidator.Current;
psv.SetPlotWindowArea(ps, window);
psv.SetPlotType(ps, Autodesk.AutoCAD.DatabaseServices.PlotType.Window);
psv.SetUseStandardScale(ps, true);
psv.SetStdScaleType(ps, StdScaleType.ScaleToFit);
psv.SetPlotCentered(ps, true); //StdScaleType.StdScale1To1
psv.SetPlotConfigurationName(ps, "DWG To PDF.pc3", "ISO_A3_(297.00_x_420.00_MM)");
pi.OverrideSettings = ps;
piv.Validate(pi);
if (numSheet == 1)
{
pe.BeginDocument(pi, doc.Name, null, 1, true, "c:\\multiblock");
}
pe.BeginPage(ppi, pi, (numSheet == BlocksToPlot.Count), null);
pe.BeginGenerateGraphics(null);
ppd.SheetProgressPos = 50;
pe.EndGenerateGraphics(null);
// Finish the sheet
pe.EndPage(null);
ppd.SheetProgressPos = 100;
ppd.PlotProgressPos += Convert.ToInt32(100 / BlocksToPlot.Count);
ppd.OnEndSheet();
numSheet++;
}
// Finish the document
pe.EndDocument(null);
// And finish the plot
ppd.PlotProgressPos = 100;
ppd.OnEndPlot();
pe.EndPlot(null);
}
}
}
else
{
ed.WriteMessage("\nAnother plot is in progress.");
}
}
}
Solved! Go to Solution.