[Closed] PLEASE HELP: Is this possible?
Hi there!
I’m just wondering if it is possible to combine the code below with the UI, to copy the function into a loop or even double loop!??
I have addded spinners, but I’m stuck on how to link these, to the function CREATE() (I think thats what gets it going)
I’d really like it, if as you increase the columns and rows (in the UI spinner) the function is copied along the x-axis, and the z-axis! (and possibly be able to rotate and reposition the whole lot…see script below) (the width=2465 and height=3000 by the way)
Does anyone know if it is possible?
Many thanks
–Facade Generator
[size=1]–Script by Timo Sorakivi
[/size](
[size=1]–Define variables–
[/size][size=1]local[/size] a = #([size=1]“a”[/size],330,3000,360,[123,121,115])
[size=1]local[/size] b = #([size=1]“b”[/size],330,3000,360,[123,121,115])
[size=1]local[/size] c = #([size=1]“c”[/size],500,3000,600,[255,214,122])
[size=1]local[/size] d = #([size=1]“d”[/size],420,3000,10,[0,0,0])
[size=1]local[/size] ee = #([size=1]“ee”[/size],420,3000,10,[0,0,0])
[size=1]local[/size] f = #([size=1]“f”[/size],155,3000,160,[255,214,122])
[size=1]local[/size] g = #([size=1]“g”[/size],155,3000,160,[255,214,122])
[size=1]local[/size] h = #([size=1]“h”[/size],155,3000,160,[255,214,122])
[size=1]local[/size] i = #([size=1]“i”[/size],465,3000,160,[255,214,122])
[size=1]local[/size] j = #([size=1]“j”[/size],155,3000,160,[255,214,122])
[size=1]local[/size] k = #([size=1]“k”[/size],310,3000,160,[255,214,122])
[size=1]local[/size] baseItems = #(a,b,c,d,ee)
[size=1]local[/size] altItems = #()
altItems[1] = #(f,g,h)
altItems[2] = #(i)
altItems[3] = #(j,k)
[size=1]local[/size] pan_row = 1
[size=1]local[/size] pan_col = 1
[size=1]local[/size] x_move = 0
[size=1]local[/size] y_move = 0
[size=1]local[/size] z_move = 0
[size=1]local[/size] xOffset = 0
[size=1]local[/size] yOffset = 0
[size=1]local[/size] zOffset = 0
[size=1]local[/size] allItems = #()
[size=1]local[/size] theResult = #()
[size=1]local[/size] noboxes
[size=1]local[/size] cnt
[size=1]–Generate individual panel–
[/size][size=1]fn[/size] chooseAlts = (
v1 = altItems[random 1 3]
[size=1]return[/size] v1
)
[size=1]–Generate first block–
[/size][size=1]fn[/size] gimmeFirst = (
r1 = allItems[random 1 allItems.count]
counter = 0
[size=1]while[/size] (r1[1] == [size=1]“d”[/size][size=1]or[/size] r1[1] == [size=1]“ee”[/size][size=1]and[/size] counter < 20) [size=1]do[/size] (
counter += 1
r1 = allItems[random 1 allItems.count]
)
[size=1]if[/size](counter >= 20) [size=1]then[/size] noboxes = 1
[size=1]return[/size] r1
)
[size=1]–Generate next block–
[/size][size=1]fn[/size] gimmeNext indx = (
counter = 0
edell = theResult[indx-1]
r1 = allItems[random 1 allItems.count]
[size=1]while[/size] (r1[5] == edell[5] [size=1]and[/size] counter < 20) [size=1]do[/size] (
counter += 1
r1 = allItems[random 1 allItems.count]
)
[size=1]if[/size](counter >= 20) [size=1]then[/size] noboxes = 1
[size=1]return[/size] r1
)
[size=1]fn[/size] CREATE = (
noboxes = 0
theResult = #()
allItems = baseItems + chooseAlts()
cnt = allItems.count
[size=1]–print allItems
[/size][size=1]–format “%
” cnt
[/size]
[size=1]– first box
[/size]theResult[1] = gimmeFirst()
[size=1]– next boxes
[/size][size=1]for[/size] i = 2 [size=1]to[/size] (cnt-1) [size=1]do[/size] (
num = findItem allItems theResult[i-1]
deleteItem allItems num
theResult[i] = gimmeNext i
)
num = findItem allItems theResult[cnt-1]
deleteItem allItems num
[size=1]– last box
[/size]theResult[cnt] = allItems[1]
[size=1]–format “ratk : %
” theResult[cnt]
[/size][size=1]if[/size] (theResult[cnt][1] == [size=1]“d”[/size][size=1]or[/size] theResult[cnt][1] == [size=1]“ee”[/size]) [size=1]do[/size] (
noboxes = 1
)
[size=1]–print theResult
[/size][size=1]if[/size] (noboxes == 0) [size=1]do[/size] (
[size=1]local[/size] offsets = #(0)
[size=1]local[/size] posoffset = 0
[size=1]for[/size] i [size=1]in[/size] theResult [size=1]do[/size] append offsets i[2]
o = 1
zOffset += 3000
[size=1]–offsets each individual panel
[/size][size=1]for[/size] i [size=1]in[/size] theResult [size=1]do[/size] (
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()
)
)
[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:false
spinner spn_panZ [size=1]”Rows: “[/size] type:#integer range:[1,100,pan_row] enabled:false
)
group [size=1]“PLACE FACADE”
[/size](
label lbl_note3 [size=1]“Move facade into correct position”
[/size]spinner spn_move_x [size=1]”Move in X: “[/size] type:#float range:[-100,100,x_move] enabled:false
spinner spn_move_y [size=1]”Move in Y: “[/size] type:#float range:[-100,100,y_move] enabled:false
spinner spn_move_z [size=1]”Move in Z: “[/size] type:#float range:[-100,100,z_move] enabled:false
)
group [size=1]“ROTATE FACADE”
[/size](
label lbl_note4 [size=1]“Angle of rotation in z-axis”
[/size]spinner spn_rotz [size=1]”Angle of Rotation: “[/size] type:#integer range:[0,0,360] enabled:false
)
button but_reset [size=1]”Reset “[/size] align:#center across:2 width:60 height:27 pos:[100,305] toolTip: [size=1]“Click here to return to default setting”
[/size]
[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