hexagon logo

File I/O Command - File Dialog default directory

Objective: When a user completes an inspection routine a file dialog will open allowing a user to choose a (.pdf) report which was previously created. The current inspection results will then be appended to the selected file.

The problem: The native PCDMIS File Dialog command does not allow a user to specify the initial path. The default behavior is to open the most recent used location. This is a problem because the user will need to navigate a rather large and confusing file system rather than having the initial path open where they need to be.

The question: does anyone know where the default (recent) path is stored so I can intervene programmatically and set the File Dialog path to whatever I need? I can not find it in the registry or any .dat or .log files that I've searched.

Using VBScript I have tried invoking a Microsoft Word FileDialog() to accomplish this task and it works how I want except I get a "Server Busy" error stating "This action cannot be completed because the other program is busy. Choose 'Switch To' to activate the busy program and correct the problem". It seems that PCDMIS doesn't like to wait more than a few seconds for the other program (Word) to return a result. I have tried multiple methods to suppress this error but it comes up no matter what I try.

It seems that I need to use the File I/O Command File Dialog but I can't figure out how to direct the "Open" location?

Thanks for looking!
  •             ASSIGN/ST_TM=SYSTEMTIME("HH-mm-ss")
                ASSIGN/SYS_DT=SYSTEMDATE("MM-dd-yyy'")
                ASSIGN/MTI1="S:\XXX_CMM_Programs\CUSTOMER\PART NAME\06-REPORTS\\" [COLOR=#FF0000]<--PATH[/COLOR]
                ASSIGN/MTI2="NAME IT HOWEVER YOU WISH"  [COLOR=#FF0000] <-- FILE NAME[/COLOR]
                ASSIGN/MTI3=CONCAT(MTI2," CAVITY-",C1.INPUT," ",ST_TM," ",SYS_DT)
                ASSIGN/MTI4=CONCAT(MTI1,MTI3)
                PRINT/REPORT,EXEC MODE=END,$
                  TO_FILE=ON,[COLOR=#FF0000]APPEND[/COLOR]=MTI4,AUTO OPEN REPORT=OFF,$
                  TO_PRINTER=OFF,COPIES=1,$
                  TO_DMIS_REPORT=OFF,FILE_OPTION=INDEX,FILENAME=,$
                  REPORT_THEORETICALS=ALL,REPORT_FEATURE_WITH_DIMENSIONS=YES,$
                  TO_EXCEL_OUTPUT=OFF,
                  PREVIOUS_RUNS=DELETE_INSTANCES
    


    No operator input is required. This does all of that for you.

    Mike
  • ...or create a file dialog that "feeds" the print command above with a filepath...
  • Thank you for the response!

    I cannot hard code the file name since it will always be different. Think of two parts of an assembly that are inspected at different times by different users. The second user will then need to select the report that was created by the first user to append the inspection results. This allows two related parts to be viewed in a single report.

    Creating a file dialog that "feeds" the print command is exactly what I am doing but the problem is the default "Open" path of the file dialog. Each inspection routine will have reports saved to different locations on the network depending on the part. So with the default behavior each new user will have the file dialog open to the location that was accessed by the previous user. They will then need to navigate the network to the location that their files are located. I would like the file dialog to automatically open to the desired location to save the user the time and effort of browsing the network. I can use it as is but it will create more work and confusion for the end user which is what I would like to avoid.

    Here is the VBScript that I am using which works except for the error I mentioned above...

    Sub Main

    Dim App As Object
    Set App = CreateObject ("PCDLRN.Application")

    'this is where I attempted to supress the server error - it didn't work
    'prevent OLE timeout Error
    Application.OLERequestPendingTimeout = 0
    Application.OLEServerBusyTimeout = 0


    Dim Part As Object
    Set Part = App.ActivePartProgram

    Dim Ew As Object
    Set Ew = Part.EditWindow

    Dim objfl As Variant
    Dim SavPath As Variant

    Dim WAPP As Object
    Set WAPP = CreateObject("WORD.APPLICATION")

    Dim fd As FileDialog
    Set fd = WAPP.FileDialog(3)

    'this opens the Microsoft Word file picker dialog
    With fd
    .ButtonName = "OK"
    .Filters.Add "Reports", "*.pdf", 1
    .Filters.Add "All Files", "*.*", 2
    .AllowMultiSelect = False
    .InitialView = 2
    .Title = "Select report to append"
    .InitialFileName = "\\network\path\to\file"
    End With


    'this saves the path/filename of the user selected file to a variable called SavPath
    If fd.Show = -1 Then
    For Each objfl In fd.SelectedItems
    MsgBox objfl
    SavPath = fd.SelectedItems(1)
    Next
    Else
    'user clicked cancel
    End If


    'this writes directly to the printing/report save path. I tried using an assignment variable but it didn't work.
    'it seems like PCDMIS doesn't like to use a variable with the "Append" option turned on.

    Ew.SetPrintOptionsEx 2, 0, 1, 1, SavPath, 1, False
    ' 2 = PCD_FILE
    ' 0 = DMIS_OFF
    ' 1 = PCD_APPEND
    ' 1 = ExtNum
    ' 1 = PCD_PDF
    ' bHyperReportsInline = False


    'clean up
    Wapp.quit
    Set App = Nothing
    Set Part = Nothing
    Set Ew = Nothing
    Set Wapp = Nothing

    End Sub
  • Pseudocode:
    Use a variable in PC-DMIS that will hold your path/filename selected from the opendialog.
    Populate that variable from within your VBScript.
    Use the variable in the filepath portion of the print command in your program.
    Profit.
  • It seems that I need to use the File I/O Command File Dialog but I can't figure out how to direct the "Open" location?


    I don't think you can change that from PC-DMIS. I believe Windows is keeping track of 'last used folder in FileOpenDialog' by itself, and doesn't store it in [the ordinary] Registry.

    I got SHBrowseForFolder to work in PC-DMIS Basic, but that doesn't give you a way to point to a file, only to folders :-(

    Option Explicit
    
    Private Const BIF_RETURNONLYFSDIRS As Long = &H1
    
    Function BrowseFolder(Optional Caption As String, Optional InitialFolder As String) As String
      Dim SH As Object
      Dim F As Object
      Set SH = CreateObject("Shell.Application")
      Set F = SH.BrowseForFolder(0&, Caption, BIF_RETURNONLYFSDIRS,  InitialFolder)
      If Not F Is Nothing Then
        BrowseFolder = F.Items.Item.Path
      End If
    End Function
    
    Sub main()
      MsgBox BrowseFolder ("Caption", "C:\TEMP")
    End Sub
    
  • Nice , but is that the only option for the ulFlags? (BIF_RETURNONLYFSDIRS)