2023-03-08 11:46 AM
Hello,
I might be drowning in a glass of water here.
I have a working script where two objects of the same width are duplicated by a FOR-TO-NEXT, where the user chooses if it want all the objects at the same height or alternate height.
With my limited knoledge, I have set two loops, one for the "smaller" and another one for the "bigger" one. My problem comes when changing the width of the whole repetition element where the last object in the loop is "out" from the cage and sometimes it doesn't.
In this case if I set the width of the whole element to 1550mm it looks as it should:
But if I set the width of the whole element to 1475mm it goes crazy:
Not sure if instead of two loops I can do the same but with one loop only.
Here is my loop for each element:
N1= INT(A /(width+gap))
FOR H=1 TO N1
GOSUB 20
ADDx gap + width
NEXT H
N2= INT(A /(width-gap))
FOR H=1 TO N2 STEP 2
GOSUB 40
ADDx gap + width
NEXT H
DEL TOP
END
20:
ADDx gap*0.5
block widthA, heightB, ZZYZX
RETURN
40:
ADDx gap + widthA + gap*0.5
block widthA, heightC, ZZYZX
RETURN
Juan
Solved! Go to Solution.
2023-03-09 08:21 AM - edited 2023-03-09 08:26 AM
Did not know about the Modulo operation. Was thinking that you could take the integer of half your input, multiply it then compare... the same outcome in 2 characters vs 20.
Given the blocks are just variations on the same shape, it would probably be better to use a generic subroutine and define parameters instead;
for i=1 to last
if i%2 then
height = c
else
height = d
endif
gosub "block 1"
next i
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 |
2023-03-08 03:03 PM
Use the modulo for the current loop number. E.g.:
for i=1 to last
if i%2 then
gosub "block 1"
else
gosub "block 2"
endif
next i
(where "last" is the total number fo blocks you need)
2023-03-09 08:21 AM - edited 2023-03-09 08:26 AM
Did not know about the Modulo operation. Was thinking that you could take the integer of half your input, multiply it then compare... the same outcome in 2 characters vs 20.
Given the blocks are just variations on the same shape, it would probably be better to use a generic subroutine and define parameters instead;
for i=1 to last
if i%2 then
height = c
else
height = d
endif
gosub "block 1"
next i
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 |
2023-03-10 06:35 AM
Thank you both for chime in, I wasn't aware we can use a Modulo operation.
Both solutions are great, but the one from Ling I noticed it would be easier to maintain since there is one subroutine ony so I can ditch the second one. Nevertheless, it is great to see different approach to the same problem. 👍
Juan
2023-03-21 07:26 PM - edited 2023-03-21 07:27 PM
Could also work like that if you need more than 2 Variations.
current_sub = 1
for i=1 to last
gosub current_sub
next i
END:
1:
!Dimension variation
current_sub = 2
RETURN
2:
!Dimension variation
current_sub = 3
RETURN
3:
!Dimension variation
current_sub = 1
RETURN