2023-04-20 03:02 PM - edited 2023-04-20 04:30 PM
Hello,
I'd like to know how to improve my use of the Parameter buffer when it comes to loops because I have a loop that create a simple stack of prisms :
for N = 1 to 4
put 0, 0, 15,
1, 0, 15,
1, 1, 15,
0, 1, 15,
0, 0, 1
prism_ nsp/3, 0.5, get(nsp)
addz 0.5
next N
del 4
I feel this code is not good as I populate and clear the stack with each loop rather than populating it once, looping the geometry and clearing the stack at the end. I would like to make it better but the following snippet doesn't work :
put 0, 0, 15,
1, 0, 15,
1, 1, 15,
0, 1, 15,
0, 0, 1
for N = 1 to 4
prism_ nsp/3, 0.5, use(nsp)
addz 0.5
next N
del 4
get(nsp) ! Clearing the stack that way after the loop doesn't work
Is there a way to clear the parameter buffer without having to use get() in a command ? Or am I reduced to do this :
put 0, 0, 15,
1, 0, 15,
1, 1, 15,
0, 1, 15,
0, 0, 1
for N = 1 to 4-1
prism_ nsp/3, 0.5, use(nsp)
addz 0.5
next N
prism_ nsp/3, 0.5, get(nsp)
del 3
get(nsp)
Looks less readable but seems to be the only solution ?
Solved! Go to Solution.
2023-04-20 03:41 PM - edited 2023-04-20 03:46 PM
Try to use
if NSP>0 then ttt = max(get(NSP))
Final code:
n_prism = 4
put 0, 0, 15
put 1, 0, 15
put 1, 1, 15
put 0, 1, 15
put 0, 0, 1
for N = 1 to n_prism
prism_ nsp/3, 0.5, use(nsp)
addz 0.5
next N
del n_prism
if nsp>0 then ttt = max(get(nsp))
Structural engineer, developer of free addon for sync GDL param and properties
2023-04-20 03:41 PM - edited 2023-04-20 03:46 PM
Try to use
if NSP>0 then ttt = max(get(NSP))
Final code:
n_prism = 4
put 0, 0, 15
put 1, 0, 15
put 1, 1, 15
put 0, 1, 15
put 0, 0, 1
for N = 1 to n_prism
prism_ nsp/3, 0.5, use(nsp)
addz 0.5
next N
del n_prism
if nsp>0 then ttt = max(get(nsp))
Structural engineer, developer of free addon for sync GDL param and properties
2023-04-20 04:00 PM
Thanks, it worked 👍
2023-09-09 02:36 AM
The last get (nsp) is not needed because it does not perform any operations and only extracts data, resulting in a program error.
2023-09-11 03:35 AM
If you only ever 'USE' the PUT stack, then the stack will remain populated.
The last 'GET' just clears the stack so you can use PUT again later if you need to.
Barry.
2024-01-11 03:33 PM
It should be possible to just use GET(NSP) to Empty the stack. While it is not, Thank you for this solution.