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

Printer Paper Sizes

14 REPLIES 14
SOLVED
Reply
Message 1 of 15
stuartnathan
2787 Views, 14 Replies

Printer Paper Sizes

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.

14 REPLIES 14
Message 2 of 15
SENL1362
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()

 

 

 

Message 3 of 15
stuartnathan
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.

 

Message 4 of 15
SENL1362
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.

 

Message 5 of 15
stuartnathan
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.

 

Message 6 of 15
SENL1362
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

 

 

 

Message 7 of 15
stuartnathan
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

Message 8 of 15
SENL1362
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"

Message 9 of 15
stuartnathan
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.

Message 10 of 15
jeff
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
Message 11 of 15
stuartnathan
in reply to: jeff

we may be thinking of different things but I use Public

Message 12 of 15
stuartnathan
in reply to: jeff

We may be a cross-purposes.

 

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

Message 13 of 15
jeff
in reply to: stuartnathan

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
Message 14 of 15
stuartnathan
in reply to: jeff

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

 

Message 15 of 15
avton_kadov
in reply to: stuartnathan

Sorry for necro post... How do this function on VBA? If it possible...

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