hexagon logo

Save variables in part program

I don't know how to put the thread title to reflect post content, but this post and code deals with how to save an integer variable (in this case, a loop counter) in between program executions, without the need for saving it to an external file and read it in again.

START      =ALIGNMENT/START,RECALL:USE_PART_SETUP,LIST=YES
            ALIGNMENT/END
            MODE/MANUAL
            CHECK/3,1
            MOVESPEED/ 100
            FORMAT/TEXT,OPTIONS,ID,HEADINGS,SYMBOLS, ;MEAS,NOM,TOL,DEV,OUTTOL, , 
            LOADPROBE/E50D4L30CF
            TIP/T1A0B0, SHANKIJK=0, 0, 1, ANGLE=0

$$ YES,
            *
            Put your pre-loop alignment
            and measurements here
            *

            ASSIGN/VARCHECKED=0
            GOTO/CHECKVAR

BEGIN      =LABEL/
            IF/VARCHECKED==1

COUNTER    =LOOP/START,ID=YES,NUMBER=999,START=COUNTER,SKIP=,
              OFFSET:XAXIS=0,YAXIS=0,ZAXIS=0,ANGLE=0

F1         =GENERIC/POINT,DEPENDENT,CARTESIAN,$
            NOM/XYZ,<COUNTER,0,0>,$
            MEAS/XYZ,<COUNTER,0,0>,$
            NOM/IJK,<0,0,1>,$
            MEAS/IJK,<0,0,1>

$$ YES,
            *
            Put your in-loop measurements
            and evaluations here
            *

            LOOP/END
            END_IF/
            GOTO/ENDPROGRAM

CHECKVAR   =LABEL/
DIM HOLDER= LOCATION OF POINT F1  UNITS=MM ,$
GRAPH=OFF  TEXT=OFF  MULT=10.00  OUTPUT=NONE  HALF ANGLE=NO
AX       MEAS    NOMINAL       +TOL       -TOL        DEV     OUTTOL
X       20.000     20.000      0.000      0.000      0.000      0.000 #-
END OF DIMENSION HOLDER

            ASSIGN/LASTRUN=HOLDER.X.MEAS
C1         =COMMENT/INPUT,YES,FULL SCREEN=NO,
            "Last run ended on number : " + LASTRUN
            "Enter start number for this run."
            ASSIGN/COUNTER=C1.INPUT
            ASSIGN/VARCHECKED=1
            GOTO/BEGIN

ENDPROGRAM =LABEL/
            ASSIGN/HOLDER.X.MEAS=COUNTER-1


The main thing here is to convert the variable (COUNTER) to an absolute value by putting it into a generic feature and then evaluating a regular DIM, which will hold the value in between program executions.

On the next execution of the program, that value is fetched so execution can continue where it was stopped the last time.

More like a proof of concept and not tested thoroughly, but I provide it here for inspirational purposes. Feel free to modify it to suit your needs, but please post your version so others can learn from it.
Parents Reply Children
No Data