cancel
Showing results for
Did you mean:
cancel
Showing results for
Did you mean:
BIM Coordinator Program (INT) April 22, 2024
Find the next step in your career as a Graphisoft Certified BIM Coordinator!
GDL
About building parametric objects with GDL.

# Loop Parameter Reset

Guru
Hi all,

If I have a loop of 1 to N utilising the parameter X=A, where A is some previously defined value, is it possible to pick out when i=G then X=B without needing to save A to a new parameter so that for other steps the original value is still utilised?

Simplified example:
```
!======THESE TWO LINES CANNOT BE INCLUDED IN THE LOOP======
x = 1
n = 5
!===========================================================

FOR i = 1 to n step 1

If i = 3 then x = 5
text2	y,	0,	x

next i```
```Returns:	1	1	5	5	5
Desired:	1	1	5	1	1```

Ling.

EDIT: Clarified that X is outside of the loop.
EDIT 2: Wow... I am really good at manually writing out the correct return figures...

 AC22-23 AUS 7000 Help Those Help You - Add a Signature Self-taught, bend it till it breaks Creating a Thread Win11 | i9 10850K | 64GB | RX6600 Win10 | R5 2600 | 16GB | GTX1660
15 REPLIES 15
Moderator
Just put an IF statement in your loop?
Unless I am not understanding what you need.
```for i = 1 to n
X=A
if i = G then
X=B
endif
next i```

Barry.
One of the forum moderators.
Versions 6.5 to 27
Dell XPS- i7-6700 @ 3.4Ghz, 16GB ram, GeForce GTX 960 (2GB), Windows 10
Lenovo Thinkpad - i7-1270P 2.20 GHz, 32GB RAM, Nvidia T550, Windows 11
Guru
Doesn't that change the value of X for all proceeding steps? Or has my understanding of inline definitions been flawed this whole time... I am not up to needing this yet except for when i = N where N is the final use of that value, so a none issue, but the situation popped up into my head and made a few knots...

Ling.

EDIT : Modified original post to clarify details

 AC22-23 AUS 7000 Help Those Help You - Add a Signature Self-taught, bend it till it breaks Creating a Thread Win11 | i9 10850K | 64GB | RX6600 Win10 | R5 2600 | 16GB | GTX1660
Moderator
Lingwisyer wrote:
Doesn't that change the value of X for all proceeding steps?

X can only ever equal one value.
I thought you just wanted to trap a certain count or point in the loop.

You can reset the value of X as you go through the script.
It shouldn't affect where it has been used already but will all future uses.
This is assuming you are not resetting the actual parameter value.

Whenever I change a value I always store an original version of it.
```X=10
X_orig = X
X=20```
Then if ever I need to go back to the original value...
`X= X_orig `

Maybe I don't understand exactly what you want after all.

Barry.
One of the forum moderators.
Versions 6.5 to 27
Dell XPS- i7-6700 @ 3.4Ghz, 16GB ram, GeForce GTX 960 (2GB), Windows 10
Lenovo Thinkpad - i7-1270P 2.20 GHz, 32GB RAM, Nvidia T550, Windows 11
Mentor
Your error was in the conditional statement location
```

x = 1
n = 5

FOR i = 1 to n step 1
If i = 3 then
x = 5
endif

text2	y,	0,	x
next i

```
A good friend of mine have once told me that I´m so brute that I´m capable of creating a GDL script capable of creating GDLs.
Guru
Moonlight wrote:
Your error was in the conditional statement location
```

x = 1
n = 5

FOR i = 1 to n step 1
If i = 3 then
x = 5
endif

text2	y,	0,	x
next i

```

That just shifts the number change. Does not isolate it. I will probably just end up making a new set a parameters to temporarily store the relevant values.

Ling.

 AC22-23 AUS 7000 Help Those Help You - Add a Signature Self-taught, bend it till it breaks Creating a Thread Win11 | i9 10850K | 64GB | RX6600 Win10 | R5 2600 | 16GB | GTX1660
Moderator
This works if it is what you are after.
```n = 5

FOR i = 1 to n step 1
x = 1
If i = 3 then
x = 5
endif

text2	i,	0,	x
next i
```

Barry.
One of the forum moderators.
Versions 6.5 to 27
Dell XPS- i7-6700 @ 3.4Ghz, 16GB ram, GeForce GTX 960 (2GB), Windows 10
Lenovo Thinkpad - i7-1270P 2.20 GHz, 32GB RAM, Nvidia T550, Windows 11
Guru
X is some previously defined value, external to the loop, it cannot be statically defined here.

 AC22-23 AUS 7000 Help Those Help You - Add a Signature Self-taught, bend it till it breaks Creating a Thread Win11 | i9 10850K | 64GB | RX6600 Win10 | R5 2600 | 16GB | GTX1660
Expert
a few minor things:
1. you can do the if statement in one line without the "endif". looks better and fewer lines of code.
2. don't need the "step 1" as that is assumed unless otherwise defined

```
n = 5
for i = 1 to n
x = 1
If i = 3 then x = 5
text2	i,	0,	x
next i
```
Creator of Cadswift's parametric GDL libraries
Creator of Infinite Openings and Component Catalogues
Push the envelope & watch it bend
Expert
looking back at your original post, it is as Barry said, just move the "x = 1" into the loop before the "if... x = 5".
that way its reinstating the x = 1 for each value, and it only get overwritten when the if statement is true.
Creator of Cadswift's parametric GDL libraries
Creator of Infinite Openings and Component Catalogues
Push the envelope & watch it bend