hexagon logo

How-To: Output selected data to a CSV file

This stuff may be easy for you pros, but this is for the beginners like me.

I figured all this out using the well-written Help file code examples in PCDMIS 4.3MR1.

It's useful for exporting your data, especially if you only need to output some of your data to Excel in a certain format.


Step 1: At the beginning of the program, the operator is prompted to enter the serial # of the part being run, and this input is assigned to variable V1.

C1         =COMMENT/INPUT,YES,'Serial Number:'
            ASSIGN/V1=C1.INPUT



(Not shown: the program checks two holes and dimensions their Positions)

Step 2: A pair of Position Dimension results are assigned to variables VOD and VID

ASSIGN/VOD=OD_HOLE_POSITION.TP.DEV
            ASSIGN/VID=ID_HOLE_POSITION.TP.DEV



Step 3: Then the variables V1, VOD, and VID are concatenated into a string and assigned to a new variable VRALL. The plus signs, spaces, and quotes are very necessary to make sure the values of the variables and the commas are correctly done.
ASSIGN/VRALL=V1+","+VOD+","+VID





Step 4: we run a quick check to see if the target file we want to dump data into exists.
If the file is there PCDMIS will give the variable VEXIST1 the value of 1, if it's missing then it gets zero.

VEXIST1    =FILE/EXISTS,C:\datafolder\\datadumpfile.CSV



Step 5: If this file is not there, well then we can make a new one! We can even set it up with headers.
The IF function will only cause the lines of code between IF and END_IF to be exectuted if the IF statement is true. Therefore, if the file already exists and VEXIST now equals 1 not 0, and this step will be skipped.
The FPTR is a file-pointer function called up by FILE that handles the file opening, reading, writing, and closing commands.
In this example, the FILE command calls a filepointer named FTPR, then uses it with OPEN to create a new file, then WRITELINE four times to add the header information, then CLOSE with KEEP which saves it.

IF/VEXIST1==0
FPTR       =FILE/OPEN,C:\datafolder\\datadumpfile.CSV,WRITE
            FILE/WRITELINE,FPTR,#,OD_HOLE,ID_HOLE
            FILE/WRITELINE,FPTR,Nominal,0,0
            FILE/WRITELINE,FPTR,U.Toler,0.003,0.003
            FILE/WRITELINE,FPTR,L.Toler,0,0
            FILE/CLOSE,FPTR,KEEP
            END_IF/



Step 6: OK, now the actual writing of the data to the file.
Notice that the file-pointer's OPEN command has the choice APPEND selected and not OVERWRITE, and that the next command is WRITELINE.
This is so that during each subsequent part run the value of the variable VRALL (Step 3) gets added to the file as a new single line.

FPTR       =FILE/OPEN,C:\datafolder\\datadumpfile.CSV,APPEND
            FILE/WRITELINE,FPTR,VRALL
            FILE/CLOSE,FPTR,KEEP




Step 6: If you open the resulting datadump.csv file in Notepad you'll see the commas.
The first 4 lines are the header info and were written when the file was created back in Step 5.
The next lines are the actual data from running the program through twice, on parts with serial numbers 777 and 778.

#,OD_HOLE,ID_HOLE
Nominal,0,0
U.Toler,0.003,0.003
L.Toler,0,0
777,0.0022,0.0022
778,0.0019,0.0025

But if you open it up in Excel the commas will be translated as cell dividers and each value will be in it's own cell.

Attached Files
Parents
  • C1 =COMMENT/INPUT,NO,FULL SCREEN=NO,
    Sample Number



    ASSIGN/PTNUM=C1.INPUT
    ASSIGN/PTN=STR(PTNUM)+1
    RUN =LABEL/
    DCC program routine code ( this area is whatever program routine one has created)
    Right after last line of routine code


    $$ NO,
    *****************************************
    ASSIGN/FIL_CSV="C:\Users\Public\Documents\WAI\PC-DMIS\2015.1\CSV_FILES\\125ml_CAP_Substrate.csv" Place where you have pcdmis on drive via installation... use of undescore helps
    ASSIGN/SYSDAT=SYSTEMDATE("MM dd yy")
    ASSIGN/SYSTIM=SYSTEMTIME("HH:mm:ss")
    ASSIGN/V10=SYSDAT+","+SYSTIM
    ASSIGN/V11=DIST1.MEAS
    ASSIGN/V12=LOC1.D.MEAS
    ASSIGN/V13=LOC4.D.MEAS
    ASSIGN/V14=FCFPARL1.MEAS
    ASSIGN/V15= PTN
    ASSIGN/V16=V15+","+V14+","+V13+","+V12+","+V11+","+V10
    FPTR =FILE/OPEN,FIL_CSV,APPEND
    FILE/WRITELINE,FPTR,V16
    FILE/CLOSE,FPTR,KEEP

    Assign/V... whatever dimension you desire via assn drop down table/window. Report(s) that need to have single result columns will require each dimension must be singularly assigned!!!!

    *Open in excel to see results ;but keep as CSV format/style. ** will not append if this csv file is open at time of appending. Each part program will require its on CSV file!!!
Reply
  • C1 =COMMENT/INPUT,NO,FULL SCREEN=NO,
    Sample Number



    ASSIGN/PTNUM=C1.INPUT
    ASSIGN/PTN=STR(PTNUM)+1
    RUN =LABEL/
    DCC program routine code ( this area is whatever program routine one has created)
    Right after last line of routine code


    $$ NO,
    *****************************************
    ASSIGN/FIL_CSV="C:\Users\Public\Documents\WAI\PC-DMIS\2015.1\CSV_FILES\\125ml_CAP_Substrate.csv" Place where you have pcdmis on drive via installation... use of undescore helps
    ASSIGN/SYSDAT=SYSTEMDATE("MM dd yy")
    ASSIGN/SYSTIM=SYSTEMTIME("HH:mm:ss")
    ASSIGN/V10=SYSDAT+","+SYSTIM
    ASSIGN/V11=DIST1.MEAS
    ASSIGN/V12=LOC1.D.MEAS
    ASSIGN/V13=LOC4.D.MEAS
    ASSIGN/V14=FCFPARL1.MEAS
    ASSIGN/V15= PTN
    ASSIGN/V16=V15+","+V14+","+V13+","+V12+","+V11+","+V10
    FPTR =FILE/OPEN,FIL_CSV,APPEND
    FILE/WRITELINE,FPTR,V16
    FILE/CLOSE,FPTR,KEEP

    Assign/V... whatever dimension you desire via assn drop down table/window. Report(s) that need to have single result columns will require each dimension must be singularly assigned!!!!

    *Open in excel to see results ;but keep as CSV format/style. ** will not append if this csv file is open at time of appending. Each part program will require its on CSV file!!!
Children