Newparameter

Viewing 15 reply threads
  • Author
    Posts
    • #2366
      Szabadi Gergely
      Participant

      Hi!

      I have a problem. I would like to create an object, which has “n” units, which are the same macro units with several setups each. I would like to solve this case, with newparameter, like this:

      for i=1 to n
      	newparameter "setup1"+i, "RealNum", 1, 1
              newparameter "setup2"+i, "RealNum", 1, 1
      next i
      

      something like this, but I don’t have a clue, still new in GDL

      Thanks for any help

      G. Szabadi

    • #2367
      Gergely Fehér
      Keymaster

      Hi,

      In GDL objects the parameter list is fixed, you can not add more parameters to it from scripts. “NEWPARAMETER” command works only in backward migration, when you add parameters while saving your plan back to a previous version.
      The solution is to set a limit to your “n”, and add all the parameters to your objects parameter list and then hide the ones you don’t need when “n” is less than it’s maximal value. Take care, that the total number of parameters can not exceed 1024 in version 19 (and I think in 18 too).

      Gergely Fehér
      Team Leader, Library Team
      GRAPHISOFT SE

    • #2368
      Szabadi Gergely
      Participant

      Thank you, for your answer

      it is working fine (I don’t have so many parameters to reach the limit), but can you tell me any way, except copy the script, to add these parameters one kind of values?

      I have:

      param1
      param2
      param3
      etc.

      and I want to write same values for all of them, but it seems that this is not the best solution:

      
      values{2} "param1" 1, 'opt1', 2, 'opt2 etc...
      values{2} "param2" 1, 'opt1', 2, 'opt2 etc...
      values{2} "param3" 1, 'opt1', 2, 'opt2 etc...

      can I loop this somehow?

      G. Szabadi

    • #2369
      Joachim Sühlo
      Participant

      Normally you can write:

      DIM _param_value[]
      
      _param_value[1] = 'opt1'
      _param_value[2] = 'opt2'
      _param_value[3] = 'opt3'
      _param_value[4] = 'opt4'
      _param_value[5] = 'opt5'
      _param_value[6] = 'opt6'
      
      VALUES "param1" _param_value

      But this does not work with VALUES{2}, I do not know why.
      Instead this works, but I don’t know if this is what you wanted.

      DIM _param_val[]
      
      _param_val[1] = 1
      _param_val[2] = 'opt1'
      _param_val[3] = 2
      _param_val[4] = 'opt2'
      _param_val[5] = 3
      _param_val[6] = 'opt3'
      
      VALUES{2} "param2" _param_val[1], _param_val[2], _param_val[3], _param_val[4], _param_val[5], _param_val[6]

      And you can loop it like this:

      FOR i = 2 TO 3
      VALUES{2} "param" + STR(i,1,0) _param_val[1], _param_val[2], _param_val[3], _param_val[4], _param_val[5], _param_val[6]
      NEXT i

      GDL Object Developer
      b-prisma
      MAC OSx 10.12

      • #2372
        Gergely Fehér
        Keymaster

        Joachim,

        I suggest to not use “mixed” type arrays. It would be better, to do the following:

        dim intValues[3]
            intValues[1] = 1
            intValues[2] = 2
            intValues[3] = 3
        dim strDescriptions[3]
            strDescriptions[1] = 'opt1'
            strDescriptions[2] = 'opt2'
            strDescriptions[3] = 'opt3'
        values{2} "param" intValues, strDescriptions

        Gergely Fehér
        Team Leader, Library Team
        GRAPHISOFT SE

    • #2370
      Szabadi Gergely
      Participant

      Thank you very much it works well!

      Can you help me script this parameter if I want to use it in an “if”- type control statement?

      for i = 1 to 10
      if "param"+STR(i,1,0) = 2 then
      ....
      else
      endif
      next i

      I get error massage with and without the quotation marks too. I can’t figure out why

      G. Szabadi

      • #2371
        Gergely Fehér
        Keymaster

        In your sample “param”+STR(i,1,0) is a string, which can’t be check if it is equal with 2, as 2 is an integer.

        Gergely Fehér
        Team Leader, Library Team
        GRAPHISOFT SE

    • #2373
      Szabadi Gergely
      Participant

      Thank you very much for your answer, so it seems that I can’t concanenate strings to refer a variable name. Does anybody know how to shorten these:

      variables: a1, a2, a3, a4, a5

      for i=1 to 5
      values{2} "a"+str(i,1,0) 1, 'opt1', 2, 'opt2'
      next i
      
      if a1=1 then
      ...
      endif
      
      if a2=1 then
      ....
      endif
      
      etc.
      

      if a string can equal to a string, than why is this not working?

      for i=1 to 4
      if "a"+str(i,1,0)='opt1' then
      ....
      endif
      next i

      G. Szabadi

    • #2395
      Péter Baksa
      Keymaster

      In GDL scripts “…” is just a string even if the contents are the name of an existing parameter. In general-use languages there is usually a function like eval() to get the value behind the string, GDL can’t do this.
      In your second example the if condition translates to “a1″=’opt1′ which is false.
      You could use an array parameter and loop over it, but the values command can’t handle arrays.

      Péter Baksa
      Library Platform, Software Engineer
      GRAPHISOFT SE

    • #2414
      Szabadi Gergely
      Participant

      Thanks for the answer!
      I tried to create loop with arrays, but still now working. I don’t get error massage, the script is good, but not working. Does anybody has an idea, why?

      parameters a1, a2, a3, a4, a5

      !MASTER SCRIPT
      
      dim 	parama[2][5]
      	parama[1][1]=1
      	parama[1][2]=2
      	parama[1][3]=3
      	parama[1][4]=4
      	parama[1][5]=5
      	parama[2][1]='opt1'
      	parama[2][2]='opt2'
      	parama[2][3]='opt3'
      	parama[2][4]='opt4'
      	parama[2][5]='opt5'
      
      dim varia[]
          varia[1]='a1'
          varia[2]='a2'
          varia[3]='a3'
          varia[4]='a4'
          varia[5]='a5'
      
      !PARAMETERS SCRIPT
      
      for k=1 to 5
      values{2} "a"+str(k,1,0) parama[1], parama[2]
      next k
      
      !3D SCRIPT
      
      for i=1 to 5
      if varia(i)='opt1' then     !I have error to submit here the right type of bracket 
      addx (i-1)*.5
      block 1, 1, 1
      del 1
      endif
      next i

      G. Szabadi

    • #2415
      Péter Baksa
      Keymaster

      Your code would work with the following corrections:

      dim varia[]
          varia[1]=a1
          varia[2]=a2
          varia[3]=a3
          varia[4]=a4
          varia[5]=a5

      Quotation marks not needed.

      if varia­[LIT][i][/LIT]=1 then
      parameters set with values{2} can be used as numbers.

      Péter Baksa
      Library Platform, Software Engineer
      GRAPHISOFT SE

      • #2418
        Péter Baksa
        Keymaster

        So I meant:
        if varia­[ i ] = 1 then

        Péter Baksa
        Library Platform, Software Engineer
        GRAPHISOFT SE

    • #2416
      Péter Baksa
      Keymaster

      offtopic
      it’s hard to enter [ i ] in this forum, just add spaces around the i.

      Péter Baksa
      Library Platform, Software Engineer
      GRAPHISOFT SE

    • #2417
      Szabadi Gergely
      Participant

      Thank you very much!!!!!!!!!!!!!

      G. Szabadi

    • #2419
      Szabadi Gergely
      Participant

      Again, thanks. Huge help! Bu I don’t understand why is this working after if command and why it is not working with parameter command.

      if varia[ i ]= 1 then ! works fine
      parameters varia2[ i ]=2 ! doesn’t work

      G. Szabadi

    • #2420
      Szabadi Gergely
      Participant

      I had found an other problem with it. This is nice, working fine, create 5 block, but if a3=2 still creat 5 block instead of skipping the 3th one

      parameters a1, a2, a3, a4, a5

      !MASTER SCRIPT
      
      dim 	parama[2][5]
      	parama[1][1]=1
      	parama[1][2]=2
      	parama[1][3]=3
      	parama[1][4]=4
      	parama[1][5]=5
      	parama[2][1]='opt1'
      	parama[2][2]='opt2'
      	parama[2][3]='opt3'
      	parama[2][4]='opt4'
      	parama[2][5]='opt5'
      
      dim varia[]
          varia[1]=a1
          varia[2]=a2
          varia[3]=a3
          varia[4]=a4
          varia[5]=a5
      
      !PARAMETERS SCRIPT
      
      for k=1 to 5
      values{2} "a"+str(k,1,0) parama[1], parama[2]
      next k
      
      !3D SCRIPT
      
      for i=1 to 5
      if varia[ i ]=1 then
      addx (i-1)*.5
      block 1, 1, 1
      del 1
      endif
      next i

      G. Szabadi

      • #2421
        Gergely Fehér
        Keymaster

        It works for me (maybe you should check with a bigger gap between your blocks, as they are overlapping in your sample…), but you should modify your script a bit:

        !MASTER 
        dim intparam[5]
        	intparam[1] = 1
        	intparam[2] = 2
        	intparam[3] = 3
        	intparam[4] = 4
        	intparam[5] = 5
        
        dim descparam[5]
        	descparam[1] = 'opt1'
        	descparam[2] = 'opt2'
        	descparam[3] = 'opt3'
        	descparam[4] = 'opt4'
        	descparam[5] = 'opt5'
        !Paramscript
        for k=1 to 5
        	values{2} "a"+str(k,1,0) intparam, descparam
        next k

        You should avoid using “mixed” type arrays.

        Gergely Fehér
        Team Leader, Library Team
        GRAPHISOFT SE

    • #2450
      Szabadi Gergely
      Participant

      If I define a parameter with array that has separately string values, and integer values, how can I refer for the string values? I want to write the string values, but anyhow I do it I get back the integer values

      !MASTER
      dim intparam[]
          intparam[1]=1
          intparam[2]=2
          intparam[3]=3
          intparam[3]=4
      
      dim strparam[]
          strparam[1]='opt1'
          strparam[2]='opt2'
          strparam[3]='opt3'
          strparam[3]='opt4'
      
      !PARAMETERS
      values{2} "a" intparam[], strparam[]
      
      !2D
      
      text2 0, 0, a

      G. Szabadi

      • #2451
        Gergely Fehér
        Keymaster

        In this sample code, you can do it simply:
        text2 0, 0, strparam[a]

        In general, you can use the “PARVALUE_DESCRIPTION” function. Check it on the bottom of this page.

        Gergely Fehér
        Team Leader, Library Team
        GRAPHISOFT SE

    • #2457
      Szabadi Gergely
      Participant

      Thanks, perfect. I am trying to refer to this string description from a label. I am trying with ASSOCLP_PARVALUE_WITH_DESCRIPTION but with no sucess.

      !MASTER
      dim intparam[]
          intparam[1]=1
          intparam[2]=2
          intparam[3]=3
          intparam[3]=4
      
      dim strparam[]
          strparam[1]='opt1'
          strparam[2]='opt2'
          strparam[3]='opt3'
          strparam[3]='opt4'
      
      !PARAMETERS
      values{2} "a" intparam[], strparam[]
      
      !2D
      
      text2 0, 0, a
      
      ! LABEL 2D Script to refer and write "a"
      
      info1=""
      n=REQUEST("ASSOCLP_PARVALUE_WITH_DESCRIPTION", "a", DUMMY_name_index, DUMMY_type, DUMMY_flags, DUMMY_dim1, DUMMY_dim2, info1)
      
      text 0, 0, info1 

      I tried with strparam[a] as I put dim strparam[] in the label Master script also.

      G. Szabadi

    • #2477
      Dominika Bobály
      Keymaster

      There are multiple problems with the script above:
      – the 2 arrays in the master should run to the 4th index (you have double 3)
      – values{2} only works for integer types (“A” is length type by default)
      – loose the array brackets in the values{2} command definition
      – the ASSOCLP_PARVALUE_WITH_DESCRIPTION request returns pairs of value-description of the requested parameter, so info1 should be an array type of variable (otherwise it will only contain the first returned value only, without description string)
      You can do this:

      dim info1[]
      
      n = REQUEST("ASSOCLP_PARVALUE_WITH_DESCRIPTION", "parammparamm", DUMMY_name_index, DUMMY_type, DUMMY_flags, d, dd, info1)
      
      if vardim1(info1) > 0 then
      	for ii = 1 to vardim1(info1) step 2
      		text2 0, 0, info1[ii]
      		text2 1, 0, info1[ii+1]
      	next ii
      endif

      Dominika Bobály
      Library Developer, Library Team
      GRAPHISOFT SE

Viewing 15 reply threads
  • The forum ‘Parameter connections’ is closed to new topics and replies.