hexagon logo

Import static data from textfile (fast hack)

Proof of concept.

Contents of data.txt:
Article: 988893
Description: pistons
Nr. Lot: 838384


How pc-dimis can import only the data "988893" , "pistons" and "838384
" from this file??


Code for reading:
FPTR       =FILE/OPEN,C:\Documents and Settings\CS-FC-SDE-S-PCID254\Desktop\data.txt,READ
            ASSIGN/ROW1=""
            ASSIGN/ROW2=""
            ASSIGN/ROW3=""
V1         =FILE/READLINE,FPTR,{ROW1}
V1         =FILE/READLINE,FPTR,{ROW2}
V1         =FILE/READLINE,FPTR,{ROW3}
            FILE/CLOSE,FPTR,KEEP
            ASSIGN/ROW1=ROW1-"Article: "
            ASSIGN/ROW2=ROW2-"Description: "
            ASSIGN/ROW3=ROW3-"Nr. Lot: "


Note that the contents of the three rows must match the static string that we are deleting from the line we read, otherwise it will not work. If you change the "Article: " to anything else, you must also change the "ROW1-"Article: " to match your change. This applies of course to the ROW2 and ROW3 contents as well.

An easy hack with no string verification or any of the fancy stuff. It builds on the fact that the source file "data.txt" only contains three rows with data that is interesting for us and these are the three first rows in the source file.
Parents
  • You can also use this "ignore" technique to easily read in data separated by some delimiter. In this case the file is comma delimited:
    FPTR       =FILE/OPEN,ROOT + PN + "\\PROGRAMS\\" + OP + "\\" + PN + "_" + OP + "_" + "DATUM_C" + ".TXT",READ
    DTM_C      =FILE/READLINE,FPTR,{DTMCX} + "," + {DTMCY} + "," + {DTMCZ} + "," + {DTMCI} + "," + {DTMCJ} + "," + {DTMCK} 
                FILE/CLOSE,FPTR,KEEP
    $$ NO,
                DTMCX
                DTMCY
                DTMCZ
                DTMCI
                DTMCJ
                DTMCK
    DTM_C3     =GENERIC/PLANE,DEPENDENT,CARTESIAN,$
                NOM/XYZ,<69.046,1.908,234.581>,$
                MEAS/XYZ,<DTMCX,DTMCY,DTMCZ>,$
                NOM/IJK,<-1,0,0>,$
                MEAS/IJK,<DTMCI,DTMCJ,DTMCK>
    DIM ROOT_LNGTH= 2D DISTANCE FROM PLANE LE_BF_PLN TO PLANE DTM_C3 PAR TO   XAXIS,NO_RADIUS  UNITS=MM,$
    GRAPH=OFF  TEXT=OFF  MULT=50.00  OUTPUT=BOTH
    AX    NOMINAL       MEAS        DEV
    M      237.900    237.900      0.000
Reply
  • You can also use this "ignore" technique to easily read in data separated by some delimiter. In this case the file is comma delimited:
    FPTR       =FILE/OPEN,ROOT + PN + "\\PROGRAMS\\" + OP + "\\" + PN + "_" + OP + "_" + "DATUM_C" + ".TXT",READ
    DTM_C      =FILE/READLINE,FPTR,{DTMCX} + "," + {DTMCY} + "," + {DTMCZ} + "," + {DTMCI} + "," + {DTMCJ} + "," + {DTMCK} 
                FILE/CLOSE,FPTR,KEEP
    $$ NO,
                DTMCX
                DTMCY
                DTMCZ
                DTMCI
                DTMCJ
                DTMCK
    DTM_C3     =GENERIC/PLANE,DEPENDENT,CARTESIAN,$
                NOM/XYZ,<69.046,1.908,234.581>,$
                MEAS/XYZ,<DTMCX,DTMCY,DTMCZ>,$
                NOM/IJK,<-1,0,0>,$
                MEAS/IJK,<DTMCI,DTMCJ,DTMCK>
    DIM ROOT_LNGTH= 2D DISTANCE FROM PLANE LE_BF_PLN TO PLANE DTM_C3 PAR TO   XAXIS,NO_RADIUS  UNITS=MM,$
    GRAPH=OFF  TEXT=OFF  MULT=50.00  OUTPUT=BOTH
    AX    NOMINAL       MEAS        DEV
    M      237.900    237.900      0.000
Children
No Data