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

    .NET

    Reply
    Valued Contributor
    Posts: 70
    Registered: ‎02-17-2005
    Accepted Solution

    Printer Paper Sizes

    523 Views, 13 Replies
    12-27-2011 02:33 AM

    I am trying to get the various sizes of paper for each printer. I can do this for Windows Printers.

    But I also want to get the sizes of the .pc3 files.

    So far I have this.

       Friend Function GetPaperSizes(ByVal Plotter As String) As StringCollection
          For i = 0 To PrinterSettings.InstalledPrinters.Count - 1
             ps.PrinterName = PrinterSettings.InstalledPrinters.Item(i)
             For j = 0 To ps.PaperSizes.Count - 1
                pz = ps.PaperSizes.Item(j)
                AcadEdt.WriteMessage(vbLf & pz.PaperName & " w=" & pz.Width * 0.254 & " h=" & pz.Height * 0.254)
             Next
          Next
          Dim p As PlotConfig = PlotConfigManager.SetCurrentConfig(Plotter)
          Dim t As String = p.Comment
          AcadEdt.WriteMessage(vbLf & t)
          Using tr As Transaction = CurDb.TransactionManager.StartTransaction()
             Dim lyMgr As LayoutManager = LayoutManager.Current                               '  Get the current layout
             Dim cLayout As Layout = tr.GetObject(lyMgr.GetLayoutId(lyMgr.CurrentLayout), OpenMode.ForRead)
             Dim cpInfo As PlotInfo = New PlotInfo()                                          '  Get the PlotInfo from the layout 
             cpInfo.Layout = cLayout.ObjectId                                                 '  Get a copy of the PlotSettings from the layout
             Dim cpSet As PlotSettings = New PlotSettings(cLayout.ModelType)
             cpSet.CopyFrom(cLayout)                                                          '  Update the PlotConfigurationName property of the PlotSettings object
             Dim s As String = pl.Comment
             '  Returns a list of media sizes that are supported for the current device or the PC3 files. (Acad Help)
             '  except that it always returns ""
             Dim cpVdr As PlotSettingsValidator = PlotSettingsValidator.Current
             Try
                Return cpVdr.GetCanonicalMediaNameList(cpSet)
             Catch ex As Exception
                Return Nothing
             End Try
          End Using
       End Function

     So,

    I am looking for the various sheet descriptions + width and height.

     

    All help gratefully received.

    Please use plain text.
    Valued Contributor
    SENL1362
    Posts: 58
    Registered: ‎07-20-2011

    Re: Printer Paper Sizes

    12-28-2011 02:41 AM in reply to: stuartnathan

    These (C#) samples may help you to find the answers.

     

    1: QueryPlotters()

    2: QueryMediaNames()

    3: QueryPlotStyles()

    4: QueryPaperSize()

    5: QueryNamedPlotStyles()

    6: QueryDetailedNamedPlotStyles()

     

     

     

    Please use plain text.
    Valued Contributor
    Posts: 70
    Registered: ‎02-17-2005

    Re: Printer Paper Sizes

    12-28-2011 03:01 AM in reply to: SENL1362

    Thanks for your help.

    I've got a bit of this already, but you may well have found the missing bits for me.

    Let me have a look and I'll get back to you.

     

    Please use plain text.
    Valued Contributor
    SENL1362
    Posts: 58
    Registered: ‎07-20-2011

    Re: Printer Paper Sizes

    12-28-2011 03:10 AM in reply to: stuartnathan

    Watchout for the custom papersizes when creating NamedPlotStyles.

    These custom papersizes are referenced by their internal id and those  may alter when newley defined in a PC3 file or in the Printer.

     

    Please use plain text.
    Valued Contributor
    Posts: 70
    Registered: ‎02-17-2005

    Re: Printer Paper Sizes

    12-28-2011 03:23 AM in reply to: SENL1362

    OK. Converted to VB and tried the code

       Public Sub QueryDetailedNamedPlotStyles()
           Dim plSetVdr As PlotSettingsValidator = PlotSettingsValidator.Current
          CurDb.TileMode = False
          AcadEdt.SwitchToPaperSpace()
          Using tr As Transaction = CurDb.TransactionManager.StartTransaction()
             Dim plotDict As DBDictionary = DirectCast(CurDb.PlotSettingsDictionaryId.GetObject(OpenMode.ForRead), DBDictionary)
             AcadEdt.WriteMessage(vbLf & "{0} NamedPlotStyles", plotDict.Count)

     etc.

    plotDict.Count alwats returns 0, so I don't get the sizes etc.

     

    I went to Page Setup, ensured I had a plotter set etc.

     

    However, in reality the idea is to plot automatically so people don't have to setup Page.

     

    Please use plain text.
    Valued Contributor
    SENL1362
    Posts: 58
    Registered: ‎07-20-2011

    Re: Printer Paper Sizes

    12-28-2011 03:43 AM in reply to: stuartnathan

    Propably an empty drawing -- no Named Plot Styles.

    Try to add some from within paperspace: File/Page Setup Manager/New...

    Enter Printer/Pc3, Papersize, PlotArea, PlotScale, Orientation  and Pen Table

     

     

     

    Please use plain text.
    Valued Contributor
    Posts: 70
    Registered: ‎02-17-2005

    Re: Printer Paper Sizes

    12-28-2011 04:09 AM in reply to: SENL1362

    Sorry. Didn't look closely enough.

    I think QueryMediaNames may do the trick.

     

    Incidently, I didn't know you could do what you do with the WriteMessage function. Neat.

     

    I'll get back

    Please use plain text.
    Valued Contributor
    SENL1362
    Posts: 58
    Registered: ‎07-20-2011

    Re: Printer Paper Sizes

    12-28-2011 04:30 AM in reply to: stuartnathan

     

    Incidently, I didn't know you could do what you do with the WriteMessage function. Neat.

     

    Do you referring to the Formatting of strings such as in:

      ed.WriteMessage("\n\tPaper: {0:0.00} X {1:0.00} ({2})",  ps.PlotPaperSize.X, ps.PlotPaperSize.Y, ps.CanonicalMediaName);


    You  can use that  in any  String  operation, like

       String myFormattedString =String.Format("{0:0.0}", TheValue);            // "0.0"

        String.Format("{0:0.0}", 0.0);            // "0.0"
        String.Format("{0:0.#}", 0.0);            // "0"

    Please use plain text.
    Valued Contributor
    Posts: 70
    Registered: ‎02-17-2005

    Re: Printer Paper Sizes

    12-28-2011 08:07 AM in reply to: SENL1362

    I've got it working and it is just what I want.

     

    PSizes is used elsewhere and is a global variable. It contains the Width and Height and I use the CanonicalMediaName as a key.

    a_Paper.Suffix is read from an INI file and contains MM, or CM or INCHES etc.

     

    So my code is this:

     

       Public Sub QueryMediaNames()
          PSizes = New Collection
          Dim layMgr As LayoutManager = LayoutManager.Current
          Dim plSetVdr As PlotSettingsValidator = PlotSettingsValidator.Current
          Using tr As Transaction = CurDb.TransactionManager.StartTransaction()
             Dim ly As Layout = DirectCast(tr.GetObject(layMgr.GetLayoutId(layMgr.CurrentLayout), OpenMode.ForRead), Layout)
             Dim np As New PlotSettings(ly.ModelType)
             np.CopyFrom(ly)
             Dim canMedNames As StringCollection = plSetVdr.GetCanonicalMediaNameList(np)
             Dim i As Integer, s As String
             For Each c As String In canMedNames
                If c.ToUpper.Contains(a_Paper.Suffix.ToUpper) Then
                   i = InStr(c, "(")
                   If i > 0 Then
                      Dim p As gs_Size
                      s = c.Substring(i)
                      s = s.Substring(0, s.Length - 4)
                      i = InStr(s, "_x_")
                      p.Width = CSng(s.Substring(0, i - 1))
                      p.Height = CSng(s.Substring(i + 2))
                      PSizes.Add(p, c)
                   End If
                End If
             Next
          End Using
       End Sub

     Thanks for your help.

    I now need to use the paper sizes.

    Please use plain text.
    Mentor
    Posts: 241
    Registered: ‎05-12-2009

    Re: Printer Paper Sizes

    12-28-2011 09:39 AM in reply to: stuartnathan

    You can create a global variable using CIL but I do not think you can in VB.NET

    You can also find your answers @ TheSwamp
    Please use plain text.