hexagon logo

SKIPPING OPS WITH IF AND STATEMENTS

Hey all,

A program begins with a basic alignment and then a DCC alignment. When the program starts it asks what op you're checking, 1, 2, or 3 for example. Depending on what you select the program should construct your alignments and then move on to that op. If you're only checking op2 for example, how do you first instruct pcdmis to run the alignment code before moving on to op2? 

It's been years since I've done this and I feel like Forrest Gump all of a sudden.

Thank You

  • I don't see any IF statement to control what happens if they enter 4, did you forget to include it? The reason when they enter 4 this happens is because nothing is controlling what they are allowed to enter. 

    Option 1. Change to Tracefield so that they only have available options to select from in a dropdown list. And force the option to be required to be integer if needed. Instead of C1.INPUT value check, you'd be using V1, or whatever variable you choose

    TRACEFIELD/DISPLAY=YES,REPORT=NO,DISPLAY MESSAGE=Select Operation ; Operation : 3
                ASSIGN/V1=GETTRACEVALUE("Operation")

    Image on left for creating the Tracefield, image on right for what it looks like when executed.

    Option 2, add a condition to control what values are allowed. A third if statement for if the value is not 1, 2, or 3 to return display "error" and return to C1

    REDO       =LABEL/
    C1         =COMMENT/INPUT,NO,FULL SCREEN=NO,
                Enter Number
                IF/C1.INPUT == 1
      $$ NO,
                  Do something
                  GOTO/OP1
                END_IF/
                IF/C1.INPUT == 2
      $$ NO,
                  Do something
                  GOTO/OP2
                END_IF/
                IF/C1.INPUT == 3
      $$ NO,
                  Do something
                  GOTO/OP3
                END_IF/
                IF/C1.INPUT <> 1 OR 2 OR 3
                  COMMENT/OPER,NO,FULL SCREEN=NO,AUTO-CONTINUE=NO,OVC=NO,
                  Invalid Input. Must be 1, 2 or 3. --> Return to input C1
                  GOTO/REDO
                END_IF/
    OP1        =LABEL/
    OP2        =LABEL/
    OP3        =LABEL/

    I believe this is similar to what I posted above 2 months ago now that I look at it.

    If there is an OP4, can you share it? I will need information to figure out how to correct the issue

  • I had op4 in but removed it this morning thinking that if they don't press 1, 2 or 3, the program would run as a complete part. Regardless, op4 had the same result of trying to go through the part, ignoring the clearplane that was inside of the "IF/C1.INPUT == 4 prompt.

    Is it correct to put whatever moves I need to jump from the alignment to the op being selected within the IF statements?

  • William,

    I've been experimenting when I can. I get op1, 2 and 3, for example. My problem is when I want to run all three ops, i.e. the full program. In my mind adding OP4 in as an option with no coding for op4 tells the program to skip all the code for op1, 2 and 3 simply because you're not selecting one of them.

    I recall from C# programming that omitting code is just as useful as including it. You know, computers. If it's not 1 then it's 0 and vice versa. If it's not 1, 2 or 3 then it's ignoring whatever that code is telling it to do, by omission.

    The other nagging issue is my probe always rotates to whatever probe angle is last in the program. If for example the full program ends with A90/B-90, but op1 only uses A90/B90, op1 will still end by rotating to A90/B-90 even though I end my op1 with a GOTO/END after the op1 dimensioning.

  • To fix your probe rotation issue, you'll need to press F5 and, in the General tab, uncheck Reset global settings when branching.

  • A tip command is a state (global) command, along with others. If the checkbox is activated, when PC-DMIS encounters a branch command (GOTO) it will scan up in the program and reset to the previously defined state command. You can read about it here: nexus.hexagon.com/.../Reset_global_settings_when_branching.htm

  • IF you want option 4 to run the entire program. Have it start at the same GOTO as 1, and at the end of each block of code that is signified to be for 1, 2, or 3. You'll have a variable for if Option 4 is selected to continue to block 2, if option 1, go to reporting or something you choose. Repeat for end of block 2, and 3 if needed, but since 3 would be last, no need for a GOTO, just let it keep running, and then go to reporting. rough idea below soon.

    Something like this?

    C1         =COMMENT/INPUT,NO,FULL SCREEN=NO,
                1 for first block, 2 for 2nd block, 3 for 3rd block, 4 for entire program
                IF_GOTO/C1.INPUT==1 OR 4,GOTO = BLOCK1
                IF_GOTO/C1.INPUT==2,GOTO = BLOCK2
                IF_GOTO/C1.INPUT==3,GOTO = BLOCK3
    BLOCK1     =LABEL/
    $$ NO,
                Code Block 1
                IF_GOTO/C1.INPUT==1,GOTO = RPTBLOCK
                IF_GOTO/C1.INPUT==4,GOTO = BLOCK2
    BLOCK2     =LABEL/
    $$ NO,
                Code Block 2
                IF_GOTO/C1.INPUT==2,GOTO = RPTBLOCK
    BLOCK3     =LABEL/
    $$ NO,
                Code Block 3
    RPTBLOCK   =LABEL/

  • So, with IF flow controls, the only time the routine will pass into/execute the code: is IF the IF equals 1 (yes). 
    The easiest method to implement "run it all" with a 4 value... is to simply add "OR" to your IF commands (referencing  's code above)

     IF/OPERATION == 1 OR 4
    run op1

    IF/OPERATION == 2 OR 4
    run op2

    IF/OPERATION == 3 OR 4
    run op3

    when you run input 4, it will now execute all 3 ops.

    also, regarding probe rotations of skipped code, you might want to go into the F5 general tab, click F1 help and click on "check boxes for the general tab" and read up on "Reset global settings when branching"  I believe this will skip probe rotations when they are skipped, when it IS checked.

  • It will skip probe rotations when it is not checked.

  • Makes sense. I never considered that. Thanks.