Notifications
Clear all

[Closed] I know this is simple but…how do you loop an offset?

Hi everyone!

I have a simple script below which I want to use to copy boxes in the x and z axis to form a grid, changed by a simple UI.

However, I am not sure how to script the copy and offset functions in the double loop(see below) Does anyone know how to code it?

Many, many, thanks!

Script:

(
[size=1][size=1]–Define variables–

[/size][size=1]local[/size] b = box pos:[0,0,0] width:2465 height:3000 length:180

[size=1]local[/size] pan_row = 1

[size=1]local[/size] pan_col = 1

[size=1]local[/size] xOffset = 0

[size=1]local[/size] zOffset = 0

[size=1]fn[/size] CREATE = ( b

[size=1]for[/size] i = 1 [size=1]to[/size] spn_panX.value-1 [size=1]do

[/size](

[size=1]for[/size] j = 1 [size=1]to[/size] spn_panZ.value-1 [size=1]do

[/size](

select b

[size=1]–offset and copy the panel (b) in z and x directions (THIS IS TOTALLY WRONG)

[/size]Offset:[(3000i),0,(2465j)]

)[size=1]–end do

[/size])[size=1]–end do

[/size])[size=1]–end create

[/size]

[size=1]–automatically destroys and replaces any existing rollout boxes–

[/size][size=1]if[/size] ((r_thePanels != undefined) [size=1]and[/size] (r_thePanels.isdisplayed)) [size=1]do

[/size](destroyDialog r_thePanels)

[size=1]–Define interface

[/size][size=1]rollout[/size] r_thePanels [size=1]“FACADE GENERATOR”

[/size](

label lbl_note1 [size=1]“Press to generate panel”

[/size]button btn_CREATE [size=1]“CREATE”[/size] width:100 height:20 align:#center toolTip: [size=1]“Click here to generate panel”

[/size]

group [size=1]“FACADE SIZE”

[/size](

label lbl_note2 [size=1]“Increase length and width of facade”

[/size]spinner spn_panX [size=1]”Columns: “[/size] type:#integer range:[1,100,pan_col] enabled:true

spinner spn_panZ [size=1]”Rows: “[/size] type:#integer range:[1,100,pan_row] enabled:true

)

[size=1]–Event Handler

[/size][size=1]on[/size] btn_CREATE pressed [size=1]do[/size] CREATE()

)

) [size=1]–ends rollout

[/size]CreateDialog r_thePanels pos:[200,200] width:260

[/size]

1 Reply

Where do I start?..

You have to decide whether you want to CREATE and OFFSET boxes inside the loop (in which case you have to make sure you DELETE anything created in a previous step), or do you want to create once and then only offset the existing boxes as you change the spinners. The answer to this question will dictate the look of your code.

For example, when you create a box or sphere using the Max Primitives, you might not notice this but the base object in the real plugin actually deletes and rebuilds the whole mesh on each change of a spinner. So this is something that is valid, but if you want for example to apply your own materials to the boxes manually and then preserve them, having the script deleting your previous object and creating new ones constantly might be something you don’t want.

The structure of your code is also a bit wrong, you are trying to access spinners of the rollout from a function defined BEFORE the rollout even existed, which of course means they cannot be “seen” by the function. Your options are: Either move the function inside the rollout right after the group definition and before the event handler, or leave the function where it is and pre-declare the rollout variable in the beginning of the script and prefix the spinners with the rollout variable name to get to them from the function.