hexagon logo

Variables in Print command for csv file naming.

I have a program where I am looping 15 parts. I am appending my csv file output using print command inside the loop so all the data for the parts on the fixture load end up in the same file. That works fine. Now I want to control the file naming with an operator input variable and Date and Time. Assign the variable values before starting the loop. When I run the program, it hits the print command and brings up a save file window every part iteration. It seems to somehow think that I am proposing a new file name each time. Thank you for any suggestions.

Parents
  • I do something like this with PDFs. However, I do not use the native CSV command within PC-DMIS. I do my own customized CSV to work with our ERP.:

    ---BEFORE THE LOOP----
    
    ASSIGN/PDFINDEX=SYSTEMDATE("yyMMdd")+"_"+SYSTEMTIME("HHmmss")
    ASSIGN/PDFFILE="M:\Quality\CMM Reports\\"+VPN+"\\Data\True Positions\\"+VPN+"_TP_"+PDFINDEX+".PDF"
    
    ---PRINT COMMANDS---
    
    IF/LOOP1=="1"
    PRINT/REPORT,EXEC MODE=END,$
    TO_FILE=ON,OVERWRITE=PDFFILE,AUTO OPEN=OFF,$
    TO_PRINTER=OFF,COPIES=1,$
    TO_DMIS_REPORT=OFF,FILE_OPTION=OVERWRITE,FILENAME=,$
    REPORT_THEORETICALS=ALL,REPORT_FEATURE_WITH_DIMENSIONS=NO,$
    TO_EXCEL=OFF,$
    PREVIOUS_RUNS=DELETE_INSTANCES
    GOTO/L2
    END_IF/
    IF/LOOP1>"1"
    PRINT/REPORT,EXEC MODE=END,$
    TO_FILE=ON,APPEND=PDFFILE,AUTO OPEN=OFF,$
    TO_PRINTER=OFF,COPIES=1,$
    TO_DMIS_REPORT=OFF,FILE_OPTION=OVERWRITE,FILENAME=,$
    REPORT_THEORETICALS=ALL,REPORT_FEATURE_WITH_DIMENSIONS=NO,$
    TO_EXCEL=OFF,$
    PREVIOUS_RUNS=DELETE_INSTANCES
    GOTO/L2
    END_IF/
    L2 =LABEL/
    IF/LOOP1==FORM4
    COMMENT/REPT,
    .
    "TOTAL RUNTIME: "+ELAPSEDEXECUTIONTIME()
    .
    PRINT/REPORT,EXEC MODE=END,$
    TO_FILE=ON,APPEND=PDFFILE,AUTO OPEN=ON,$
    TO_PRINTER=OFF,COPIES=1,$
    TO_DMIS_REPORT=OFF,FILE_OPTION=OVERWRITE,FILENAME=,$
    REPORT_THEORETICALS=ALL,REPORT_FEATURE_WITH_DIMENSIONS=NO,$
    TO_EXCEL=OFF,$
    PREVIOUS_RUNS=DELETE_INSTANCES
    END_IF/
    L3 =LABEL/

    The last print command appends the runtime to the report if the total number of loops equals the total number designated at the beginning of the program.

  • Yes but in pdf reports you are not trying to append to an existing file as far as I am aware.

  • Sure I am. The first command "overwrites" which creates the initial PDF. Then if the Loop is greater than 1, it will append. Once the loop equals the number of parts, then it appends the runtime. 

  • That's exactly where my thought was going on as well using loop  counts. Nice stuff.

  • Ok I can try that. The problem in this case is that it seems to insist that I have to save it as new file. Even though the file name should be the same. Might be able to stop this by defining file path string as a variable rather than referencing the variables in the print command inside the loop.

  • Are you wanting to append to the same file every time you start the program from the beginning? Otherwise, based on the date and time, which is before the loop, it will write a "new" file at Loop=1 and then append to that same file when ever the loop is >1. I have used this method on 50 or so programs with no issues. Now, if you want to append to the same date and time with several new runs, then there will be additional flow control that requires writing and reading the date/time from a txt or csv file. 

Reply
  • Are you wanting to append to the same file every time you start the program from the beginning? Otherwise, based on the date and time, which is before the loop, it will write a "new" file at Loop=1 and then append to that same file when ever the loop is >1. I have used this method on 50 or so programs with no issues. Now, if you want to append to the same date and time with several new runs, then there will be additional flow control that requires writing and reading the date/time from a txt or csv file. 

