[VBA-CE U14] Get active Windows Printer name

Hi,

I am trying to get some information about the active printer.  This routine give me the Print Driver Name, the paper name, and the orientation.  What I am really missing is the Windows Printer Name.

How do I get the Windows Printer Name?  (IE. I can get a result of "Printer.pltcfg", but I also need to get the "HPOfficeJetPro" name from the active Windows printer.)

Sub ActivePrinterSettings()
    Dim Result As String
    CadInputQueue.SendCommand "DIALOG PLOT "
    Result = GetCExpressionValue("plotUI.uiPrinterName")
    Result = Result & vbNewLine & GetCExpressionValue("plotUI.uiPaperName")
    Result = Result & vbNewLine & IIf(GetCExpressionValue("plotUI.uiOrientation") = 0, "Portrait", "Landscape")
    Result = Result & vbNewLine & GetCExpressionValue("plotUI.uiFormSizeX") & ", " & GetCExpressionValue("plotUI.uiFormSizeY")
    MsgBox Result
End Sub

--Thanks,
--Robert Arnold

  • I am trying to get some information about the active printer

    MicroStation CONNECT Update 13 introduced the PrintManager object. There are a few other classes related to printing.

    We wrote a Printer Enumerator for VBA a year or two ago.

     
    Regards, Jon Summers
    LA Solutions

  • Hi Jon,
    I had seen a couple of your printer related pages.  I do appreciate your website and notes.  Right now I'm trying to find the active Microstation-Windows printer, rather than a list of printers.  Also, I see the PrintManager--which has events, but does not give a lot of info about the active settings.  Please let me know if I'm missing something.

    I'm hoping that this should be a simple GetCExpressionValue command.  I wish that I knew all the different plotui parameters.

    --Thanks,
    --Robert

  • Hi Robert,

    see the sample below. This used to work flawlesly in V8i, but it needs to be fixed for CONNECT.


    Private Declare Function mdlDialog_find Lib "stdmdlbltin.dll" _
                                            (ByVal DialogID As Long, _
                                             ByVal ownerMD As Long) As Long
                                             
    Private Declare Function mdlWindow_titleGet Lib "stdmdlbltin.dll" _
                                                (ByVal titleP As String, _
                                                 ByVal titleChars As Long, _
                                                 ByVal windowP As Long) As Long
    
    Private Declare Function mdlSystem_findMdlDesc Lib "stdmdlbltin.dll" _
                                                   (ByVal nameP As String) As Long    ' Returns a pointer to a structure
    
    ' Get printer name from window title
    Public Function GetPrinterName() As String
        Dim status As Long
        Dim lngPw As Long
        lngPw = 0
        Const strTaskID As String = "PLOTDLG"
        Const lngDialogID As Long = 1200&
    
        status = mdlSystem_findMdlDesc(strTaskID)
        If status <> 0 Then
            lngPw = mdlDialog_find(lngDialogID, status)
        End If
        
        'if plot dialog is not open
        If lngPw = 0 Then Exit Function
    
        Dim strTitle As String
        strTitle = Space$(255)
        mdlWindow_titleGet strTitle, 255, lngPw
        
        strTitle = Utils.TruncateAtEOS(strTitle)
        
        Dim name As String
        name = strTitle
        name = Left(name, InStrRev(name, "(") - 1)
        name = Mid(name, InStr(1, name, "-") + 1)
        GetPrinterName = Trim(name)
    End Function

     

    And these are other published expressions (again in V8i) that I know of:

    • plotdlgPrefs.plotDriverType ' 1=>BentleyPlotDriver 0=>WinPlotDriver
    • plotUI.uiFormSizeX
    • plotUI.uiFormSizeY
    • plotUI.uiNumCopiesToPrint
    • plotUI.uiDgnfilenm
    • plotUI.uiPaperDimStr
    • plotUI.uiPaperDimLabel
    • plotUI.uiPrintDest
    • plotUI.uiPlotArea
    • plotUI.uiPlotViewIndex

    Tom

  • Hi,

    Per , There is another CExpression: "plotUI.uiSysPrinterName" which returns the name of the selected printer. E.g. if  the expression "plotUI.uiPrinterName" returns "Windows printer", the expression "plotUI.uiSysPrinterName" returns the exact name of the selected Windows printer name.

    That means that my expanded test looks like:

    Sub ActivePrinterSettings()
        Dim Result As String
        CadInputQueue.SendCommand "DIALOG PLOT "
        Result = GetCExpressionValue("plotUI.uiPrinterName")
        Result = Result & vbNewLine & GetCExpressionValue("plotUI.uiSysPrinterName")
        Result = Result & vbNewLine & GetCExpressionValue("plotUI.uiPaperName")
        Result = Result & vbNewLine & IIf(GetCExpressionValue("plotUI.uiOrientation") = 0, "Portrait", "Landscape")
        Result = Result & vbNewLine & GetCExpressionValue("plotUI.uiFormSizeX") & ", " & GetCExpressionValue("plotUI.uiFormSizeY")
        MsgBox Result
    End Sub

    Thanks again for all the suggestions.

    --Thanks,
    --Robert

    Answer Verified By: RobertArnold