hexagon logo

How can I save past runs as individual files

Hello,

I am relatively new to CMM programing. I was wondering if there was any way to set up a system where when a measurement routine ends, the program automatically saves the routine with the measurement points for that specific serial number to a set file directory. It's been a hassle for when I forget to print out a report at the end of a routine, go to run the next part and I lose my information for the previous one forever. I would like to have it set up as to where, when a measurement routine ends, the program asks me what i could like to name the file, and where to save it. Would someone with more knowledge of the program be able to assist me with some code that I can put in my programs so that this can be done, please?

Thanks
  • Hello,

    I am relatively new to CMM programing. I was wondering if there was any way to set up a system where when a measurement routine ends, the program automatically saves the routine with the measurement points for that specific serial number to a set file directory. It's been a hassle for when I forget to print out a report at the end of a routine, go to run the next part and I lose my information for the previous one forever. I would like to have it set up as to where, when a measurement routine ends, the program asks me what i could like to name the file, and where to save it. Would someone with more knowledge of the program be able to assist me with some code that I can put in my programs so that this can be done, please?

    Thanks


    When you say "saves the routine with the measurement points"....do you mean that you want PCD to save the XYZIJK data for your features to a folder? Or....do you mean that you want PCD to save a copy of the inspection report to a folder? (both of which are do-able)


  • When you say "saves the routine with the measurement points"....do you mean that you want PCD to save the XYZIJK data for your features to a folder? Or....do you mean that you want PCD to save a copy of the inspection report to a folder? (both of which are do-able)


    Both if possible lol
  • OR, save the PRG itself (without the CAD) with the serial number so you can go back and add things for features already measured (which is also doable)
  • This is how I save my PDFs.

    Operator runs program. Operator gets two pop-up comments where they have to type in a "serial number" and a "run number".

    Once program is done, it "prints" the inspection rpt as a PDF to a folder I set up. The PDF itself will get named by the operator's inputs & by the exact date & time it gets created so it will always be uniquely named. I have it set up so you don't even have to open it to see if it's rejected or not.

    This is at the top of my program
    SERIALNUMBERQUESTION =COMMENT/INPUT,NO,FULL SCREEN=NO,
    Serial Number:
    ASSIGN/VAR_SERIAL_NUMBER=UPPERCASE(SERIALNUMBERQUESTION.INPUT)
    ASSIGN/VAR_SERIALNUMBER_STATEMENT="Serial Number: "+VAR_SERIAL_NUMBER
    COMMENT/REPT,
    
    COMMENT/REPT,
    VAR_SERIALNUMBER_STATEMENT
    RUNNUMBERQUESTION =COMMENT/INPUT,NO,FULL SCREEN=NO,
    Run Number:
    IF_GOTO/RUNNUMBERQUESTION.INPUT<1 OR RUNNUMBERQUESTION.INPUT>9999,GOTO = RUNNUMBERQUESTION
    IF_GOTO/LEN(RUNNUMBERQUESTION.INPUT)>4,GOTO = RUNNUMBERQUESTION
    ASSIGN/VAR_RUNNUMBER=FORMAT("%04d",INT(RUNNUMBERQUESTION. INPUT))
    ASSIGN/VAR_RUNNUMBER_STATEMENT="Run Number: "+VAR_RUNNUMBER
    COMMENT/REPT,
    VAR_RUNNUMBER_STATEMENT
    


    code goes here
    code goes here
    code goes here
    code goes here
    code goes here
    code goes here
    code goes here
    code goes here
    code goes here
    code goes here


    This is at the bottom of my program
    ASSIGN/NUMOOT=GETPROGRAMINFO("NUMOOT")
    ASSIGN/PROG_NAME=GETPROGRAMINFO ("PARTNAME")
    ASSIGN/DATE=STR(SYSTEMDATE ("dMMMyyyy"))
    ASSIGN/TIME=STR(SYSTEMTIME ("HHmmss"))
    ASSIGN/REJECT="____REJECT____"
    IF/NUMOOT=="0"
    ASSIGN/REPORT_NAME="O:\\CMM PROGRAMS\\CMM_PDF_PC DMIS\\AG0OFFLINETEST\\"+PROG_NAME+"__"+VAR_SERIAL_ NUMBER+"__"+VAR_RUNNUMBER+"__"+DATE+"__"+TIME+"__. PDF"
    END_IF/
    ELSE/
    ASSIGN/REPORT_NAME="O:\\CMM PROGRAMS\\CMM_PDF_PC DMIS\\AG0OFFLINETEST\\"+PROG_NAME+"__"+VAR_SERIAL_ NUMBER+"__"+VAR_RUNNUMBER+"__"+DATE+"__"+TIME+"__" +REJECT+".PDF"
    END_ELSE/
    PRINT/REPORT,EXEC MODE=END,$
    TO_FILE=ON,AUTO=1,AUTO OPEN=OFF,$
    TO_PRINTER=OFF,COPIES=1,$
    TO_DMIS_REPORT=OFF,FILE_OPTION=OVERWRITE,FILENAME= REPORT_NAME,$
    REPORT_THEORETICALS=NONE,REPORT_FEATURE_WITH_DIMEN SIONS=NO,$
    TO_EXCEL=OFF,$
    PREVIOUS_RUNS=KEEP_INSTANCES
    


    Other people will chime in for the other parts of the answer you requested.
  • OR, save the PRG itself (without the CAD) with the serial number so you can go back and add things for features already measured (which is also doable)


    This is what I was getting at originally, because sometimes I add sequences to our company reports that weren't there originally and I need to re run the part again, wasting a bunch of time.
  • This is how I save my PDFs.

    Operator runs program. Operator gets two pop-up comments where they have to type in a "serial number" and a "run number".

    Once program is done, it "prints" the inspection rpt as a PDF to a folder I set up. The PDF itself will get named by the operator's inputs & by the exact date & time it gets created so it will always be uniquely named. I have it set up so you don't even have to open it to see if it's rejected or not.

    This is at the top of my program
    SERIALNUMBERQUESTION =COMMENT/INPUT,NO,FULL SCREEN=NO,
    Serial Number:
    ASSIGN/VAR_SERIAL_NUMBER=UPPERCASE(SERIALNUMBERQUESTION.INPUT)
    ASSIGN/VAR_SERIALNUMBER_STATEMENT="Serial Number: "+VAR_SERIAL_NUMBER
    COMMENT/REPT,
    
    COMMENT/REPT,
    VAR_SERIALNUMBER_STATEMENT
    RUNNUMBERQUESTION =COMMENT/INPUT,NO,FULL SCREEN=NO,
    Run Number:
    IF_GOTO/RUNNUMBERQUESTION.INPUT<1 OR RUNNUMBERQUESTION.INPUT>9999,GOTO = RUNNUMBERQUESTION
    IF_GOTO/LEN(RUNNUMBERQUESTION.INPUT)>4,GOTO = RUNNUMBERQUESTION
    ASSIGN/VAR_RUNNUMBER=FORMAT("%04d",INT(RUNNUMBERQUESTION. INPUT))
    ASSIGN/VAR_RUNNUMBER_STATEMENT="Run Number: "+VAR_RUNNUMBER
    COMMENT/REPT,
    VAR_RUNNUMBER_STATEMENT
    


    code goes here
    code goes here
    code goes here
    code goes here
    code goes here
    code goes here
    code goes here
    code goes here
    code goes here
    code goes here


    This is at the bottom of my program
    ASSIGN/NUMOOT=GETPROGRAMINFO("NUMOOT")
    ASSIGN/PROG_NAME=GETPROGRAMINFO ("PARTNAME")
    ASSIGN/DATE=STR(SYSTEMDATE ("dMMMyyyy"))
    ASSIGN/TIME=STR(SYSTEMTIME ("HHmmss"))
    ASSIGN/REJECT="____REJECT____"
    IF/NUMOOT=="0"
    ASSIGN/REPORT_NAME="O:\\CMM PROGRAMS\\CMM_PDF_PC DMIS\\AG0OFFLINETEST\\"+PROG_NAME+"__"+VAR_SERIAL_ NUMBER+"__"+VAR_RUNNUMBER+"__"+DATE+"__"+TIME+"__. PDF"
    END_IF/
    ELSE/
    ASSIGN/REPORT_NAME="O:\\CMM PROGRAMS\\CMM_PDF_PC DMIS\\AG0OFFLINETEST\\"+PROG_NAME+"__"+VAR_SERIAL_ NUMBER+"__"+VAR_RUNNUMBER+"__"+DATE+"__"+TIME+"__" +REJECT+".PDF"
    END_ELSE/
    PRINT/REPORT,EXEC MODE=END,$
    TO_FILE=ON,AUTO=1,AUTO OPEN=OFF,$
    TO_PRINTER=OFF,COPIES=1,$
    TO_DMIS_REPORT=OFF,FILE_OPTION=OVERWRITE,FILENAME= REPORT_NAME,$
    REPORT_THEORETICALS=NONE,REPORT_FEATURE_WITH_DIMEN SIONS=NO,$
    TO_EXCEL=OFF,$
    PREVIOUS_RUNS=KEEP_INSTANCES
    


    Other people will chime in for the other parts of the answer you requested.


    thank you! I will give it a shot


  • thank you! I will give it a shot


    you can slim this down and take a lot of stuff out of this but i like how it runs at our facilities
  • If you want to save a copy of the program itself you can use a basic script to save the current measuring routine, then save a copy of the measuring routine in some sort of archive folder.

    shared a nice script for that a while back. Here is a link to that post: https://www.pcdmisforum.com/forum/pc-dmis-enterprise-metrology-software/pc-dmis-code-samples/390021-auto-archive-freebie

    I created some of my own scripts based on what he shared to save copies of the measuring routine each time we measure a part where I work. This one below can be called at the end of a measuring routine and it will automatically look in the program for operator inputs such as Operator Initials or Serial Number. It will then prompt the operator if they want to save the measuring routine and save a copy of the measuring routine in a separate folder in the same directory as the measuring routine is being executed from. If the operator clicks OK, It will make a folder with the same name as the measuring routine file name with an '(Archive)' suffix. A copy of the .prg and .cad file will be put in that folder with suffixes added to the file names. The suffixes will be the operator inputs separated by dashes "-" and the date/time the file was created. Those files are then made to be 'read-only' so the data is not lost if someone executes one of the archived programs.

    ' Save_Copy_And_Write_Protect
    '
    ' By Cris_C 9-12-2019
    '
    ' Credit to NinjaBadger for the original program from which this was created.
    ' Post Link: https://www.pcdmisforum.com/forum/pc-dmis-enterprise-metrology-software/pc-dmis-code-samples/390021-auto-archive-freebie
    '
    ' This Basic Script it to be called at the end of a measuring routine.
    ' It Saves the current measuring routine and then copies the .prg and the .cad file
    ' to a folder in the same directory as the measuring routine. The folder has the same
    ' name as the measuring routine .prg name with an "(Archive)" suffix.
    ' The copies are given a suffix made from operator inputs in the program (such as Serial number) and
    ' The date/time the copy was made.
    ' The copy of the .prg file and .cad file are then made Read-Only so data is not lost if someone tries
    ' to re-execute an archived program.
    
    Sub main()
    
    'Create objects------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    '--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    Dim pcapp As Object
    Set pcapp = createobject("pcdlrn.application")
    Dim pcpart As Object
    Set pcpart = pcapp.activepartprogram
    Dim Cmd As Object
    Dim Cmds As Object
    Dim ComCmd As Object
    Set Cmds = pcpart.Commands
    
    'Figure out where To copy To/from-----------------------------------------------------------------------------------------------------------------------------------------------------------
    '--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    'Get the current prg And cad file path
    Dim prg_source_path
    Dim cad_source_path
    prg_source_path = pcpart.fullname
    cad_source_path = left(prg_source_path,len(prg_source_path)-4) & ".cad"
    
    'Get program Name (without file extension)
    Dim progname
    progname = left(pcpart.Name,len(pcpart.Name)-4)
    
    'Define the Archive Path
    Dim archivepath
    archivepath = left(pcpart.FullName,len(pcpart.FullName)-len(pcpart.Name)) & progname & "(Archive)"
    
    'Get Additional Information from the CMM Program User inputs. --------------------------------------------------------------------------------------------------------------------
    '---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    'Go Through Each of the Commands In the program And Find all the comments. If a comment is an Input comment Then Get the Object And retrieve the user Input.
    'take the user Input And concatinate it into one variable. Essentially making a chain of all the user inputs In the order they appear In the program.
    Dim userinputs
    For Each Cmd In Cmds
    If Cmd.IsComment Then
    Set ComCmd = Cmd.CommentCommand
    If ComCmd.CommentType = 2 Then
    userinputs = userinputs & ComCmd.Input & "-"
    End If
    End If
    Next Cmd
    
    'Replace Any characters that will mess up windows If you use them In a file Name. Also some that would be fine but I just don't like To see In a file Name.
    Dim revisedinputs
    For count=1 To Len(userinputs)
    If mid(userinputs,count,1) = "/" Or mid(userinputs,count,1) = "\" Or mid(userinputs,count,1) = "<" Or mid(userinputs,count,1) = ">" Or mid(userinputs,count,1) = ":" Or mid(userinputs,count,1) = "." Or _
    mid(userinputs,count,1) = ";" Or mid(userinputs,count,1) = "?" Or mid(userinputs,count,1) = "*" Or mid(userinputs,count,1) = "|" Or mid(userinputs,count,1) = "," Or mid(userinputs,count,1) = """" Then
    newchar = "#"
    Else
    newchar = mid(userinputs,count,1)
    End If
    revisedinputs = revisedinputs & newchar
    Next
    
    'Make sure the inputs are Not too Long For a file Name, Limit it To an arbitrary 30 characters. It leaves lots of space For Long CMM Program names And date And time.
    revisedinputs = left(revisedinputs,30)
    
    'Complete the saving Name/path And Get ready To propt the user -----------------------------------------------------------------------------------------------------------------
    '--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    'Genrate the destination (save) paths
    prg_dest_path = archivepath & "\" & progname & "(" & revisedinputs & ")_" & format(now(),"YYMMDDHHNNSS") & ".prg"
    cad_dest_path = archivepath & "\" & progname & "(" & revisedinputs & ")_" & format(now(),"YYMMDDHHNNSS") & ".cad"
    
    'Create the Long String of text that will be used In the OK/Cancel Message box
    Dim Msg
    Msg = "The CMM measuring is complete." & chr(13)
    Msg = Msg & chr(13)
    Msg = Msg & "Would you like to save the current CMM program and also create a backup with the following name and location?" & chr(13)
    Msg = Msg & chr(13)
    Msg = Msg & prg_dest_path & chr(13)
    Msg = Msg & chr(13)
    Msg = Msg & "Click OK to save CMM program and make a backup." & chr(13)
    Msg = Msg & "Click CANCEL to skip the saving/backup operation." & chr(13)
    
    'Create title For mesasge box
    MsgTitle = "CMM Program Backup Utility"
    
    
    'Create File System Object For file operations
    'Note: This Object is Not documented In the PC-DMIS help file. More details On it can be found On the Microsoft wesite. Try this link:
    'https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/filesystemobject-object
    Dim fso As Object
    Dim fo As Object
    Set fso = createobject("scripting.filesystemobject")
    
    'Display the OK/Cancel Message box And save/copy If user clicks OK. If the user clicks OK it will return a 1. -----------------------------------------------------------
    '----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    If MsgBox(Msg,1,MsgTitle) = 1 Then
    'Save existing program
    pcpart.save
    'Check If the destination folder exists, If Not Then create one
    If Not fso.folderexists(archivepath) Then
    Set ofolder = fso.createfolder(archivepath)
    End If
    'Copy the program And the cad file
    fso.copyfile prg_source_path, prg_dest_path
    fso.copyfile cad_source_path, cad_dest_path
    'Create a file Object pointing To the coppied program And cad file. Then make the program Read-Only.
    Set fo = fso.GetFile(prg_dest_path)
    fo.Attributes = 1
    Set fo = fso.GetFile(cad_dest_path)
    fo.Attributes = 1
    End If
    
    'Tidy up -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    '----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    Set fso = Nothing
    Set pcpart = Nothing
    Set pcapp = Nothing
    Set Cmd = Nothing
    Set Cmds = Nothing
    Set ComCmd = Nothing
    
    End Sub
    
    
  • Would this allow for additional measurements to be added to the read only file? such as adding a distance between two already measured features? Or is it locked as is?
  • All it does is apply the read-only setting in windows on the archived copies of the program. So, if an archived measuring routine needs to be revised by adding a report feature or such, you can right click on the program in windows, select properties, then uncheck the 'Read-only' check box. Then, if you open it you can save any changes that you make.

    Though, what I typically do is open the program while it is still marked as read-only, make my edits and do a 'save as' to create a new copy and add a word or two to the end of the new file name to explain what was revised. That way there is a bit more traceability and an unmodified copy in case I screw something up. I work with a lot of big complicated prototype parts so there can sometimes be a lot of revisions made to the reports as they are reviewed by everyone involved. Normally the changes are just simple formatting or adding extra snapshots for profiles and such.