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

Parents
  • I appreciate the answers, but I'm having the same problem with each. If I select op1 it will run through the alignments, and all the op1 features, but it continues on to op2, even though I have an END_IF/ after op1. This is just a sample I'm using while trying to work this out, so yeah, there really is just two diameters in op1.

    I did get it to skip op1 and jump to op2. 

    C1 =COMMENT/INPUT,NO,FULL SCREEN=NO,

    1
    2
    3

    IF/C1.INPUT == 1
    CIR3 =FEAT/CONTACT/CIRCLE/DEFAULT,CARTESIAN,IN,LEAST_SQR
    THEO/<4,-2,0>,<0,0,1>,2
    ACTL/<4,-2,0>,<0,0,1>,2
    TARG/<4,-2,0>,<0,0,1>
    START ANG=0,END ANG=360
    ANGLE VEC=<1,0,0>
    DIRECTION=CCW
    SHOW FEATURE PARAMETERS=NO
    SHOW CONTACT PARAMETERS=YES
    NUMHITS=4,DEPTH=0.0787,PITCH=0
    SAMPLE METHOD=SAMPLE_HITS
    SAMPLE HITS=0,SPACER=0.0197
    AVOIDANCE MOVE=NO
    FIND HOLE=DISABLED,ONERROR=NO,READ POS=NO
    SHOW HITS=NO


    CIR4 =FEAT/CONTACT/CIRCLE/DEFAULT,CARTESIAN,IN,LEAST_SQR
    THEO/<2,-4,0>,<0,0,1>,2
    ACTL/<2,-4,0>,<0,0,1>,2
    TARG/<2,-4,0>,<0,0,1>
    START ANG=0,END ANG=360
    ANGLE VEC=<1,0,0>
    DIRECTION=CCW
    SHOW FEATURE PARAMETERS=NO
    SHOW CONTACT PARAMETERS=YES
    NUMHITS=4,DEPTH=0.0787,PITCH=0
    SAMPLE METHOD=SAMPLE_HITS
    SAMPLE HITS=0,SPACER=0.0197
    AVOIDANCE MOVE=NO
    FIND HOLE=DISABLED,ONERROR=NO,READ POS=NO
    SHOW HITS=NO
    END_IF/

    L2 =LABEL/
    CIR5 =FEAT/CONTACT/CIRCLE/DEFAULT,CARTESIAN,IN,LEAST_SQR
    THEO/<6,-4,0>,<0,0,1>,2
    ACTL/<6,-4,0>,<0,0,1>,2
    TARG/<6,-4,0>,<0,0,1>
    START ANG=0,END ANG=360
    ANGLE VEC=<1,0,0>
    DIRECTION=CCW
    SHOW FEATURE PARAMETERS=NO
    SHOW CONTACT PARAMETERS=YES
    NUMHITS=4,DEPTH=0.0787,PITCH=0
    SAMPLE METHOD=SAMPLE_HITS
    SAMPLE HITS=0,SPACER=0.0197
    AVOIDANCE MOVE=NO
    FIND HOLE=DISABLED,ONERROR=NO,READ POS=NO
    SHOW HITS=NO

  • I would put a label at the end of the program and then put a GOTO to that label at the end of each operation.

Reply Children
  • I need to revisit this topic. I have a program with 3ops. My comment asks the operator to select which op they're running, 1,  2,  3 or 4 for the full program. If they select either 1, 2 or 3, it runs fine. If they select 4 however, it has issues. FYI, this program only has one alignment. I'm assuming there doesn't need to be any code if they select op4, as it should skip 1, 2, and 3.

    This is the code below. If I select op 1, it will properly go to the XMINUS clearplane and run through op1. If however I select op 4, it will immediately try going through the part to XPLUS.

    My last issue with this is that the probe makes unintended and unnecessary rotations when selecting independent ops. We use a 90° probe on this part and at some points it will point the probe straight up to ZPLUS, then rotate back to it's correct position. It appears it's reading the angle from the probe above it, but that code is in a different op so I'm unsure why it's using it.


    A_B_C =ALIGNMENT/START,RECALL:BASIC_ALN,LIST=YES
    ALIGNMENT/LEVEL,XMINUS,DAT_A
    ALIGNMENT/TRANS,XAXIS,DAT_A
    ALIGNMENT/ROTATE_CIRCLE,YPLUS,TO,DAT_B,AND,DAT_C,ABOUT,XMINUS
    ALIGNMENT/TRANS,YAXIS,DAT_B
    ALIGNMENT/TRANS,ZAXIS,DAT_B
    ALIGNMENT/END


    DATDEF/A,FEATURES=DAT_A,,
    DATDEF/B,FEATURES=DAT_B,,
    DATDEF/C,FEATURES=DAT_C,,


    IF/C1.INPUT == 1
    GOTO/OP1
    END_IF/

    IF/C1.INPUT == 2
    MOVE/CLEARPLANE
    CLEARP/XMINUS,-4,XMINUS,0,OFF
    CLEARP/XMINUS,-25,XMINUS,0,ON
    TIP/T1A90B90, SHANKIJK=-1, -0.001, 0.003, ANGLE=89.773
    MOVE/POINT,NORMAL,<-4,0,0>
    MOVE/POINT,NORMAL,<-4,0,350>
    MOVE/POINT,NORMAL,<300,0,350>
    GOTO/OP2
    END_IF/


    IF/C1.INPUT == 3

    MOVE/CLEARPLANE
    MOVE/POINT,NORMAL,<-23.975,3.559,395.34>
    MOVE/POINT,NORMAL,<158.601,3.775,395.557>
    LOADPROBE/3MM_X_50MM_5
    TIP/T1A0B180, SHANKIJK=0.001, -1, -0.001, ANGLE=-0.15
    GOTO/OP3
    END_IF/

    OP1 =LABEL/
    CLEARP/XMINUS,-4,XMINUS,0,ON
    MOVE/CLEARPLANE

  • Setup one startup point, let each OP block share this beginning point, all alignments needed for OP do inside OP block

    Use goto command for navigating through operations.
    put Labels in each OP with START and END label, in the beginning of block check for operator input and navigate to labels according it.

  • 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.