Maybe this will help someone since there really isn't very much in the way of documentation on the PlottingServices.
[CommandMethod("CSharpPlot")]
static public void CSharpPlot()
{
// Set up some variables
string fullDWGPath = @"C:\PlotTestFile.dwg";
Document ThisDrawing = Application.DocumentManager.Open(fullDWGPath, true);
Database ThisDB = ThisDrawing.Database;
int Copies = 1;
Object parms = null;
string plotDeviceName = "myValidPlotDevice.pc3";
string styleSheet = "myValidStyleSheet.ctb";
Point2d originPoint = new Point2d(0, 0);
// Set up some PLOT specific variables
PlotInfo pInfo = new PlotInfo();
pInfo.Layout = LayoutManager.Current.GetLayoutId("Model");
PlotSettings pSet = new PlotSettings(true);
PlotSettingsValidator pSetValid = PlotSettingsValidator.Current;
PlotPageInfo pPInfo = new PlotPageInfo();
PlotConfigManager.SetCurrentConfig(plotDeviceName);
PlotConfigManager.RefreshList(RefreshCode.All);
// set the Canonical Media Name (paper name) - for sample purposes just grab the first one
StringCollection cMNs = PlotConfigManager.CurrentConfig.CanonicalMediaNames;
string mediaName = cMNs[0].ToString();
try
{
pSetValid.SetPlotConfigurationName(pSet, plotDeviceName, mediaName);
// It was recommended to refresh lists before changing settings
pSetValid.RefreshLists(pSet);
pSetValid.SetCurrentStyleSheet(pSet, styleSheet);
pSetValid.SetPlotCentered(pSet, false);
pSetValid.SetPlotOrigin(pSet, originPoint);
pSetValid.SetPlotPaperUnits(pSet, PlotPaperUnit.Inches);
pSetValid.SetPlotRotation(pSet, PlotRotation.Degrees000);
pSetValid.SetPlotType(pSet, Autodesk.AutoCAD.DatabaseServices.PlotType.Limits);
pSetValid.SetUseStandardScale(pSet, true);
pSetValid.SetStdScaleType(pSet, StdScaleType.StdScale3To8InchIs1ft);
pSetValid.SetZoomToPaperOnUpdate(pSet, false);
// apply setting overrides to plot info
pInfo.OverrideSettings = pSet;
PlotInfoValidator pInfoValid = new PlotInfoValidator();
pInfoValid.MediaMatchingPolicy = MatchingPolicy.MatchEnabled;
pInfoValid.Validate(pInfo);
// Settings are set - attempt plot
PlotProgressDialog pProgDialog = new PlotProgressDialog(false, 1, true);
//PlotProgressDialog pProgDialog = new PlotProgressDialog(true, 1, true); // In case it's a preview
pProgDialog.OnBeginPlot();
pProgDialog.IsVisible = true;
PlotEngine pEng = PlotFactory.CreatePublishEngine();
//PlotEngine pEng = PlotFactory.CreatePreviewEngine(1); // In case it's a preview
pEng.BeginPlot(pProgDialog, parms);
pEng.BeginDocument(pInfo, fullDWGPath, parms, Copies, false, string.Empty);
// pEng.BeginDocument(pInfo, fullDWGPath, parms, Copies, true, fullPLTPath); // In case plot to file
pEng.BeginPage(pPInfo, pInfo, true, parms);
pEng.BeginGenerateGraphics(parms);
pEng.EndGenerateGraphics(parms);
pEng.EndPage(parms);
pEng.EndDocument(parms);
pEng.EndPlot(parms);
pProgDialog.OnEndPlot();
pProgDialog.Destroy();
pEng.Destroy();
}
catch (Autodesk.AutoCAD.Runtime.Exception e)
{
System.Windows.Forms.MessageBox.Show(e.TargetSite + "\n" + e.StackTrace);
}
}