PLEASE HELP! Is this possible?

Hi there,

I'm just wondering if it is possible to combine the code below with a UI, to copy the function into a loop!??

I have addded spinners, but I'm stuck on how to link these, to the function CREATE()

I'd really like it, if as you increase the columns and rows the function is copied along the x-axis, and the z-axis!

Does anyone know if it is possible?

Many thanks

--Facade Generator

--Script by Timo Sorakivi

(
--Define variables--
local a = #("a",330,3000,360,[123,121,115])
local b = #("b",330,3000,360,[123,121,115])
local c = #("c",500,3000,600,[255,214,122])
local d = #("d",420,3000,10,[0,0,0])
local ee = #("ee",420,3000,10,[0,0,0])
local f = #("f",155,3000,160,[255,214,122])
local g = #("g",155,3000,160,[255,214,122])
local h = #("h",155,3000,160,[255,214,122])
local i = #("i",465,3000,160,[255,214,122])
local j = #("j",155,3000,160,[255,214,122])
local k = #("k",310,3000,160,[255,214,122])
local baseItems = #(a,b,c,d,ee)
local altItems = #()
altItems[1] = #(f,g,h)
altItems[2] = #(i)
altItems[3] = #(j,k)

local pan_row = 1
local pan_col = 1
local x_move = 0
local y_move = 0
local z_move = 0

local xOffset = 0
local yOffset = 0
local zOffset = 0

local allItems = #()
local theResult = #()
local noboxes
local cnt

--Generate individual panel--
fn chooseAlts = (
v1 = altItems[random 1 3]
return v1
)

--Generate first block--
fn gimmeFirst = (
r1 = allItems[random 1 allItems.count]
counter = 0
while (r1[1] == "d" or r1[1] == "ee" and counter < 20) do (
counter += 1
r1 = allItems[random 1 allItems.count]
)
if(counter >= 20) then noboxes = 1
return r1
)

--Generate next block--
fn gimmeNext indx = (
counter = 0
edell = theResult[indx-1]
r1 = allItems[random 1 allItems.count]
while (r1[5] == edell[5] and counter < 20) do (
counter += 1
r1 = allItems[random 1 allItems.count]
)
if(counter >= 20) then noboxes = 1
return r1
)

fn CREATE = (
noboxes = 0
theResult = #()
allItems = baseItems + chooseAlts()
cnt = allItems.count

--print allItems
--format "%\n" cnt

-- first box
theResult[1] = gimmeFirst()

-- next boxes
for i = 2 to (cnt-1) do (
num = findItem allItems theResult[i-1]
deleteItem allItems num
theResult[i] = gimmeNext i
)
num = findItem allItems theResult[cnt-1]
deleteItem allItems num

-- last box
theResult[cnt] = allItems[1]

--format "ratk : %\n" theResult[cnt]
if (theResult[cnt][1] == "d" or theResult[cnt][1] == "ee") do (
noboxes = 1
)

--print theResult
if (noboxes == 0) do (
local offsets = #(0)
local posoffset = 0
for i in theResult do append offsets i[2]
o = 1
zOffset += 3000

--offsets each individual panel
for i in theResult do (
o += 1
posoffset += 0.5 * offsets[o-1] + 0.5 * offsets[o]
box name:i[1] pos:[posoffset,0,0] wirecolor:i[5] width:i[2] height:i[3] length:i[4]
)
completeRedraw()

)

)

--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:false
spinner spn_panZ "Rows: " type:#integer range:[1,100,pan_row] enabled:false
)
group "PLACE FACADE"
(
label lbl_note3 "Move facade into correct position"
spinner spn_move_x "Move in X: " type:#float range:[-100,100,x_move] enabled:false
spinner spn_move_y "Move in Y: " type:#float range:[-100,100,y_move] enabled:false
spinner spn_move_z "Move in Z: " type:#float range:[-100,100,z_move] enabled:false
)
group "ROTATE FACADE"
(
label lbl_note4 "Angle of rotation in z-axis"
spinner spn_rotz "Angle of Rotation: " type:#integer range:[0,0,360] enabled:false
)
button but_reset "Reset " align:#center across:2 width:60 height:27 pos:[100,305] toolTip: "Click here to return to default setting"

--Event Handler
on btn_CREATE pressed do CREATE()

)

) --ends rollout

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

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Budi G's picture

hi Randle90210 I'll try to

hi Randle90210

I'll try to help you...

Example from your script:

spinner spn_rotz "Angle of Rotation: " type:#integer range:[0,0,360] enabled:false

First, change "range" and "enabled" like this:

spinner spn_rotz "Angle of Rotation: " type:#integer range:[0,360,0] enabled:true

and then you can link to your function like this

on spn_rotz changed val do ()

FYI, check maxscript reference for help.
search display sample about "spinner"

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.