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

PlotSettingsValidator, SetStdScale Error

10 REPLIES 10
Reply
Message 1 of 11
PacificorpJB
932 Views, 10 Replies

PlotSettingsValidator, SetStdScale Error

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

10 REPLIES 10
Message 2 of 11
fieldguy
in reply to: PacificorpJB

I've seen this behaviour in the editor before - eg. scaling viewports.

 

Try 4762 : 10000 to satisfy the integer complaint.

Message 3 of 11
PacificorpJB
in reply to: fieldguy

Hi Fieldguy --

 

Thanks for the input, same thing though Im afraid (4762:10000) I think it's setstdcale call th's actually throwing the error and at that point the value is back to a decimal (0.4762...); which makes the error even more enigmatic . . .where is the interger it's refering to?

 

Thanks though.

Message 4 of 11
fieldguy
in reply to: PacificorpJB

Try this maybe.  I know it compiles and runs but I have not checked the scale on the output.

 

Dim myscale As CustomScale = NewCustomScale(4762, 10000)

psv.SetCustomPrintScale(ps, myscale)

 

 

Message 5 of 11
CADKarasu
in reply to: PacificorpJB

Great, that pretty much got it with the following modifications to get it to work with all the possible values in my form.

Thanks so much for your help.

 

Dim psv AsPlotSettingsValidator = PlotSettingsValidator.Current

 

With psv

 

If bplot.Scale2Fit.IsChecked Then

      .SetStdScaleType(pltsettings,StdScaleType.ScaleToFit)

      .SetUseStandardScale(pltsettings,True)

ElseIf bplot.ScaleB.Text = "N/A" Then

     .SetUseStandardScale(pltsettings,False)

     Dim cscale AsNew Autodesk.AutoCAD.DatabaseServices.CustomScale_

                     (CDbl(bplot.ScaleA.Text), 1.0)

     .SetCustomPrintScale(pltsettings, cscale)

Else

     Dim inchval AsDouble = CDbl(bplot.ScaleA.Text)

     Dim unitval AsDoubleCDbl(bplot.ScaleB.Text)

     Dim myscale AsNewCustomScale(inchval, unitval)

     .SetCustomPrintScale(pltsettings, myscale)

EndIf

EndIf

 

EndWith

 

Thanks Again.

Message 6 of 11
fieldguy
in reply to: CADKarasu

No problem - glad I could help.

 

Please mark the thread with an "Accepted Solution".  I think you need to do that as the creator.

Message 7 of 11
CADKarasu
in reply to: fieldguy

Be happy to but how exactly do I go about doing that?  Poked around in all the options but couldn't find the place to do so?

Message 8 of 11
fieldguy
in reply to: CADKarasu

As the creator of the msg, you should see this button in all of the replies.

 

accepter.png

Message 9 of 11
PacificorpJB
in reply to: fieldguy

Accepted Solution [cid:image001.png@01CD2D1C.5E2E76D0] Jim Brinkmeyer Systems Analyst 503 813 6615 Jim.Brinkmeyer@PacifiCorp.Com
Message 10 of 11
CADKarasu
in reply to: CADKarasu

Hum... Except I don't.  There's nothing under the Reply link at all and I checked severl emails.  Would totally like to give you credit though.

Message 11 of 11
fieldguy
in reply to: CADKarasu

It's more about clean up and tying up loose ends than credit.  I thought it would/should be easy.  Oh well!  We tried eh?

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