Increment variable name in a do until loop

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Increment variable name in a do until loop

    Is there a way to increment variable names using a counting variable in a do until loop. Going to try and explain what I want to do. I have 7 parts as they get bigger the number of holes increase. I am wanting to use a text file to create a parametric program. I can do this easily but I need to be able to get to the xyz of each hole after the loop exits. I have a position requirement that requires all holes position to be checked as a set. I would like to read each line from the text file into different variables for example cir1x cir1y cir1d ect. So I can then create auto feature. I can easily do this to report xy and d of each hole as it reads through the file using this code.

    Code:
    FPTR       =FILE/OPEN,Z:\parametricdata\test.txt,READ
                DO/
    V4         =FILE/READLINE,FPTR,{CIR1X}+","+{CIR1Y}+","+{CIR1Z}+","+{CIR1D}
    CIR1       =FEAT/CONTACT/CIRCLE/DEFAULT,CARTESIAN,IN,LEAST_SQR
                THEO/<CIR1X,CIR1Y,CIR1Z>,<0,0,1>,CIR1D
                ACTL/<1.5,1.5,0>,<0,0,1>,0.125
                TARG/<CIR1X,CIR1Y,CIR1Z>,<0,0,1>
                START ANG=0,END ANG=360
                ANGLE VEC=<1,0,0>
                DIRECTION=CCW
                SHOW FEATURE PARAMETERS=NO
                SHOW CONTACT PARAMETERS=NO
    DIM LOC1= LOCATION OF CIRCLE CIR1  UNITS=IN ,$
    GRAPH=OFF  TEXT=OFF  MULT=10.00  OUTPUT=BOTH  HALF ANGLE=NO
    AX       MEAS    NOMINAL       +TOL       -TOL     OUTTOL        DEV
    X       1.5000  CIR1X     0.0020     0.0020     0.0000     0.0000 ----#----
    Y       1.5000     CIR1Y     0.0020     0.0020     0.0000     0.0000 ----#----
    D       0.1250  CIR1D     0.0020     0.0020     0.0000     0.0000 ----#----
    END OF DIMENSION LOC1
                UNTIL/V4=="EOF"
                FILE/CLOSE,FPTR,KEEP
    I can also do what i need for each line but just creating read lines for each one with different variable names. Each part has a different amount of holes ranging from 58 holes all the way up to 82. Is it possible to increment with each iteration of the loop the variable name?

  • #2
    Originally posted by chrisryn View Post
    Is there a way to increment variable names using a counting variable in a do until loop. Going to try and explain what I want to do. I have 7 parts as they get bigger the number of holes increase. I am wanting to use a text file to create a parametric program. I can do this easily but I need to be able to get to the xyz of each hole after the loop exits. I have a position requirement that requires all holes position to be checked as a set. I would like to read each line from the text file into different variables for example cir1x cir1y cir1d ect. So I can then create auto feature. I can easily do this to report xy and d of each hole as it reads through the file using this code.

    Code:
    FPTR =FILE/OPEN,Z:\parametricdata\test.txt,READ
    ASSIGN/COUNTER=0
    DO/
    ASSIGN/COUNTER=COUNTER + 1
    V4 =FILE/READLINE,FPTR,{CIR1X[COUNTER]}+","+{CIR1Y[COUNTER]}+","+{CIR1Z[COUNTER]}+","+{CIR1D[COUNTER]}
    CIR1 =FEAT/CONTACT/CIRCLE/DEFAULT,CARTESIAN,IN,LEAST_SQR
    THEO/<CIR1X[COUNTER],CIR1Y[COUNTER],CIR1Z[COUNTER]>,<0,0,1>,CIR1D[COUNTER]
    ACTL/<1.5,1.5,0>,<0,0,1>,0.125
    TARG/<CIR1X[COUNTER],CIR1Y[COUNTER],CIR1Z[COUNTER]>,<0,0,1>
    START ANG=0,END ANG=360
    ANGLE VEC=<1,0,0>
    DIRECTION=CCW
    SHOW FEATURE PARAMETERS=NO
    SHOW CONTACT PARAMETERS=NO
    DIM LOC1= LOCATION OF CIRCLE CIR1 UNITS=IN ,$
    GRAPH=OFF TEXT=OFF MULT=10.00 OUTPUT=BOTH HALF ANGLE=NO
    AX MEAS NOMINAL +TOL -TOL OUTTOL DEV
    X 1.5000 CIR1X 0.0020 0.0020 0.0000 0.0000 ----#----
    Y 1.5000 CIR1Y 0.0020 0.0020 0.0000 0.0000 ----#----
    D 0.1250 CIR1D 0.0020 0.0020 0.0000 0.0000 ----#----
    END OF DIMENSION LOC1
    UNTIL/V4=="EOF"
    FILE/CLOSE,FPTR,KEEP
    I can also do what i need for each line but just creating read lines for each one with different variable names. Each part has a different amount of holes ranging from 58 holes all the way up to 82. Is it possible to increment with each iteration of the loop the variable name?
    If I understood you right:

    Try this above in red. Using Array variables (VariableName[index as integer]). Search up the help file on them, they're very useful. FYI they start at index 1 and not 0 like most syntax' out there.

    It's untested just going from imagination. Please report back with debug results.

    Wait EDIT:

    I think you're looking for...
    Code:
    DIM LOC1= LOCATION OF CIRCLE CIR1[INDEX] UNITS=IN ,$
    GRAPH=OFF TEXT=OFF MULT=10.00 OUTPUT=BOTH HALF ANGLE=NO
    AX MEAS NOMINAL +TOL -TOL OUTTOL DEV
    X 1.5000 CIR1X 0.0020 0.0020 0.0000 0.0000 ----#----
    Y 1.5000 CIR1Y 0.0020 0.0020 0.0000 0.0000 ----#----
    D 0.1250 CIR1D 0.0020 0.0020 0.0000 0.0000 ----#----
    END OF DIMENSION LOC1
    [INDEX] being your loop iteration.
    Last edited by Kp61dude!; 08-16-2019, 01:45 PM.
    PcDmis 2015.1 SP10 CAD++
    Global 7-10-7 DC800S

    Comment


    • #3
      Aircode

      Do command
      Counter=counter+1
      assign/FNAME==CONCAT("CIRCLE",STR(COUNTER))
      FNAME=(Your autofeature)
      Loop

      Comment


      • Kp61dude!
        Kp61dude! commented
        Editing a comment
        Wait I was way off! This is what the OP wanted?

    • #4
      Ok so what I need is in the read line section where cir1x ect is. I need to be able to do cir1x then after the next execution of the do loop to do cir2x ect. The code I posted was an example of what I have got to work. Except the variables change with each iteration of the loop so I can't call them later.

      Comment


      • #5
        Originally posted by chrisryn View Post
        Ok so what I need is in the read line section where cir1x ect is. I need to be able to do cir1x then after the next execution of the do loop to do cir2x ect. The code I posted was an example of what I have got to work. Except the variables change with each iteration of the loop so I can't call them later.
        You want to call these variables later?
        Code:
        {CIR1X}+","+{CIR1Y}+","+{CIR1Z}+","+{CIR1D}
        If so make them into ARRAY type variables like I explained earlier.

        So after you update your loop to like like what I posted just put this into a comment so you can see what is what right after your loop end (after FILE/CLOSE,FPTR,KEEP):
        Code:
                    COMMENT/OPER,NO,FULL SCREEN=NO,AUTO-CONTINUE=NO,
                    CIR1X[1]
                    CIR1X[2]
                    CIR1X[3]
                    CIR1X[4]
                    CIR1X[5]
                    CIR1X[6]
                    CIR1X[7]
                    CIR1X[8]
                    and so forth...
        Last edited by Kp61dude!; 08-17-2019, 03:30 PM.
        PcDmis 2015.1 SP10 CAD++
        Global 7-10-7 DC800S

        Comment


        • #6
          Ok I did a test recommended by Kp61dude! and here is what worked.

          Code:
          FPTR       =FILE/OPEN,Z:\parametricdata\test.txt,READ
                      ASSIGN/COUNTER=0
                      DO/
                      ASSIGN/COUNTER=COUNTER+1
          V4         =FILE/READLINE,FPTR,{CIRX[COUNTER]}+","+{CIRY[COUNTER]}+","+{CIRZ[COUNTER]}+","+{CIRD[COUNTER]}
                      UNTIL/V4=="EOF"
                      FILE/CLOSE,FPTR,KEEP
                      IF/COUNTER==5
                      END_IF/
          CIR1       =FEAT/CONTACT/CIRCLE/DEFAULT,CARTESIAN,IN,LEAST_SQR
                      THEO/<CIRX[1],CIRY[1],CIRZ[1]>,<0,0,1>,CIRD[1]
                      ACTL/<0,0,0>,<0,0,1>,0.25
                      TARG/<CIRX[1],CIRY[1],CIRZ[1]>,<0,0,1>
                      START ANG=0,END ANG=360
                      ANGLE VEC=<1,0,0>
                      DIRECTION=CCW
                      SHOW FEATURE PARAMETERS=NO
                      SHOW CONTACT PARAMETERS=NO
          CIR2       =FEAT/CONTACT/CIRCLE/DEFAULT,CARTESIAN,IN,LEAST_SQR
                      THEO/<CIRX[2],CIRY[2],CIRZ[2]>,<0,0,1>,CIRD[2]
                      ACTL/<1,1,0>,<0,0,1>,0.5
                      TARG/<CIRX[2],CIRY[2],CIRZ[2]>,<0,0,1>
                      START ANG=0,END ANG=360
                      ANGLE VEC=<1,0,0>
                      DIRECTION=CCW
                      SHOW FEATURE PARAMETERS=NO
                      SHOW CONTACT PARAMETERS=NO
          CIR3       =FEAT/CONTACT/CIRCLE/DEFAULT,CARTESIAN,IN,LEAST_SQR
                      THEO/<CIRX[3],CIRY[3],CIRZ[3]>,<0,0,1>,CIRD[3]
                      ACTL/<2,2,0>,<0,0,1>,0.75
                      TARG/<CIRX[3],CIRY[3],CIRZ[3]>,<0,0,1>
                      START ANG=0,END ANG=360
                      ANGLE VEC=<1,0,0>
                      DIRECTION=CCW
                      SHOW FEATURE PARAMETERS=NO
                      SHOW CONTACT PARAMETERS=NO
          CIR4       =FEAT/CONTACT/CIRCLE/DEFAULT,CARTESIAN,IN,LEAST_SQR
                      THEO/<CIRX[4],CIRY[4],CIRZ[4]>,<0,0,1>,CIRD[4]
                      ACTL/<0,0,0>,<0,0,1>,0.5
                      TARG/<CIRX[4],CIRY[4],CIRZ[4]>,<0,0,1>
                      START ANG=0,END ANG=360
                      ANGLE VEC=<1,0,0>
                      DIRECTION=CCW
                      SHOW FEATURE PARAMETERS=NO
                      SHOW CONTACT PARAMETERS=NO
          CIR5       =FEAT/CONTACT/CIRCLE/DEFAULT,CARTESIAN,IN,LEAST_SQR
                      THEO/<CIRX[5],CIRY[5],CIRZ[5]>,<0,0,1>,CIRD[5]
                      ACTL/<1.5,1.5,0>,<0,0,1>,0.125
                      TARG/<CIRX[5],CIRY[5],CIRZ[5]>,<0,0,1>
                      START ANG=0,END ANG=360
                      ANGLE VEC=<1,0,0>
                      DIRECTION=CCW
                      SHOW FEATURE PARAMETERS=NO
                      SHOW CONTACT PARAMETERS=NO
          Thanks for the comments and help.

          Comment


          • #7
            Now I would just add error handling to your code and call it good for production. Only if you feel that the text file may not contain what is expected BUT if you know it'll always contain what it should (fingers crossed) then just ride with it.
            PcDmis 2015.1 SP10 CAD++
            Global 7-10-7 DC800S

            Comment

            Related Topics

            Collapse

            Working...
            X