Jump to content

Plotting Specific Paper Sizes VBA


EGoldberg

Recommended Posts

All,

 

I'm looking for a little help with plotting specific paper sizes in VBA. I'm writing a program that gives the drafters in our group a little flexibility. The program allows them to pick available plotters from a list and then allows them to set up what paper sizes they want printed where. For instance, A size: InkJet 1 (8.5x11), B size: InkJet 1 (11x17), C size: Oce Plotter (... etc etc). All the drawings selected, if they are a certain size should then be plotted to the predetermined plotter.

 

I can get it to print to the proper printer but I don't know how to set the proper paper size. I've demonstrated an ability to do it using sendcommand, but I know that's poor programming. Is there a way of plottingtodevice using a specific available paper size?

Link to comment
Share on other sites

Well I figured out how to do that part. Now I just need to figure out how to get the program to wait long enough for the previous job to print before going onto the next one.

Link to comment
Share on other sites

Disregard this entirely... figured it out.

 

That's great.

 

For those following, what was the solution you arrived at ??

Link to comment
Share on other sites

I just typed a whole nice description up with details and everything but because there was links to my source info and I have 8 posts instead of the 9 necessary to post links; I lost everything. I don't really have the time to go into detail again but if you have any questions, please let me know. Basically I use two user forms. One contains a list of all the drawings and sizes, the other contains labels that store the plotter info and the paper sizes available to each plotter and what was selected for size A, B, C, D, and E. Using that info, the plotter info is compared to the size of the drawing and plotted to the correct plotter.

 

Userform1 - code snippet

For I = ListBox1.ListCount - 1 To 0 Step -1
   If ListBox1.Selected(I) = True Then
       tdd = Split(ListBox1.list(I), " - ")
       If tdd(2) <> "Size: Unknown!" Then
           Application.Documents(tdd(0)).Activate
           Thisdrawing.ActiveLayout = Thisdrawing.Layouts(tdd(1))
           sze = Right(tdd(2), 1)

var_BGPlot = Thisdrawing.GetVariable("BACKGROUNDPLOT")
Thisdrawing.SetVariable "BACKGROUNDPLOT", 0
bResult = True
getBackPlot = bResult

           Select Case sze
           Case "A"
               pltps = Split(PSS.Label9.Caption, " - ")
           Case "B"
               pltps = Split(PSS.Label10.Caption, " - ")
           Case "C"
               pltps = Split(PSS.Label11.Caption, " - ")

           Case "D"
               pltps = Split(PSS.Label12.Caption, " - ")

           Case "E"
               pltps = Split(PSS.Label13.Caption, " - ")


           End Select


Thisdrawing.PlotConfigurations.Add "TESTPC2", True
Thisdrawing.ActiveLayout.ConfigName = pltps(0)
Thisdrawing.PlotConfigurations.Item("TESTPC2").ConfigName = pltps(0)
Thisdrawing.ActiveLayout.StyleSheet = "NU-STD.stb"
Thisdrawing.PlotConfigurations.Item("TESTPC2").StyleSheet = "NU-STD.stb"
cmn = Thisdrawing.ActiveLayout.GetCanonicalMediaNames
For qq = 0 To UBound(cmn)
lcn = Thisdrawing.ActiveLayout.GetLocaleMediaName(cmn(qq))
    If lcn = pltps(1) Then

       Thisdrawing.ActiveLayout.CanonicalMediaName = cmn(qq)
       Thisdrawing.PlotConfigurations.Item("TESTPC2").CanonicalMediaName = cmn(qq)


       Thisdrawing.ActiveLayout.StandardScale = acScaleToFit
       Thisdrawing.PlotConfigurations.Item("TESTPC2").StandardScale = acScaleToFit
       Thisdrawing.ActiveLayout.CenterPlot = True
       Thisdrawing.PlotConfigurations.Item("TESTPC2").CenterPlot = True


       Thisdrawing.ActiveLayout.RefreshPlotDeviceInfo

       Thisdrawing.ActiveLayout.RefreshPlotDeviceInfo
       Thisdrawing.PlotConfigurations.Item("TESTPC2").RefreshPlotDeviceInfo

       Thisdrawing.ActiveLayout.RefreshPlotDeviceInfo

       Thisdrawing.Plot.PlotToDevice pltps(0) '"TESTPC2"
       Thisdrawing.ActiveLayout.RefreshPlotDeviceInfo

            Thisdrawing.PlotConfigurations.Item("TESTPC2").Delete




Thisdrawing.SetVariable "BACKGROUNDPLOT", var_BGPlot

    End If
Next


       End If
   End If
Next I

 

Userform(2) PSS

 

Private Declare Function GetProfileString Lib "kernel32" _
       Alias "GetProfileStringA" _
       (ByVal lpAppName As String, _
        ByVal lpKeyName As String, _
        ByVal lpDefault As String, _
        ByVal lpReturnedString As String, _
        ByVal nSize As Long) As Long

