.NET

Reply
Valued Contributor
stuartnathan
Posts: 70
Registered: ‎02-17-2005
Message 1 of 14 (862 Views)
Accepted Solution

Printer Paper Sizes

862 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.

Mentor
SENL1362
Posts: 156
Registered: ‎07-20-2011
Message 2 of 14 (843 Views)

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()

 

 

 

Valued Contributor
stuartnathan
Posts: 70
Registered: ‎02-17-2005
Message 3 of 14 (836 Views)

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.

 

Mentor
SENL1362
Posts: 156
Registered: ‎07-20-2011
Message 4 of 14 (832 Views)

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.

 

Valued Contributor
stuartnathan
Posts: 70
Registered: ‎02-17-2005
Message 5 of 14 (828 Views)

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.

 

Mentor
SENL1362
Posts: 156
Registered: ‎07-20-2011
Message 6 of 14 (822 Views)

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

 

 

 

Valued Contributor
stuartnathan
Posts: 70
Registered: ‎02-17-2005
Message 7 of 14 (817 Views)

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

Mentor
SENL1362
Posts: 156
Registered: ‎07-20-2011
Message 8 of 14 (815 Views)

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"

Valued Contributor
stuartnathan
Posts: 70
Registered: ‎02-17-2005
Message 9 of 14 (805 Views)

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.

Valued Mentor
jeff
Posts: 322
Registered: ‎05-12-2009
Message 10 of 14 (801 Views)

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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community