.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

PlottingServices help

3 REPLIES 3
Reply
Message 1 of 4
mohnston
704 Views, 3 Replies

PlottingServices help

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
3 REPLIES 3
Message 2 of 4
MikeWillDo
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();
Message 3 of 4
jason.brenton
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?
Message 4 of 4
jason.brenton
in reply to: mohnston

I got that figured out, don't know how it waasn't showing up, think it was a typo.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost