[Closed] Looking for a more efficient way of checking multiple checkboxes?
Hi all… got another one here.
I’m trying to update an array based on checkboxes selected and then use them as frames to render from the timeline. For example
Checkbox 1 = Frame 1
Checkbox 2 = Frame 2
Checkbox 3 = Frame 3
And so on and so forth (38 frames total)
This will be used to select specific frames to add to the render que, for example…
When you check the check boxes for 1, 5, 19, 22,23,24,28, those frames will be added to the ‘Frames’ Time Output under the common Parameters of the Render set up.
I have almost got this all working but the last part has me a little stumped (I do currently get an error ‘Invalid RendPickupFrames sting character: u’ not sure where it is getting a u from yet) but my main concern is in the only way I can think of to add each of the checked boxes to the array is with an if = true for each one of them, but I’m thinking that there must be a more efficient way to do this that I cannot think of being that I am new to scripting (I bet you’ve never heard anyone say that before haha).
Anyway, I’ll show you what I have (of a sample to avoid all the checkbox rollout elements) and you should be able to see what I’m talking about.
try(destroydialog FrameRollout_UI)catch()
frames = #()
rollout FrameRollout_UI "Frame Select"
(
group "Select Frames"
(
checkbox cb0 " Front" pos: [20,30] checked: true
checkbox cb1 "Back" pos: [150,30] checked: false
checkbox cb2 "Left" pos: [280,30] checked: false
checkbutton Toggle_all "Toggle All" tooltip:"This will turn all checkboxes to 'On/Off" pos: [300,220]
)
button btnSubmit "Submit to Deadline" pos: [300,460]
on Toggle_all changed state do
if state then
(
for aControl in FrameRollout_UI.controls do
(
case classof aControl of
(
CheckBoxControl: aControl.state = true
)
)
)
else
(
for aControl in FrameRollout_UI.controls do
(
case classof aControl of
(
CheckBoxControl: aControl.state = false
)
)
)
on btnSubmit pressed do
(
if cb0.state == true then
(
Insertitem 0 frames 1
Format "New Array: %\n" frames
)
if cb1.state == true then
(
Insertitem 1 frames 2
Format "New Array: %\n" frames
)
if cb2.state == true then
(
Insertitem 2 frames 3
Format "New Array: %\n" frames
)
for f in frames do
(
rendTimeType=4
rendPickupFrames=(F as string)
rendSaveFile=1
rendoutputfilename = ("C:\Users\MY\Desktop\Master Scene v1.0\RendTests\Frame_"+(f as string)+".tif")
max quick render --swap this for deadline submition
)
)
)
-- Create the UI
createDialog FrameRollout_UI 420 500
Appreciate any help and guidance here… I’m trying
try(destroydialog FramesRollout) catch()
rollout FramesRollout "Make Render PickupFrames" width:220
(
local frame_bt_pattern = "frame_cb_*"
group "Renfer Frames: "
(
checkbutton frame_cb_001 "" width:20 across:8
checkbutton frame_cb_002 "" width:20
checkbutton frame_cb_003 "" width:20
checkbutton frame_cb_004 "" width:20
checkbutton frame_cb_005 "" width:20
checkbutton frame_cb_006 "" width:20
checkbutton frame_cb_007 "" width:20
checkbutton frame_cb_008 "" width:20
checkbutton frame_cb_009 "" width:20 across:8
checkbutton frame_cb_010 "" width:20
checkbutton frame_cb_011 "" width:20
checkbutton frame_cb_012 "" width:20
checkbutton frame_cb_013 "" width:20
checkbutton frame_cb_014 "" width:20
checkbutton frame_cb_015 "" width:20
checkbutton frame_cb_016 "" width:20
checkbutton frame_cb_017 "" width:20 across:8
checkbutton frame_cb_018 "" width:20
checkbutton frame_cb_019 "" width:20
checkbutton frame_cb_020 "" width:20
checkbutton frame_cb_021 "" width:20
checkbutton frame_cb_022 "" width:20
checkbutton frame_cb_023 "" width:20
checkbutton frame_cb_024 "" width:20
checkbutton frame_cb_025 "" width:20 across:8
checkbutton frame_cb_026 "" width:20
checkbutton frame_cb_027 "" width:20
checkbutton frame_cb_028 "" width:20
checkbutton frame_cb_029 "" width:20
checkbutton frame_cb_030 "" width:20
checkbutton frame_cb_031 "" width:20
checkbutton frame_cb_032 "" width:20
label emp_00 height:-4
)
button make_pickup_bt "Pickup" width:48 align:#left offset:[-4,2] across:2 tooltip:"Make Render PickupFrames"
edittext pickup_frames_ed fieldwidth:150 align:#left offset:[-54,4]
label emp_01 height:-2
local frame_buttons = #()
local frame_numbers = #{}
fn makeRendPickupFrames =
(
for k=1 to frame_buttons.count do frame_numbers[k] = frame_buttons[k].state
ss = stringstream ""
with printallelements on format "%" frame_numbers to:ss
str = ss as string
free ss
str = substitutestring (trimright (trimleft str "#{") "}") ".." "-"
)
on make_pickup_bt pressed do
(
str = makeRendPickupFrames()
-- rendpickupframes = str
format ">> %\n" str
pickup_frames_ed.text = str
)
on make_pickup_bt rightclick do
(
case of
(
(keyboard.altpressed): frame_buttons.state = off -- clear all
(keyboard.controlpressed): frame_buttons.state = on -- set all
(keyboard.shiftpressed): for b in frame_buttons do b.state = not b.state -- toggle
)
make_pickup_bt.pressed()
)
on FramesRollout open do
(
frame_buttons = for c in FramesRollout.controls where c.name != undefined and matchpattern c.name pattern:frame_bt_pattern collect
(
s = substring c.name (c.name.count-2) -1
c.text = (execute s) as string
c
)
)
)
createdialog FramesRollout
try(destroydialog FramesRollout) catch()
rollout FramesRollout "Make Render PickupFrames" width:220
(
local frame_bt_pattern = "frame_cb_*"
group "Renfer Frames: "
(
checkbutton frame_cb_001 "" width:20 across:8
checkbutton frame_cb_002 "" width:20
checkbutton frame_cb_003 "" width:20
checkbutton frame_cb_004 "" width:20
checkbutton frame_cb_005 "" width:20
checkbutton frame_cb_006 "" width:20
checkbutton frame_cb_007 "" width:20
checkbutton frame_cb_008 "" width:20
checkbutton frame_cb_009 "" width:20 across:8
checkbutton frame_cb_010 "" width:20
checkbutton frame_cb_011 "" width:20
checkbutton frame_cb_012 "" width:20
checkbutton frame_cb_013 "" width:20
checkbutton frame_cb_014 "" width:20
checkbutton frame_cb_015 "" width:20
checkbutton frame_cb_016 "" width:20
checkbutton frame_cb_017 "" width:20 across:8
checkbutton frame_cb_018 "" width:20
checkbutton frame_cb_019 "" width:20
checkbutton frame_cb_020 "" width:20
checkbutton frame_cb_021 "" width:20
checkbutton frame_cb_022 "" width:20
checkbutton frame_cb_023 "" width:20
checkbutton frame_cb_024 "" width:20
checkbutton frame_cb_025 "" width:20 across:8
checkbutton frame_cb_026 "" width:20
checkbutton frame_cb_027 "" width:20
checkbutton frame_cb_028 "" width:20
checkbutton frame_cb_029 "" width:20
checkbutton frame_cb_030 "" width:20
checkbutton frame_cb_031 "" width:20
checkbutton frame_cb_032 "" width:20
label emp_00 height:-4
)
button make_pickup_bt "Pickup" width:46 align:#left offset:[-4,2] across:4 tooltip:"Make Render PickupFrames"
button clear_pickup_bt "Clear" width:46 align:#left offset:[10,2]
button setall_pickup_bt "Set All" width:46 align:#left offset:[10,2]
button invert_pickup_bt "Invert" width:46 align:#left offset:[10,2]
edittext pickup_frames_ed fieldwidth:204 align:#left offset:[-8,2]
label emp_01 height:-2
local frame_buttons = #()
local frame_numbers = #{}
fn makeRendPickupFrames =
(
for k=1 to frame_buttons.count do frame_numbers[k] = frame_buttons[k].state
ss = stringstream ""
with printallelements on format "%" frame_numbers to:ss
str = ss as string
free ss
str = substitutestring str " " ""
str = substring str 3 (str.count-3)
str = substitutestring str ".." "-"
)
on make_pickup_bt pressed do
(
str = makeRendPickupFrames()
-- rendpickupframes = str
format ">> %\n" str
pickup_frames_ed.text = str
)
on clear_pickup_bt pressed do
(
frame_buttons.state = off
make_pickup_bt.pressed()
)
on setall_pickup_bt pressed do
(
frame_buttons.state = on
make_pickup_bt.pressed()
)
on invert_pickup_bt pressed do
(
for b in frame_buttons do b.state = not b.state
make_pickup_bt.pressed()
)
on FramesRollout open do
(
frame_buttons = for c in FramesRollout.controls where c.name != undefined and matchpattern c.name pattern:frame_bt_pattern collect
(
s = substring c.name (c.name.count-2) -1
c.text = (execute s) as string
c
)
)
)
createdialog FramesRollout
We have already discussed on this forum how to make the rendpickupframes string using a list of frames… Using a bitarray conversion is an elegant solution, but it does not allow zero and negative frames, and unordered numbers.
There was a function that made a rendpickupframes string from a numeric array. But… it’s very hard to find anything on this forum right now, so because it’s annoying, I don’t want to try.
Oh wow, that’s more then I was expecting, thanks @denisT.
I’ll spend some time digging through it and see if I can work out what’s happening, where and when.
Really appreciate your help here. I had been on this for a couple of days and I bet you just smashed it out in 15 mins haha.
Side note: I have been trying to submit this reply since 02:12 am GMT but keep getting a 403 error and just have to keep trying.
Thanks again