[Closed] readline textfile to array
If you select x amount of items in the list on the left and move them to the right and then hit the “X” clear button. Then click the “<” arrow. It will populate the right list with the objects you just removed from it.
It should not do anything.
check it out.
Thanks
try(destroyDialog ::rltest)catch()
rollout rltest "test"
(
fn fnListControls oldLst newLst oldArr newArr = ( -- add Objects to list
local currSel = oldLst.selection
for i = oldLst.items.count to 1 by -1 where currSel[i] do (appendIfUnique newArr oldLst.items[i])
newLst.items = sort newArr
for i = oldLst.items.count to 1 by -1 where currSel[i] do (deleteItem oldArr i)
oldLst.items = for i in oldArr collect i -- update list with array
oldLst.selection = #{}
)
fn fnClearBlackList newList newArr oldList oldArr = -- Clear Blacklist
(
for itm in oldArr do appendIfUnique newArr itm
newList.items = sort newArr
oldArr = #()
oldList.items = oldArr
)
local whiteListedArr = #("Render01","Render02","Render03","Render04","Render05","Render06")
local blackListedArr = #()
MultiListBox mlbWhiteSlaves "Whitelisted Slaves:" items:whiteListedArr pos:[5,5] width:130 height:12
MultiListBox mlbBlackSlaves "Blacklisted Slaves:" pos:[167,5] width:130 height:12
button btnMoveToKT ">" height:30 width:30 pos:[136,22]
button btnRemoveFromKT "<" height:30 width:30 pos:[136,54]
button btnClearKT "X" height:30 width:30 pos:[136,86]
on btnMoveToKT pressed do
(
fnListControls mlbWhiteSlaves mlbBlackSlaves whiteListedArr blackListedArr
)
on btnRemoveFromKT pressed do
(
fnListControls mlbBlackSlaves mlbWhiteSlaves blackListedArr whiteListedArr
)
on btnClearKT pressed do
(
fnClearBlackList mlbWhiteSlaves whiteListedArr mlbBlackSlaves blackListedArr
)
)
createDialog rltest 300 190
In regards to the previous post about reading from a text file and appending each line to an array. Just swap the “c:/testtext.txt” string with the location of your file:
theFile = openfile "c:/testtext.txt"
txtArray = #()
if openfile != undefined then
(
while not eof theFile do
(
append txtArray (readline theFile)
)
close theFile
)
I believe you need to pass the array to the function as a reference. The following works for me:
try(destroyDialog ::rltest)catch()
rollout rltest "test"
(
fn fnListControls oldLst newLst oldArr newArr = ( -- add Objects to list
local currSel = oldLst.selection
for i = oldLst.items.count to 1 by -1 where currSel[i] do (appendIfUnique newArr oldLst.items[i])
newLst.items = sort newArr
for i = oldLst.items.count to 1 by -1 where currSel[i] do (deleteItem oldArr i)
oldLst.items = for i in oldArr collect i -- update list with array
oldLst.selection = #{}
)
fn fnClearBlackList newList newArr oldList &oldArr = -- Clear Blacklist
(
for itm in oldArr do appendIfUnique newArr itm
newList.items = sort newArr
oldArr = #()
oldList.items = oldArr
)
local whiteListedArr = #("Render01","Render02","Render03","Render04","Render05","Render06")
local blackListedArr = #()
MultiListBox mlbWhiteSlaves "Whitelisted Slaves:" items:whiteListedArr pos:[5,5] width:130 height:12
MultiListBox mlbBlackSlaves "Blacklisted Slaves:" pos:[167,5] width:130 height:12
button btnMoveToKT ">" height:30 width:30 pos:[136,22]
button btnRemoveFromKT "<" height:30 width:30 pos:[136,54]
button btnClearKT "X" height:30 width:30 pos:[136,86]
on btnMoveToKT pressed do
(
fnListControls mlbWhiteSlaves mlbBlackSlaves whiteListedArr blackListedArr
)
on btnRemoveFromKT pressed do
(
fnListControls mlbBlackSlaves mlbWhiteSlaves blackListedArr whiteListedArr
)
on btnClearKT pressed do
(
fnClearBlackList mlbWhiteSlaves whiteListedArr mlbBlackSlaves &blackListedArr
)
)
createDialog rltest 300 190
I was unaware of the “&”
thank you!
What exactly does “&” do when using it?
It essentially assigns parameters directly to a variable, array, etc. that are passed in the argument list of a function. Look up “By Reference Parameter Passing” in the maxscript help and it will do a much better job explaining it then I could.