Message 1 of 2
Plot Script not working. Need help

Not applicable
12-06-2010
08:20 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi Guys,
I have been working on this plot script for a while now and I had it working at one time but now it does not seem to work. It is giving me errors in random places depending on the instance. I am getting errors on the units line. I have indicated where my errors are. They are not consistant. It will show in one spot at runtime now, and another at runtime later. Need help. Thanks in advance.
Heres the code.
<CommandMethod("MB_PlotAllTabs")> _ Public Sub MB_PlotAllTabs() Dim LayoutPlotSettings As String() Dim LayoutName As String Dim PageSize As String Dim PageName As String Dim PltOrientation As String 'Get current list of tabs in order Dim myTabList As SortedDictionary(Of Integer, String).ValueCollection = MB_LayoutTabList() '' Get the current document and database, and start a transaction Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument Dim acCurDb As Database = acDoc.Database Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction() '' Reference the Layout Manager Dim acLayoutMgr As LayoutManager acLayoutMgr = LayoutManager.Current For Each TabName In myTabList 'Get plotsettings from current layout LayoutPlotSettings = MB_DeterminePlotSettings() LayoutName = LayoutPlotSettings(0) PageSize = LayoutPlotSettings(1) PageName = LayoutPlotSettings(2) PltOrientation = LayoutPlotSettings(3) 'Get Default Plot Settings from XML File If PageName = "default" Then PageName = "dsize" End If Dim DefPrinterName As String = CoreClass.GetXMLSetting("printersettings", PageName, "printername") Dim DefPaperName As String = CoreClass.GetXMLSetting("printersettings", PageName, "papername") Dim DefUnits As String = CoreClass.GetXMLSetting("printersettings", PageName, "units") Dim DefScale As String = CoreClass.GetXMLSetting("printersettings", PageName, "scale") Dim DefOffset As String = CoreClass.GetXMLSetting("printersettings", PageName, "offset") Dim DefOrient As String = CoreClass.GetXMLSetting("printersettings", PageName, "orientation") Dim DefPlotStyle As String = CoreClass.GetXMLSetting("printersettings", PageName, "plotstyle") MsgBox(LayoutName, MsgBoxStyle.OkOnly) MsgBox(PageSize, MsgBoxStyle.OkOnly) MsgBox(PageName, MsgBoxStyle.OkOnly) MsgBox(PltOrientation, MsgBoxStyle.OkOnly) MsgBox(DefPrinterName, MsgBoxStyle.OkOnly) MsgBox(DefPaperName, MsgBoxStyle.OkOnly) MsgBox(DefUnits, MsgBoxStyle.OkOnly) MsgBox(DefScale, MsgBoxStyle.OkOnly) MsgBox(DefOffset, MsgBoxStyle.OkOnly) MsgBox(DefOrient, MsgBoxStyle.OkOnly) MsgBox(DefPlotStyle, MsgBoxStyle.OkOnly) 'make array of offset points, need to convert to double on use Dim OffsetPoints As String() = DefOffset.Split(New Char() {","c}) 'Get the current layout Dim acLayout As Layout acLayout = acTrans.GetObject(acLayoutMgr.GetLayoutId(LayoutName), OpenMode.ForRead) 'Get the PlotInfo from the layout Dim acPlInfo As PlotInfo = New PlotInfo() acPlInfo.Layout = acLayout.ObjectId 'Get a copy of the PlotSettings from the layout Dim acPlSet As PlotSettings = New PlotSettings(acLayout.ModelType) acPlSet.CopyFrom(acLayout) 'Update the PlotSettings object Dim acPlSetVdr As PlotSettingsValidator = PlotSettingsValidator.Current '////////////////// Begin configuration //////////////// 'Set the plot type acPlSetVdr.SetPlotType(acPlSet, Autodesk.AutoCAD.DatabaseServices.PlotType.Extents) 'Set the plot scale acPlSetVdr.SetUseStandardScale(acPlSet, True) 'acPlSetVdr.SetCustomPrintScale(acPlSet, CustomScale) acPlSetVdr.SetStdScaleType(acPlSet, StdScaleType.StdScale1To1) 'Set the offsets (always takes default from XML) acPlSetVdr.SetPlotCentered(acPlSet, False) acPlSetVdr.SetPlotOrigin(acPlSet, New Point2d(CType(OffsetPoints(0), Double), CType(OffsetPoints(1), Double))) 'Set the paper units (always takes default from XML) If DefUnits = "Millimeters" Then acPlSetVdr.SetPlotPaperUnits(acPlSet, PlotPaperUnit.Millimeters) Else acPlSetVdr.SetPlotPaperUnits(acPlSet, PlotPaperUnit.Inches)'<-----HAD AN ERROR HERE End If 'Set the paper orientation rotation (use dynamic if not default) If Not PageName = "default" Then If PltOrientation = "Landscape" Then acPlSetVdr.SetPlotRotation(acPlSet, PlotRotation.Degrees000) Else acPlSetVdr.SetPlotRotation(acPlSet, PlotRotation.Degrees090) End If Else If DefOrient = "Landscape" Then acPlSetVdr.SetPlotRotation(acPlSet, PlotRotation.Degrees000) Else acPlSetVdr.SetPlotRotation(acPlSet, PlotRotation.Degrees090) End If End If 'Set the plot device to use acPlSetVdr.SetPlotConfigurationName(acPlSet, "DWG To PDF.pc3", "ANSI A (8.50 x 11.00 Inches)") '<----HAD CONSISTANT ERRORS HERE, I REPLACED MY VARS WITH HARD STRINGS TO DEBUG '' Set the plot info as an override since it will '' not be saved back to the layout acPlInfo.OverrideSettings = acPlSet '' Validate the plot info Dim acPlInfoVdr As PlotInfoValidator = New PlotInfoValidator() acPlInfoVdr.MediaMatchingPolicy = MatchingPolicy.MatchEnabled acPlInfoVdr.Validate(acPlInfo) '' Check to see if a plot is already in progress If PlotFactory.ProcessPlotState = Autodesk.AutoCAD.PlottingServices.ProcessPlotState.NotPlotting Then Using acPlEng As PlotEngine = PlotFactory.CreatePublishEngine() '' Track the plot progress with a Progress dialog Dim acPlProgDlg As PlotProgressDialog = New PlotProgressDialog(False, 1, True) Using (acPlProgDlg) '' Define the status messages to display when plotting starts acPlProgDlg.PlotMsgString(PlotMessageIndex.DialogTitle) = "Plot Progress" acPlProgDlg.PlotMsgString(PlotMessageIndex.CancelJobButtonMessage) = "Cancel Job" acPlProgDlg.PlotMsgString(PlotMessageIndex.CancelSheetButtonMessage) = "Cancel Sheet" acPlProgDlg.PlotMsgString(PlotMessageIndex.SheetSetProgressCaption) = "Sheet Set Progress" acPlProgDlg.PlotMsgString(PlotMessageIndex.SheetProgressCaption) = "Sheet Progress" '' Set the plot progress range acPlProgDlg.LowerPlotProgressRange = 0 acPlProgDlg.UpperPlotProgressRange = 100 acPlProgDlg.PlotProgressPos = 0 '' Display the Progress dialog acPlProgDlg.OnBeginPlot() acPlProgDlg.IsVisible = True '' Start to plot the layout acPlEng.BeginPlot(acPlProgDlg, Nothing) '' Define the plot output acPlEng.BeginDocument(acPlInfo, acDoc.Name, Nothing, 1, False, Nothing) '<----HAD AN ERROR HERE '' Display information about the current plot acPlProgDlg.PlotMsgString(PlotMessageIndex.Status) = "Plotting: " & acDoc.Name & " - " & TabName '' Set the sheet progress range acPlProgDlg.OnBeginSheet() acPlProgDlg.LowerSheetProgressRange = 0 acPlProgDlg.UpperSheetProgressRange = 100 acPlProgDlg.SheetProgressPos = 0 '' Plot the first sheet/layout Dim acPlPageInfo As PlotPageInfo = New PlotPageInfo() acPlEng.BeginPage(acPlPageInfo, acPlInfo, True, Nothing) acPlEng.BeginGenerateGraphics(Nothing) '<-------HAD AN ERROR HERE acPlEng.EndGenerateGraphics(Nothing) '' Finish plotting the sheet/layout acPlEng.EndPage(Nothing) acPlProgDlg.SheetProgressPos = 100 acPlProgDlg.OnEndSheet() '' Finish plotting the document acPlEng.EndDocument(Nothing) '' Finish the plot acPlProgDlg.PlotProgressPos = 100 acPlProgDlg.OnEndPlot() acPlEng.EndPlot(Nothing) End Using End Using End If Next End Using 'Clear Settings LayoutPlotSettings = Nothing LayoutName = Nothing PageSize = Nothing PageName = Nothing PltOrientation = Nothing End Sub