Children
  • Yes, set file name with D/T outside loop then append to that file with looped data next run new file. I will try your syntax and if I have the same problem, I will post you the code.

    Thank you so much for your help.

  • I have shared my code and the window that comes up when it executes the print commands. Have found no resolution to this. Tried changing some of the flags with no affect, Thanks for any thoughts.

    C1 =COMMENT/INPUT,NO,FULL SCREEN=YES,
    Enter Operator Name
    C2 =COMMENT/INPUT,NO,FULL SCREEN=YES,
    Enter Batch Number
    C3 =COMMENT/INPUT,NO,FULL SCREEN=YES,
    Enter Cavity Number
    C4 =COMMENT/INPUT,NO,FULL SCREEN=YES,
    Enter part count
    ASSIGN/V1=C1.INPUT
    ASSIGN/V2=C2.INPUT
    ASSIGN/V3=C3.INPUT
    ASSIGN/V4=C4.INPUT
    ASSIGN/CSVTIME=SYSTEMDATE("MMddyyyy")+"_"+SYSTEMTIME("hhmmss")
    ASSIGN/CSVFILE="\\MAPAPP72\Mitutoyo\Hexagon CMM\Programs\Loader Final Programs\DATA\Pusher Cap 51495899_"+V2+"_"+CSVTIME+".CSV"
    VV2 =LOOP/START,ID=YES,NUMBER=1,START=1,SKIP=,
    OFFSET:XAXIS=0,YAXIS=62,ZAXIS=0,ANGLE=0
    VV1 =LOOP/START,ID=YES,NUMBER=1,START=1,SKIP=,
    OFFSET:XAXIS=50.8,YAXIS=0,ZAXIS=0,ANGLE=0
    COMMENT/REPT,
    V1
    COMMENT/REPT,
    V2
    COMMENT/REPT,
    V3
    COMMENT/REPT,
    V4

    __________________________________________________________________________________________________________________________

    PRINT/REPORT,EXEC MODE=END,$
    TO_FILE=ON,AUTO=1849,AUTO OPEN=ON,$
    TO_PRINTER=OFF,COPIES=1,$
    TO_DMIS_REPORT=OFF,FILE_OPTION=INDEX,FILENAME=,$
    REPORT_THEORETICALS=NONE,REPORT_FEATURE_WITH_DIMENSIONS=NO,$
    TO_EXCEL=ON,APPEND,FILENAME=CSVFILE,AUTO OPEN=OFF,$
    PREVIOUS_RUNS=DELETE_INSTANCES
    WORKPLANE/XPLUS
    REPORT/LABEL, FILENAME= FILE_HEADER.LBL
    WORKPLANE/ZPLUS
    L1 =LABEL/
    ASSIGN/V4=V4+1
    MOVE/INCREMENT,<0,0,20>
    LOOP/END
    LOOP/END
    MOVE/POINT,NORMAL,<69.8505,246.2287,231.8067

  • Change AUTO to APPEND in your print command...

    Also, go to File>Printing>Report Window Print Setup and make sure there aren't any options selected.  The routine itself can have different print settings than the print command, going through the menu shows you the routine's settings, editing (F9) the print command shows you the print command's settings.

    If you've made those changes and everything looks correct but it still prompts you for a file location when printing then it is probably a permissions problem (you may not have permission to write to the location), or your file path doesn't exist (check for mistakes where you define the file path).

  • Thank you so much for the reply.

    Not having problems with pdf files not trying to append them.

    The problem is with appending the csv file with variable data defining the file name.

    If I just have fixed name it appends to that file just fine. If I put variables in the file name it stops every part and brings up save dialog.

    Any thoughts would be appreciated

  • I think it may have been changed in a recent version but you never used to be able to use a variable for the csv file name.  It always used to just put the .csv file wherever the .prg was saved.  The work-around was to let it put the file there and then add a FILE/MOVE command once your csv file was finished.

  • What version of PC-DMIS do you have? I have 2021.2, and I tested out your code on a new program I made, and it worked just fine without a save dialog. Although I am also not trying this in a loop either.

  • I don't seem to have any trouble setting path in V2020.R2 and the path doesn't change in my code just the file name.

  • Thanks, I haven't tested it without the loop. Have run it as a single loop run. V2020.R2. I will try without loop. Also might try saving it local instead of network drive.

  • This may seem a little redundant, but have you tried putting this line:

    ASSIGN/CSVFILE1="\\MAPAPP72\Mitutoyo\Hexagon CMM\Programs\Loader Final Programs\DATA\Pusher Cap 51495899_"+V2+"_"+CSVTIME+".CSV"
    ASSIGN/CSVFILE2=CSVFILE1

    To see if PC-DMIS just doesn't like reading from the variable state of V2 in the first assign statement?

    And to put that as your new FILENAME=CSVFILE2

    Just a shot in the dark. I tried it on my PC, nothing truly changed and it still ran fine.