cancel
Showing results for
Did you mean:
cancel
Showing results for
Did you mean:
Developer forum

## Loop Parameter Reset Hero
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 Win10 | R5 2600 | 16GB | GTX1660
15 REPLIES 15 Hero
Start of the script:
```d = B - gs_fw_lower - gs_fw_upper - 2 * gs_int_fw				!Louvre space
IF louvre_over <= 0 then							!If NO louvre overlap
n = int(d /(gs_louvre_width - louvre_over))
dp = gs_louvre_width - louvre_over
ELSE
dp = gs_louvre_thk / ( cos ( atn ( ( gs_louvre_width - louvre_over) / gs_louvre_thk) ) )
n = int(d / dp) + 1
endIF```

The loop (for one set of conditionals):
```FOR i=1 to n

...

IF Louvred_sealside = "Both" then
IF i = 1 | i = n then
gs_louvre_opening_angle = gs_louvre_opening_max
gs_louvre_width = sqr((d - (dp * (n - 1) + Louvre_over))^2 - (gs_louvre_thk)^2 ) + Louvre_over
endIF
endIF

...

cprism_ louvtopmat, louvbotmat, louvsidemat,
5, gs_louvre_thk,
-a / 2 + gs_fw_side_right + gs_int_fw,	-(gs_louvre_width) / 2,	_status,
-a / 2 + gs_fw_side_right + gs_int_fw,	 (gs_louvre_width) / 2,	_status,
a / 2 - gs_fw_side_left - gs_int_fw,	 (gs_louvre_width) / 2,	_status,
a / 2 - gs_fw_side_left - gs_int_fw,	-(gs_louvre_width) / 2,	_status,
-a / 2 + gs_fw_side_right + gs_int_fw,	-(gs_louvre_width) / 2,	-1

...

next i```

 AC22-23 AUS 7000 Help Those Help You - Add a Signature Self-taught, bend it till it breaks Creating a Thread Win10 | R5 2600 | 16GB | GTX1660 Expert
if it's forbidden to repeat x=1 or use new parameter, n=5 like this:
```
FOR i = 1 to n step 1
If i = 3 then x = 5 then
text2	y,	0,	x
x=1
endif
text2	y,	0,	x
next i```
maybe if you know precisely when it occurs just exclude from the loop? (though it looks awful)
FOR i=1 to 2 ...
if i=3 then ...
FOR i=4 to n ...
AC 22, 24 | Win 10 Hero
A. wrote:
maybe if you know precisely when it occurs just exclude from the loop? (though it looks awful)
FOR i=1 to 2 ...
if i=3 then ...
FOR i=4 to n ...

Doing so would basically double the script length... Easier to just populate a half dozen new variables to my list.

 AC22-23 AUS 7000 Help Those Help You - Add a Signature Self-taught, bend it till it breaks Creating a Thread Win10 | R5 2600 | 16GB | GTX1660  Graphisoft
Lingwisyer wrote:
...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?
You just said it:
`if i = G then X = B else X = A`
Péter Baksa
Software Engineer, Library as a Platform
Graphisoft SE, Budapest Hero
Peter wrote:
Lingwisyer wrote:
...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?
You just said it:
`if i = G then X = B else X = A`

Was hoping there would be a way that did not involve rewriting a dozen macros to use a dependent variable rather than the independent, and by the sounds of it, there is not so I will be needing to rewrite them at some point.

```C = X
A = X

...

if i = G then C = B else C = A

...

*replace X with C in all dependent macros*```

Sorry for looking for a lazy way out,
Ling.

 AC22-23 AUS 7000 Help Those Help You - Add a Signature Self-taught, bend it till it breaks Creating a Thread Win10 | R5 2600 | 16GB | GTX1660  Graphisoft
In parameter calls you can assign variables to parameters:
`call "macro" parameters A = something, ....`
The subsequent calls from "macro" will use the value of something.
If you don't want to write each parameter in the call, write just the modified ones:
`call "macro" parameters all, A = something`
Péter Baksa
Software Engineer, Library as a Platform
Graphisoft SE, Budapest Latest solutions

Most liked posts