hexagon logo

Basic script error in PC-DMIS

Any help would be appreciated here. I keep getting an error message that pops up when trying to run a basic script. I've used this same script for months now, and never had any issues. now all of the sudden on 1 machine, I am getting this error. I see nothing wrong with the code in the script, and it hasn't been changed at all. I'm thinking that this might be an error on PC-DMIS side of things, and not actually an error with the script.... only problem is idk what to do to fix it...

here is the script, if any one could double check this. original script was pulled from a post here, I think by

'Script for saving PC-DMIS reports by serial number in Work Order folder
'Will create folder for work order if none is present

'SETTINGS FOR USE
'Program should have 2 comments and ASSIGN variables created for the inputs of those comments as shown below
'C1         =COMMENT/INPUT,YES,FULL SCREEN=NO,
'            WORK ORDER
'C2         =COMMENT/INPUT,YES,FULL SCREEN=NO,
'            SERIAL NUMBER
'            ASSIGN/WO=C1.INPUT
'            ASSIGN/SN=C2.INPUT

'At the end of program create another ASSIGN variable labeled REPORT_PATH and its value should be the file location you want reports in, minus the work order folder
'and with the "+WO+" variable at the end
'Example of assignment - ASSIGN/REPORT_PATH="F:\QUALITY\CMM\CMM inspection reports\BOEING\314A6128-21\\"+WO+"

'After this line enable the script to run in the program, and mark script code lines

'Now ASSIGN variable labled VAR_FILENAME and its value should have the same path as above but with the addition of SN variable and .PDF to enable the report to save
'Example of this assignment - ASSIGN/VAR_FILENAME="F:\QUALITY\CMM\CMM inspection reports\BOEING\314A6128-21\\"+WO+"\\"+SN+".PDF"

'After this, in the edit window, hit ENTER then type "PRINT" then hit TAB, and place cursor in the new code and hit F9, click the report output checkbox
'And in the text box below type VAR_FILENAME
'Then click the "Overwrite" option, "PDF" option, and select any other options you see fit

'Auto archive of reports is now set up and ready to run

'Notes for use written by ANDY SMITH, script pulled from PC-DMIS Forum, and edited for use by ANDY SMITH, original script by DaVe_M

Sub Main()

Dim objFSO, objShell
Dim PCDApp, PCDPartProgram, PCDCommands, PCDCommand, retval
Dim objFile, objFolder As Object

Set PCDApp=CreateObject("PCDLRN.Application")
Set PCDPartProgram=PCDApp.ActivePartProgram
Set PCDCommands=PCDPartProgram.Commands

Set Pathname=PCDPartProgram.GetVariableValue("REPORT_PATH")

strPath=Pathname.StringValue

Set objFSO = CreateObject("Scripting.FileSystemObject")

If objFSO.FolderExists(strPath) Then
  'Nothing
Else
  Set objFile=objFSO.CreateFolder(strPath)
End If

End Sub​

Attached Files
  • Does this happen with all programs on that one machine? Or just certain programs? Have you ran this in the vbs editor inside pc dmis so you can see what line the failure is on for troubleshooting?
    Your error says line 49 error, which is the line that creates the folder. If all other lines succeeded, my guess would be a special character was used in the operator input and the script cannot create the folder because windows does not allow special characters in files names. If using operator inputs for creating directories, I highly recommend using some code to check for special characters and looping back to the operator input if found.
    Just a guess.
  • Seems to be only on 1 machine. you might be right about the special characters, I was able to run the script when I personally run the program. although, it was through a different program. So far its working again for tonight, but I will check again later with that specific program.

    I'm still a bit new to VBS, so I'm not completely sure how to get it to check for special characters. but i'll look into it.
  • Debug your script when the error happens, look at the strPath value to see what it is. You can display it in a messagebox for clarity.
    I would add it to the script so it displays every time you run it, that way - if the error is intermittent - you'll always display the variable value making it easier for you to debug.
  • good day,

    for this short script, the error can actually only be at this point
    Set Pathname=PCDPartProgram.GetVariableValue("REPORT_P ATH")


    please check:
    * Variable "REPORT_PATH" exists in pcDMIS
    * Variable "REPORT_PATH" spelled correctly in pcDMIs
    * variable-content is actually a path in pcDMIs
    * the path can be actually created (Windows permissions)

    i think:
    * "objFSO.CreateFolder(strPath)" can only create the last folder, if several folders are to be created then there is an error message here.​



    strange: double backslash shouldn't actually work ^^
    please double check that the specified path is correct.
    Create the folders by hand and look at the path in windows and compare it with the script path
  • I found out pretty quickly that if I allow anyone to enter an input, and that input is used to create files for windows, that it will eventually break because someone wants to write "N/A" into a field.
    You can search for special characters inside of pc dmis by using if/ and goto commands.

    Redo =Label
    If/index(c1.input,"//")==0 or index(c1.input,"?")==0 or index(c1.input,"*")==0 etc
    Comment/oper
    Please retype without using special characters.
    Goto/Redo/
    End_if/

    I have since switched to a custom form inside of pc dmis while using VB scripts to ensure special characters aren't used. Reduces the code inside of pc dmis and won't even allow you to enter the character.
  • Good idea, thanks for the help. I think I will add that into our programs that use the script.
  • Thanks for the input. Yeah, I have checked all my variables for consistency and spelling, and everything looked right. for some reason it seems to be only happening on one specific program, and sometimes it will work and sometimes it doesn't. So far, so good today though.

    And upon research when I first came up with this method, per the PC-DMIS help files, the double backslash is needed to end the folder location, and then to be able to use the "WO" variable.
  • could you elaborate on this? I'm still a bit new to VBS, and haven't ever created message box in VBS.

    Appreciate it!