PlotSettingsValidator, SetStdScale Error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Have a WPF form to input ploting parameters, all of which is typical to plotting in AutoCAD Select Scale (Custom or 1:1, 1:2, 2:1,1/128 - 1'-0" etc...). Have a special request for a 1:2.1 value for a non-typical output device (which works just fine in the AutoCAD plot dialog and as 0.4762 : 1 Input into Inches and Units variables). This value bombs my program with a 'Conversion from string "Error occured" to type 'Integer' is not valid' Error inside a try catch block.
Have tried several things and I'm petty sure I'm setting all 'PlotSettingsValidator' object settings correctly. So far nothing helps.
Entire procedure is included below (program bombs at: psv.SetStdScale(pltsettings, sc))
Any help you could offer would be highly valued.
CODE
Sub Plot(ByVal doc As Document, ByVal CurrLayout As Layout, _
ByVal Stamp As Boolean, ByVal StampFileName As String, _
ByVal plot2file As Boolean, Optional ByVal fname As String = Nothing)
Try
Dim tr As Transaction = _
Application.DocumentManager.MdiActiveDocument.TransactionManager._
StartTransaction
Try
If fname = "" Then fname = Nothing
Dim layoutMgr As LayoutManager = LayoutManager.Current, sc As Double
layoutMgr.CurrentLayout = CurrLayout.LayoutName
If Stamp Then
InsertBlock(doc.Database, StampFileName, "CONFIDENTIAL", False, 0, _
New Point3d(0, 0, 0))
End If
doc.SendStringToExecute("Zoom" & vbCr & "e" & vbCr, True, False, False)
Dim pltsettings As New PlotSettings(CurrLayout.ModelType)
pltsettings.CopyFrom(CurrLayout)
pltsettings.ScaleLineweights = bplot.ScaleLW.IsChecked
Dim pltinfo As New PlotInfo
pltinfo.Layout = CurrLayout.Id
Dim psv As PlotSettingsValidator = PlotSettingsValidator.Current
psv.SetPlotConfigurationName(pltsettings, bplot.PlotterCB.SelectedItem, _
bplot.SizeCB.SelectedItem.tag)
psv.SetCurrentStyleSheet(pltsettings, bplot.Penstyle_CB.SelectedItem)
psv.SetPlotPaperUnits(pltsettings, PlotPaperUnit.Inches)
psv.RefreshLists(pltsettings)
psv.SetPlotType(pltsettings, _
ConvertPlotType(bplot.TypeCB.SelectedItem.content))
psv.SetUseStandardScale(pltsettings, True)
psv.SetPlotRotation(pltsettings, _
ConvertPlotOrientation(bplot.RotationCB.SelectedItem.content, _
bplot.UpsideDownChk.IsChecked))
psv.SetPlotCentered(pltsettings, bplot.CenterPlot.IsChecked)
psv.SetPlotPaperUnits(pltsettings, PlotPaperUnit.Inches)
' -----------------------------------------------------------------
'Conversion from string "NA" to type 'Double' is not Valid.
'Conversion from string "Error occured" to type 'Integer' is not valid.
If bplot.Scale2Fit.IsChecked Then
psv.SetStdScaleType(pltsettings, StdScaleType.ScaleToFit)
Else
If bplot.ScaleB.Text = "N/A" Then
MsgBox("Plot 1. . .")
sc = CDbl(bplot.ScaleA.Text)
Else
MsgBox("Plot 2. . .")
Dim inchval, unitval As Double
inchval = CDbl(bplot.ScaleA.Text)
unitval = CDbl(bplot.ScaleB.Text)
MsgBox("Scalea.text = " & inchval.ToString & " Type = " & _
inchval.GetType.ToString & vbLf & "Scaleb.text = " & _
unitval.ToString & " Type = " & unitval.GetType.ToString)
sc = (inchval / unitval)
End If
MsgBox("Plot 2a. . .sc =" & sc.ToString)
psv.SetStdScale(pltsettings, sc)
MsgBox("Plot 2b. . .")
End If
' -------------------------------------------------------------
pltinfo.OverrideSettings = pltsettings
Dim pltprgdlg As New PlotProgressDialog(False, 1, True)
pltprgdlg.UpperPlotProgressRange = 100
pltprgdlg.LowerPlotProgressRange = 0
Dim plteng As PlotEngine = PlotFactory.CreatePublishEngine
MsgBox("Plot 3. . .")
Try
MsgBox("Plot 4. . .")
pltprgdlg.OnBeginPlot()
pltprgdlg.IsVisible = True
plteng.BeginPlot(Nothing, Nothing)
Dim validator As New PlotInfoValidator
validator.MediaMatchingPolicy = MatchingPolicy.MatchEnabled
validator.Validate(pltinfo)
plteng.BeginDocument(pltinfo, _
Application.DocumentManager.MdiActiveDocument.Database.Filename, _
Nothing, 1, plot2file, fname)
pltprgdlg.OnBeginSheet()
pltprgdlg.UpperSheetProgressRange = 100
pltprgdlg.LowerSheetProgressRange = 0
pltprgdlg.SheetProgressPos = 0
Dim pageinfo As New PlotPageInfo
plteng.BeginPage(pageinfo, pltinfo, True, Nothing)
plteng.BeginGenerateGraphics(Nothing)
plteng.EndGenerateGraphics(Nothing)
plteng.EndPage(Nothing)
pltprgdlg.SheetProgressPos = 100
pltprgdlg.OnEndSheet()
pltprgdlg.PlotProgressPos = 100
plteng.EndDocument(Nothing)
plteng.EndPlot(Nothing)
Catch ex As Exception
MsgBox("Error occured in function (Plot - Inner)" & vbCr & ex.Message, _
"Error occured")
End Try
pltprgdlg.Destroy()
plteng.Destroy()
tr.Commit()
Catch ex As Exception
MsgBox("Error occured in function (Plot- Middle)" & vbCr & ex.Message, _
"Error occured")
Finally
tr.Dispose()
End Try
Catch ex As SystemException
System.Windows.Forms.MessageBox.Show("Error occured in function (Plot- Outer)" & vbCr & _
"[" & ex.Message & "]", "Error occured")
Dim pname = (New StackTrace().GetFrame(1)).GetMethod.Name
Dim mname = (New StackFrame().GetMethod().Name)
LogError(ex, mname, pname)
End Try
End Sub