.NET

Reply
Distinguished Contributor
mohnston
Posts: 184
Registered: ‎09-22-2006
Message 1 of 4 (249 Views)

PlottingServices help

249 Views, 3 Replies
12-06-2006 11:40 AM
I have been trying to plot using the PlottingServices.
I haven't been able to create even the simplest plot.

Does anyone have a code example they would like to share?
A very simple one would be very helpfull.

Here is my code so far. This doesn't work. I get an error when the plotInfo is validated.


static public void NETPlot()
{
// Set up some variables
Document ThisDrawing = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database ThisDB = ThisDrawing.Database;
string fullDWGPath = @"C:\PlotTest.dwg";
int Copies = 1;
Object parms = null;
string plotDeviceName = "WPI-8830-Full.pc3";
string styleSheet = "WPI-88xx-Full.ctb";
Point2d originPoint = new Point2d(0, 0);
// Set up some PLOT specific variables
PlotEngine pEng = PlotFactory.CreatePublishEngine();
PlotInfo pInfo = new PlotInfo();
PlotSettings pSet = new PlotSettings(true);
PlotSettingsValidator pSetValid = PlotSettingsValidator.Current;

PlotPageInfo pPInfo = new PlotPageInfo();
PlotProgressDialog pProgDialog = new PlotProgressDialog(false, 1, true);
PlotConfigManager.SetCurrentConfig(plotDeviceName);
//PlotConfigInfo pConfigInfo = new PlotConfigInfo();
PlotConfigManager.RefreshList(RefreshCode.All);
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.SetCanonicalMediaName(pSet, mediaName);
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);
// pSetValid.SetDefaultPlotConfig(pSet);
// apply setting overrides to plot info
pInfo.OverrideSettings = pSet;

PlotInfoValidator pInfoValid = new PlotInfoValidator();
pInfoValid.Validate(pInfo);

// Settings are set - attempt plot
pEng.BeginPlot(pProgDialog, parms);
pEng.BeginDocument(pInfo, fullDWGPath, parms, Copies, false, string.Empty);
pEng.BeginPage(pPInfo, pInfo, true, parms);
pEng.BeginGenerateGraphics(parms);
pEng.EndGenerateGraphics(parms);
pEng.EndPage(parms);
pEng.EndDocument(parms);
pEng.EndPlot(parms);
}
catch (Autodesk.AutoCAD.Runtime.Exception e)
{
System.Windows.Forms.MessageBox.Show(e.TargetSite + "\n" + e.StackTrace);
}
finally
{
pEng.Destroy();
}
}
CAD Programming Solutions
New Member
MikeWillDo
Posts: 1
Registered: ‎12-13-2006
Message 2 of 4 (249 Views)

Re: PlottingServices help

12-13-2006 07:08 PM in reply to: mohnston
Mark,
I've been slaving away at the same problem for some time...
Combining the code that you provided, with the code i already had, I managed to get an example... here it is attached...

public void test() {
MessageBox.Show("Starting Plot");
String ConfigInfoName = "";
foreach (Autodesk.AutoCAD.PlottingServices.PlotConfigInfo inf in Autodesk.AutoCAD.PlottingServices.PlotConfigManager.Devices)
{
if (inf.DeviceName.Equals("DWG To PDF.pc3"))
{
MessageBox.Show("found the right device");
ConfigInfoName = inf.DeviceName;

}

}
Autodesk.AutoCAD.PlottingServices.PlotConfig pConfig = Autodesk.AutoCAD.PlottingServices.PlotConfigManager.SetCurrentConfig(ConfigInfoName);


Autodesk.AutoCAD.PlottingServices.PlotInfo pInfo = new Autodesk.AutoCAD.PlottingServices.PlotInfo();
Autodesk.AutoCAD.DatabaseServices.LayoutManager lMan = Autodesk.AutoCAD.DatabaseServices.LayoutManager.Current;
pInfo.Layout = lMan.GetLayoutId(lMan.CurrentLayout);
pInfo.DeviceOverride = pConfig;

Autodesk.AutoCAD.DatabaseServices.PlotSettings pSettings = new Autodesk.AutoCAD.DatabaseServices.PlotSettings(true);
Autodesk.AutoCAD.DatabaseServices.PlotSettingsValidator pSValidator = Autodesk.AutoCAD.DatabaseServices.PlotSettingsValidator.Current;

Autodesk.AutoCAD.PlottingServices.PlotInfoValidator validator = new Autodesk.AutoCAD.PlottingServices.PlotInfoValidator();
validator.Validate(pInfo);
Autodesk.AutoCAD.PlottingServices.PlotProgressDialog pProgDialog = new Autodesk.AutoCAD.PlottingServices.PlotProgressDialog(false,1,true);
pProgDialog.set_PlotMsgString(Autodesk.AutoCAD.PlottingServices.PlotMessageIndex.DialogTitle,"Plotting...");
pProgDialog.set_PlotMsgString(Autodesk.AutoCAD.PlottingServices.PlotMessageIndex.CancelJobButtonMessage,"Cancel Plot");
pProgDialog.set_PlotMsgString(Autodesk.AutoCAD.PlottingServices.PlotMessageIndex.CancelSheetButtonMessage,"Cancel Sheet");
pProgDialog.set_PlotMsgString(Autodesk.AutoCAD.PlottingServices.PlotMessageIndex.SheetSetProgressCaption,"Plot Progree");
pProgDialog.set_PlotMsgString(Autodesk.AutoCAD.PlottingServices.PlotMessageIndex.SheetProgressCaption,"Sheet Progress");
pProgDialog.LowerPlotProgressRange = 0;
pProgDialog.UpperPlotProgressRange = 100;
//pProgDialog.OnBeginPlot();
pProgDialog.IsVisible = true;
Autodesk.AutoCAD.PlottingServices.PlotPageInfo pPInfo = new Autodesk.AutoCAD.PlottingServices.PlotPageInfo();

Object parms = null;
Autodesk.AutoCAD.PlottingServices.PlotEngine pEngine = Autodesk.AutoCAD.PlottingServices.PlotFactory.CreatePublishEngine();
pEngine.BeginPlot(pProgDialog,parms);
pEngine.BeginDocument(pInfo, "c:\\house7.dwg", parms, 1, true, "c:\\Mike_out.pdf");
pEngine.BeginPage(pPInfo, pInfo, true, parms);
pEngine.BeginGenerateGraphics(parms);
pEngine.EndGenerateGraphics(parms);
pEngine.EndPage(parms);
pEngine.EndDocument(parms);
pEngine.EndPlot(parms);
pEngine.Destroy();
pEngine = null;
pProgDialog.Destroy();
Active Contributor
jason.brenton
Posts: 38
Registered: ‎10-02-2007
Message 3 of 4 (249 Views)

Re: PlottingServices help

10-05-2007 10:54 AM in reply to: mohnston
I have been going over similar code to a largwe degree over the last few days, all of the listing reference to lines similar to
dim PS as PlotSettings = PlotSettings.Current()

but I find no reference or connection anywher in coding to plotsettings.current()

Anybody know where it is?
Active Contributor
jason.brenton
Posts: 38
Registered: ‎10-02-2007
Message 4 of 4 (249 Views)

Re: PlottingServices help

10-05-2007 02:11 PM in reply to: mohnston
I got that figured out, don't know how it waasn't showing up, think it was a typo.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community