Printer Paper Sizes

Printer Paper Sizes

Anonymous
Not applicable
4,904 Views
14 Replies
Message 1 of 15

Printer Paper Sizes

Anonymous
Not applicable

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.

0 Likes
Accepted solutions (1)
4,905 Views
14 Replies
Replies (14)
Message 2 of 15

SENL1362
Advisor
Advisor
Accepted solution

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

 

1: QueryPlotters()

2: QueryMediaNames()

3: QueryPlotStyles()

4: QueryPaperSize()

5: QueryNamedPlotStyles()

6: QueryDetailedNamedPlotStyles()

 

 

 

Message 3 of 15

Anonymous
Not applicable

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.

 

0 Likes
Message 4 of 15

SENL1362
Advisor
Advisor

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.

 

0 Likes
Message 5 of 15

Anonymous
Not applicable

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.

 

0 Likes
Message 6 of 15

SENL1362
Advisor
Advisor

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

 

 

 

0 Likes
Message 7 of 15

Anonymous
Not applicable

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

0 Likes
Message 8 of 15

SENL1362
Advisor
Advisor

 

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"

0 Likes
Message 9 of 15

Anonymous
Not applicable

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.

0 Likes
Message 10 of 15

jeff
Collaborator
Collaborator

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
0 Likes
Message 11 of 15

Anonymous
Not applicable

we may be thinking of different things but I use Public

0 Likes
Message 12 of 15

Anonymous
Not applicable

We may be a cross-purposes.

 

You can define variables as Public, in which case they can be accessed across different classes and modules.

0 Likes
Message 13 of 15

jeff
Collaborator
Collaborator

What you are calling a variable still has to be accessed through a object.

 

In VB when you use a Module which is just a shared class it uses Type Promotion  to promote the members to namespace scope, but create a class with the same name and you have to type module name.

 

The only declarations allowed at namespace level are module, interface, class, delegate, enumeration, and structure declarations.

 

 

 

 

You can also find your answers @ TheSwamp
0 Likes
Message 14 of 15

Anonymous
Not applicable

We are sort of getting away from the point. Thanks anyway.

 

0 Likes
Message 15 of 15

Anonymous
Not applicable
Sorry for necro post... How do this function on VBA? If it possible...
0 Likes