• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    Active Member
    PacificorpJB
    Posts: 7
    Registered: ‎10-25-2010

    PlotSettingsValidator, SetStdScale Error

    185 Views, 10 Replies
    05-07-2012 10:16 AM

    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

    Please use plain text.
    Valued Mentor
    Posts: 297
    Registered: ‎03-31-2005

    Re: PlotSettingsValidator, SetStdScale Error

    05-07-2012 12:29 PM in reply to: PacificorpJB

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

     

    Try 4762 : 10000 to satisfy the integer complaint.

    Please use plain text.
    Active Member
    PacificorpJB
    Posts: 7
    Registered: ‎10-25-2010

    Re: PlotSettingsValidator, SetStdScale Error

    05-07-2012 03:26 PM 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.

    Please use plain text.
    Valued Mentor
    Posts: 297
    Registered: ‎03-31-2005

    Re: PlotSettingsValidator, SetStdScale Error

    05-08-2012 08:29 AM 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)

     

     

    Please use plain text.
    Active Member
    CADKarasu
    Posts: 8
    Registered: ‎10-15-2010

    Re: PlotSettingsValidator, SetStdScale Error

    05-08-2012 12:00 PM 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.

    Please use plain text.
    Valued Mentor
    Posts: 297
    Registered: ‎03-31-2005

    Re: PlotSettingsValidator, SetStdScale Error

    05-08-2012 12:16 PM 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.

    Please use plain text.
    Active Member
    CADKarasu
    Posts: 8
    Registered: ‎10-15-2010

    Re: PlotSettingsValidator, SetStdScale Error

    05-08-2012 12:43 PM 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?

    Please use plain text.
    Valued Mentor
    Posts: 297
    Registered: ‎03-31-2005

    Re: PlotSettingsValidator, SetStdScale Error

    05-08-2012 01:05 PM in reply to: CADKarasu

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

     

    accepter.png

    Please use plain text.
    Active Member
    PacificorpJB
    Posts: 7
    Registered: ‎10-25-2010

    Re: PlotSettingsValidator, SetStdScale Error

    05-08-2012 01:14 PM in reply to: fieldguy
    Accepted Solution [cid:image001.png@01CD2D1C.5E2E76D0] Jim Brinkmeyer Systems Analyst 503 813 6615 Jim.Brinkmeyer@PacifiCorp.Com
    Please use plain text.
    Active Member
    CADKarasu
    Posts: 8
    Registered: ‎10-15-2010

    Re: PlotSettingsValidator, SetStdScale Error

    05-08-2012 01:19 PM 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.

    Please use plain text.