PDA

View Full Version : I know this is simple but...how do you loop an offset?


r90210
12-28-2008, 11:10 AM
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:

(
--Define variables--

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



local pan_row = 1

local pan_col = 1

local xOffset = 0

local zOffset = 0







fn CREATE = ( b



for i = 1 to spn_panX.value-1 do

(

for j = 1 to spn_panZ.value-1 do

(

select b

--offset and copy the panel (b) in z and x directions (THIS IS TOTALLY WRONG)

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



)--end do

)--end do

)--end create



--automatically destroys and replaces any existing rollout boxes--

if ((r_thePanels != undefined) and (r_thePanels.isdisplayed)) do

(destroyDialog r_thePanels)

--Define interface

rollout r_thePanels "FACADE GENERATOR"

(

label lbl_note1 "Press to generate panel"

button btn_CREATE "CREATE" width:100 height:20 align:#center toolTip: "Click here to generate panel"



group "FACADE SIZE"

(

label lbl_note2 "Increase length and width of facade"

spinner spn_panX "Columns: " type:#integer range:[1,100,pan_col] enabled:true

spinner spn_panZ "Rows: " type:#integer range:[1,100,pan_row] enabled:true

)



--Event Handler

on btn_CREATE pressed do CREATE()



)







) --ends rollout

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

Bobo
12-28-2008, 03:31 PM
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.

CGTalk Moderation
12-28-2008, 03:31 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.