V8i - VBA code for Printing from Excel

Hello all,

I am starting with VB for microstation and I would like to create a VBA macro in EXCEL that would allow me to print a selection of Microstation files to PDF files(based in a column).

For the looping process in Excel and opening the Microstation files from Excel, I do not have a problem but for the Print, aie aie!

Therefore, I used the Record facilities in VBA Project Manager and the result is below (Macro1). It is working fine but the only anoing thing is that it open 2 dialog Boxes:

      1 for the "select Printer Driver Configuration File" and 1 for the "Save Print As".

How could I avoid opening these 2 dialog Boxes and forcing the selection of a Printer Conf File and save as

 

Hello all,

I am starting with VB for microstation and I would like to create a VBA macro in EXCEL that would allow me to print a selection of Microstation files (based in a column).

For the looping process in Excel and opening the Microstation files from Excel, I do not have a problem but for the Print, aie aie!

Therefore, I used the Record facilities in VBA Project Manager and the result is below (Macro1). It is working fine but the only boring thing is that it open 2 dialog Boxes and this for all files!

      1 for the "select Printer Driver Configuration File" and 1 for the "Save Print As".

Does anyone could help me on this? Thanks in adcance

Herve

Sub Macro1()
    Dim startPoint As Point3d
    Dim point As Point3d, point2 As Point3d
    Dim lngTemp As Long
'   Start a command
    CadInputQueue.SendCommand "FIT VIEW EXTENDED 1"
    CadInputQueue.SendCommand "DIALOG PLOT"
    CadInputQueue.SendCommand "MDL SILENTUNLOAD PENTABLE"
    CadInputQueue.SendCommand "PRINT DRIVER"
    Dim modalHandler As New Macro1ModalHandler
    AddModalDialogEventsHandler modalHandler
'   The following statement opens modal dialog "Select Printer Driver Configuration File"
    CadInputQueue.SendCommand "MDL SILENTUNLOAD PENTABLE"
'   Set a variable associated with a dialog box
    SetCExpressionValue "plotUI.uiPaperName", "ISO A3", "PLOTDLG"
    SetCExpressionValue "plotUI.uiPaperName", "ISO A3", "PLOTDLG"
    CadInputQueue.SendCommand "MDL SILENTUNLOAD PENTABLE"
    CadInputQueue.SendCommand "PRINT BOUNDARY FIT ALL"
    CadInputQueue.SendCommand "MDL SILENTUNLOAD PENTABLE"
'   The following statement opens modal dialog "Save Print As"
    CadInputQueue.SendCommand "PRINT EXECUTE"
    CadInputQueue.SendCommand "MDL SILENTUNLOAD PENTABLE"
    CadInputQueue.SendCommand "PRINT EXIT PLOTDLG"
    CadInputQueue.SendCommand "MDL UNLOAD PLOTDLG"
    RemoveModalDialogEventsHandler modalHandler
    CommandState.StartDefaultCommand
End Sub

Implements IModalDialogEvents
Private Sub IModalDialogEvents_OnDialogClosed(ByVal DialogBoxName As String, ByVal DialogResult As MsdDialogBoxResult)
End SubPrivate Sub IModalDialogEvents_OnDialogOpened(ByVal DialogBoxName As String, DialogResult As MsdDialogBoxResult)
    If DialogBoxName = "Select Printer Driver Configuration File" Then
        CadInputQueue.SendCommand "MDL COMMAND MGDSHOOK,fileList_setDirectoryCmd C:\Documents and Settings\All Users\Application Data\Bentley\MicroStation V8i (SELECTseries 1)\WorkSpace\System\pltcfg\"
        CadInputQueue.SendCommand "MDL COMMAND MGDSHOOK,fileList_setFileNameCmd Herve_Mono_pdf.pltcfg"
    '   Remove the following line to let the user close the dialog box.
        DialogResult = msdDialogBoxResultOK
    End If  ' Select Printer Driver Configuration File
    If DialogBoxName = "Save Print As" Then
        CadInputQueue.SendCommand "MDL COMMAND MGDSHOOK,fileList_setDirectoryCmd C:\Documents and Settings\All Users\Application Data\Bentley\MicroStation V8i (SELECTseries 1)\WorkSpace\Projects\Untitled\out\"
        CadInputQueue.SendCommand "MDL COMMAND MGDSHOOK,fileList_setFileNameCmd T1201.pdf"
    '   Remove the following line to let the user close the dialog box.
        DialogResult = msdDialogBoxResultOK
    End If  ' Save Print As