Private Const DC_PAPERNAMES = &H10
Private Declare Function DeviceCapabilities _
 Lib "winspool.drv" _
   Alias "DeviceCapabilitiesA" _
     (ByVal lpDeviceName As String, _
      ByVal lpPort As String, _
      ByVal iIndex As Long, _
      ByRef lpOutput As Any, _
      ByRef lpDevMode As Any) _
   As Long
Private Declare Function StrLen _
 Lib "kernel32.dll" _
   Alias "lstrlenA" _
     (ByVal lpString As String) _
   As Long

Private Sub CommandButton1_Click()
If ListBox1.ListIndex > -1 And ListBox2.ListIndex > -1 Then
   If CheckBox1.value = True Then
       Label9.Caption = ListBox1.value & " - " & ListBox2.value
   ElseIf CheckBox2.value = True Then
       Label10.Caption = ListBox1.value & " - " & ListBox2.value
   ElseIf CheckBox3.value = True Then
       Label11.Caption = ListBox1.value & " - " & ListBox2.value
   ElseIf CheckBox4.value = True Then
       Label12.Caption = ListBox1.value & " - " & ListBox2.value
   ElseIf CheckBox5.value = True Then
       Label13.Caption = ListBox1.value & " - " & ListBox2.value
   End If

End If
End Sub
Private Sub CommandButton2_Click()
PSS.Hide
End Sub
Private Sub Label5_Click()
End Sub

Private Sub ListBox1_Click()
   ListBox2.Clear
   Call WinNTSetDefaultPrinterAvailPS
End Sub
Private Sub UserForm_Initialize()
   Dim r As Long
   Dim Buffer As String
   ' Get the list of available printers from WIN.INI
   Buffer = Space(8192)
   r = GetProfileString("PrinterPorts", vbNullString, "", _
      Buffer, Len(Buffer))
   ' Display the list of printer in the ListBox List1

   ParseList ListBox1, Buffer

End Sub
Private Sub ParseList(lstCtl As Control, ByVal Buffer As String)
   Dim I As Integer
   Dim s As String
   Do
       I = InStr(Buffer, Chr(0))
       If I > 0 Then
           s = Left(Buffer, I - 1)
           If Len(Trim(s)) Then lstCtl.AddItem s
           Buffer = Mid(Buffer, I + 1)
       Else
           If Len(Trim(Buffer)) Then lstCtl.AddItem Buffer
           Buffer = ""
       End If
   Loop While I > 0
End Sub
Private Sub GetDriverAndPort(ByVal Buffer As String, DriverName As _
   String, PrinterPort As String)
   Dim iDriver As Integer
   Dim iPort As Integer
   DriverName = ""
   PrinterPort = ""
   ' The driver name is first in the string terminated by a comma
   iDriver = InStr(Buffer, ",")
   If iDriver > 0 Then
        ' Strip out the driver name
       DriverName = Left(Buffer, iDriver - 1)
       ' The port name is the second entry after the driver name
       ' separated by commas.
       iPort = InStr(iDriver + 1, Buffer, ",")
       If iPort > 0 Then
           ' Strip out the port name
           PrinterPort = Mid(Buffer, iDriver + 1, _
           iPort - iDriver - 1)
       End If
   End If
End Sub
Private Sub WinNTSetDefaultPrinterAvailPS()
   Dim Buffer As String
   Dim DeviceName As String
   Dim DriverName As String
   Dim PrinterPort As String
   Dim PrinterName As String
   Dim r As Long
   If ListBox1.ListIndex > -1 Then
       ' Get the printer information for the currently selected
       ' printer in the list. The information is taken from the
       ' WIN.INI file.
       Buffer = Space(1024)
       PrinterName = ListBox1.Text
       r = GetProfileString("PrinterPorts", PrinterName, "", _
           Buffer, Len(Buffer))
       ' Parse the driver name and port name out of the buffer
       GetDriverAndPort Buffer, DriverName, PrinterPort
       x = Buffer & " " & DriverName & " " & PrinterPort
     '  ListBox2.AddItem x

       PD = PrinterName
       PD1 = DriverName
   Ret = DeviceCapabilities(PD, PD1, DC_PAPERNAMES, ByVal 0&, ByVal 0&)
  'resize the array
   ReDim PaperSizes(0 To Ret * 64) As Byte
  'retrieve all the available paper names
   Call DeviceCapabilities(PD, PD1, DC_PAPERNAMES, PaperSizes(0), ByVal 0&)
  'convert the retrieved byte array to an ANSI string
   AllNames = StrConv(PaperSizes, vbUnicode)
    'loop through the string and search for the names of the papers
     For I = 1 To Len(AllNames) Step 64
       PaperSize = Mid(AllNames, I, 64)
       PaperSize = Left(PaperSize, StrLen(PaperSize))
      ' Msg = Msg & PaperSize & vbCrLf
      If InStr(LCase(PaperSize), "custom") = 0 Then
      ListBox2.AddItem PaperSize
      End If
     Next I
   'MsgBox "Supported Paper Sizes:" & vbCrLf & vbCrLf & Msg, vbOKOnly, PD0


   End If
End Sub

 

Do note that my code eliminates "custom" sized paper. Let me know if you have any questions. And again, sorry for the lack of details but I just don't have the time to explain again right now :-/

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...