TheSwamp
Code Red => .NET => Topic started by: mohnston on December 06, 2006, 02:44:15 PM
-
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.
I'm trying to stay calm. :pissed:
Here is my code so far:
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();
}
}
-
There is an example (C++) in the ARX docs - you should be to translate it to C# easily enough.
Hope this helps.
-
I have looked over the C++ example and it wasn't much help.
I don't know C++ so the translation is not easy.
-
Mark, what is the actual error you are getting ... if you get an error ?
I haven't tried the code 'cause I'd have to change a lot to get it to suit my conditions
-
There is an example (C++) in the ARX docs - you should be to translate it to C# easily enough.
Hope this helps.
I recall a help from you... and now I want to share that...
Just replace the "->" with "." and that's all......
HTH
he he
Sorry, couldn't resist....
-
I know it sounds funny, but that's essentially it.
I initially designed mine around that sample. The function calls are pretty much the same names from C++ to C#.
-
I remember having trouble with plotting, something about background plotting being enabled. I'll take a look when I get back to the office tomorrow....
-
Yes - definately set "BACKGROUNDPLOT" to 0 to disable it.
-
Wow ! I've just spent a couple of hours playing with PlottingServices and namespaces associated with plotting.
That is one area that could do with a book being written about it.
The PlotSettingsValidator alone would be a couple of chapters
LayoutManager
PlotSettings
PlotInfo
LocaleMediaName and canonicalMediaNameList and plotDeviceList and GetPlotStyleSheetList
PlotEngine
PlotInfoValidator
MatchingPolicy
PlotPageInfo
... then a chapter on exceptions
... anyone want to finance me for about 8 weeks or so ? :-)
-
I agree wholeheartedly Kerry - plotting in ARX/.NET is a black art at best.
-
Mark,
This line :
string plotDeviceName = "WPI-8830-Full.pc3";
can you check it .. should it should be the Plotter name, not the pc3 ? ?
added:
Looks like it can be either .. perhaps treat me with ignore ;-)
give something like this a run ..
[CommandMethod("GPDN")]
static public void GetPlotDeviceNames()
{
/// requires the COM interface
/// Autodesk.AutoCAD.Interop
///
AcadApplication acadApp = (AcadApplication)AcadApp.AcadApplication;
AcadLayout activeLayout = acadApp.ActiveDocument.ActiveLayout;
Object plotDevices = activeLayout.GetPlotDeviceNames();
Array deviceArray = (Array)plotDevices;
foreach (string deviceName in deviceArray)
{
/// requires Autodesk.AutoCAD.Windows.Forms
MessageBox.Show("plot device name is: " + deviceName);
}
}
-
Yep, can be either ...
At least thats how it looks ..
-
.....
That is one area that could do with a book being written about it.
............
On reflection, the first 2 chapters should be on ' Definition of Terms ' stuff ..
.. but that's booring so it would have to go in the back :lmao:
-
My code breaks at the line:
pInfoValid.Validate(pInfo);
I read in the ARX docs that ALL the properties of the plotinfo object need to be filled or there will be an error.
Can anyone explain how to copy an existing PlotInfo object into a new one?
I will try replacing -> with . in the C++ code. My hopes are not high.
-
Try adding this instead:
PlotInfoValidator validator = new PlotInfoValidator();
validator.MediaMatchingPolicy = Autodesk.AutoCAD.PlottingServices.MatchingPolicy.MatchEnabled;
before calling the validate method
-
Thanks for the suggestion.
Unfortunately I tried it but got the same error.
---------------------------
Void Check(Int32)
at Autodesk.AutoCAD.Runtime.Interop.Check(Int32 returnValue)
at Autodesk.AutoCAD.PlottingServices.PlotInfoValidator.Validate(PlotInfo info)
at PlotNET.PlotterClass.NETPlot() in M:\Programming\Projects\ACAD_Development\PlotNET\PlotNET\Class.cs:line 106
-
forgot this:
pInfo.Layout = LayoutManager.Current.GetLayoutId("Model");
:ugly:
P.S. - If you are a VB programmer that is just getting your head around C# and someone says that you can convert C++ code to C# if you "just change -> to ." it is good to remember that the person making the suggestion knows both C++ and C# whereas you don't. Unless you know C++ you will likely hurt your brain when attempting such a maneuver, possibly bashing it into a ::.
-
I am moving into C#, and have been able to port most of my code in C++/ARX to C#, but not by simple replacing the -> for . - it requires more than that, at least for me... (I even have been able to port VB to C# - and it is much easier - but I do not know much about VB)
What, sample in the SDK are you porting?
-
Mark, have you gotten it to work or would you like and example of how to use a pagesetup...that's the way I do it.
-
What, sample in the SDK are you porting?
I was really just trying to understand the plotting code.
What ended up helping me was porting from a script file to C#.
That showed me I was missing the Layout.
Glenn,
I do have something working but I would really appreciate an example of using pagesetup since that was my first inclination.
-
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);
}
}
-
Are you using 2007? I had some plot code that worked just fine in 2005, and completely bombs in 2007 (causes a fatal exception and corrupts the current profile....) Has anyone experienced similar trouble with 2007 for plotting compared to previous versions?
- Scott
-
Are you using 2007? I had some plot code that worked just fine in 2005, and completely bombs in 2007 (causes a fatal exception and corrupts the current profile....) Has anyone experienced similar trouble with 2007 for plotting compared to previous versions?
- Scott
AutoCAD 2007
VS 2005
-
So has anybody updated plotting for 2010 yet?
-
I copied this from Kean W (Through the Interface) and made changes to plot to my machine. Seems really really slow though
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.PlottingServices;
namespace PlottingApplication
{
public class PlottingCommands
{
[CommandMethod("simplot")]
static public void SimplePlot()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
Transaction tr = db.TransactionManager.StartTransaction();
using (tr)
{
// We'll be plotting the current layout
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForRead);
Layout lo = (Layout)tr.GetObject(btr.LayoutId, OpenMode.ForRead);
// We need a PlotInfo object
// linked to the layout
PlotInfo pi = new PlotInfo();
pi.Layout = btr.LayoutId;
// We need a PlotSettings object
// based on the layout settings
// which we then customize
PlotSettings ps =
new PlotSettings(lo.ModelType);
ps.CopyFrom(lo);
// The PlotSettingsValidator helps
// create a valid PlotSettings object
PlotSettingsValidator psv = PlotSettingsValidator.Current;
// We'll plot the extents, centered and
// scaled to fit
psv.SetPlotType(ps, Autodesk.AutoCAD.DatabaseServices.PlotType.Extents);
psv.SetUseStandardScale(ps, true);
//psv.SetStdScaleType(ps, StdScaleType.ScaleToFit);
psv.SetStdScaleType(ps, StdScaleType.StdScale1To1);
psv.SetPlotCentered(ps, true);
// We'll use the standard DWF PC3, as
// for today we're just plotting to file
psv.SetPlotConfigurationName(ps, "2010 Oce.pc3", "ARCH_expand_D_(36.00_x_24.00_Inches)");
//psv.SetPlotConfigurationName(ps, "DWF6 ePlot.pc3", "ANSI_A_(8.50_x_11.00_Inches)");
// We need to link the PlotInfo to the
// PlotSettings and then validate it
pi.OverrideSettings = ps;
PlotInfoValidator piv = new PlotInfoValidator();
piv.MediaMatchingPolicy = MatchingPolicy.MatchEnabled;
piv.Validate(pi);
// A PlotEngine does the actual plotting
// (can also create one for Preview)
if (PlotFactory.ProcessPlotState == ProcessPlotState.NotPlotting)
{
PlotEngine pe = PlotFactory.CreatePublishEngine();
using (pe)
{
// Create a Progress Dialog to provide info
// and allow thej user to cancel
PlotProgressDialog ppd = new PlotProgressDialog(false, 1, true);
using (ppd)
{
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;
// Let's start the plot, at last
ppd.OnBeginPlot();
ppd.IsVisible = true;
pe.BeginPlot(ppd, null);
// We'll be plotting a single document
pe.BeginDocument(
pi,
doc.Name,
null,
1,
false,
//true, // Let's plot to file
"c:\\test-output"
);
// Which contains a single sheet
ppd.OnBeginSheet();
ppd.LowerSheetProgressRange = 0;
ppd.UpperSheetProgressRange = 100;
ppd.SheetProgressPos = 0;
PlotPageInfo ppi = new PlotPageInfo();
pe.BeginPage(
ppi,
pi,
true,
null
);
pe.BeginGenerateGraphics(null);
pe.EndGenerateGraphics(null);
// Finish the sheet
pe.EndPage(null);
ppd.SheetProgressPos = 100;
ppd.OnEndSheet();
// 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."
);
}
}
}
}
}
-
Have you checked out the .NET Developers guide? :wink:
-
I did check the developers guide, and found a similiar post of code. I did find that I "thought" I had disabled background plotting, but had not, which is why it seemed so slow