End Sub

 

Parents
  • Printer Keyins

    You can do what you want using printer keyins. The trick is  …

    1. load the printer application without showing its dialog
    2. set print parameters using print keyins
    3. issue the print command to create your PDF

    The printer application is PLOTDLG …

    CadInputQueue.SendCommand "MDL LOAD PLOTDLG"

    The application commands all start with PRINT. You probably want to specify a printer configuration (.pltcfg) and possible a printer name …

    CadInputQueue.SendCommand "PRINT DRIVER " & "pdf.pltcfg"
    CadInputQueue.SendCommand "PRINT PRINTERNAME " & "Super-Duper Plotter"
    CadInputQueue.SendCommand "PRINT DIALOG"

    You can find further help on print commands from MicroStation help and using the keyin browser. If you keyin MDL LOAD PLOTCFG then keyin PRINT you will see a long list of options.

    Regards, Jon Summers
    LA Solutions

     
    Regards, Jon Summers
    LA Solutions

  • Thanks Jon for your quick solution,

    i will look at that asap.

  • Hello Jon,

    so I manage to select the printer configuration (.pltcfg) without opening the dialog box that is a good thing.

    The .pltcfg is a custom of a bentley driver (to create PDF) but i stil can not figure out how to select a directory to save the PDF and to na,e that PDF as the name of the actual design file...without opening the SAVE AS dialog box;

    in the macro, I have  CadInputQueue.SendCommand "PRINT EXECUTE " and this opens the dialog box; I would like to avoid that dialog box.

    Do you have any tip?? Thank you in advance.

    Sub PrintBW()

       Dim startPoint As Point3d

       Dim point As Point3d, point2 As Point3d

       Dim lngTemp As Long

    '   Start a command

       CadInputQueue.SendCommand "FIT VIEW EXTENDED 1"

       CadInputQueue.SendCommand "DIALOG PLOT"

    '   Set a variable associated with a dialog box

       CadInputQueue.SendCommand "PRINT DRIVER C:\ProgramData\Bentley\MicroStation\WorkSpace\System\pltcfg\B&W_pdf.pltcfg"

       Dim modalHandler As New Macro2ModalHandler

       AddModalDialogEventsHandler modalHandler

    ''   The following statement opens modal dialog "Select Printer Driver Configuration File"

       SetCExpressionValue "plotUI.uiPaperName", "ISO A3", "PLOTDLG"

       CadInputQueue.SendCommand "PRINT BOUNDARY FIT ALL"

    ''   The following statement opens modal dialog "Save Print As"'

       CadInputQueue.SendCommand "PRINT EXECUTE "

       CadInputQueue.SendCommand "PRINT EXIT PLOTDLG"

       CadInputQueue.SendCommand "MDL UNLOAD PLOTDLG"

    '    RemoveModalDialogEventsHandler modalHandler

       CommandState.StartDefaultCommand

    End Sub

  • Unknown said:
    I can not figure out how to select a directory to save the PDF and to name that PDF as the name of the actual design file

    The MS_PLTFILES configuration variable tells Bentley drivers where to put the output file.  Search for Printing Configuration Variables in MicroStation help.

    The .pltcfg file provides a way to name the output.  Post a question to the Printing Forum if you can't find it in help.

     
    Regards, Jon Summers
    LA Solutions

Reply
  • Unknown said:
    I can not figure out how to select a directory to save the PDF and to name that PDF as the name of the actual design file

    The MS_PLTFILES configuration variable tells Bentley drivers where to put the output file.  Search for Printing Configuration Variables in MicroStation help.

    The .pltcfg file provides a way to name the output.  Post a question to the Printing Forum if you can't find it in help.

     
    Regards, Jon Summers
    LA Solutions

Children