|
Tell us what you think of the site.
|
Autodesk Media & Entertainment User Community
|
Autodesk® 3ds Max®
|
|
Autodesk® Maya®
|
|
Autodesk® Softimage®
|
|
Autodesk® MotionBuilder®
|
|
Autodesk® Mudbox™
|
|
Autodesk® ImageModeler™
|
|
Autodesk® Sketchbook® Pro
|
|
Autodesk® Smoke on Mac®
|
|
theBits = #{2,3,4,5,6,7} theArr = theBits as array newBits = #{} --Increase each value in theArr by +1 which results in
newBits = #{3,4,5,6,7,8}
I want to take a bitArray and count up and then apply those values to a new bitArray
Max 4 - 2012
Nvidia Quadro FX 3500
Duel Intel(R) Xeon(R) CPU X5355 2.66GHz, 8Gb Ram, DX9.0c.
Windows 7 64bit Operating System
|
|
|
|
I have to ask - what are you trying to achieve here? A bitArray is an array of true/false values where the index of the value is (generally) more important than the value at that index, whereas a normal array is just a list of values where the value at a specific index is (generally) more important than the index which points to it.
All your code will result in is a bitArray where index 2 is false (where it was originally true) and index 8 (which didn’t previously exist) is true.
Max 4.2 through 2013.
XP-64 (SP2)
NVidia 9800GTX-512 (Driver 266.58).
Core 2 Quad Q6600 2.4GHz, 8Gb Ram, DX9.0c.
|
|
|
|
Using maxscript I’ve made a multilistview and I want the selection to update when the users hit the Up arrow. As of right now it does not move the selection with the change.
So the question was to help solve that problem.
You can test it out to better understand what I mean. As for the down arrow that has not been updated yet. So just test using the up arrow.
Thanks Steve.
(
local AnimObjs = #()
rollout rlD ""
(
multiListBox lbxAnimatedObjects "Animated Objects" pos:[10,7] width:120 height:12
button btnAddAnimObj "+" pos:[10,185] width:24 height:24
button btnRemoveAnimObjs "-" pos:[34,185] width:24 height:24
button btnClearAnimObjs "X" pos:[58,185] width:24 height:24
button btnMoveUpAnimObj"^" pos:[82,185] width:24 height:24
button btnMoveDownAnimObj "v" pos:[106,185] width:24 height:24
on lbxAnimatedObjects rightclick do lbxAnimatedObjects.selection = #{}
on btnAddAnimObj pressed do -- Add Objects
(
userSel = getCurrentSelection()
if userSel.count >= 1 do
(
for o in userSel do (appendIfUnique AnimObjs o)
lbxAnimatedObjects.items = for i in AnimObjs collect i.name -- update list with array
)
)
on btnRemoveAnimObjs pressed do -- Removes Object fromt list
(
local currSel = lbxAnimatedObjects.selection
for i = lbxAnimatedObjects.items.count to 1 by -1 where currSel[i] do (deleteItem AnimObjs i)
lbxAnimatedObjects.items = for i in AnimObjs collect i.name -- update list with array
)
on btnMoveUpAnimObj pressed do
(
local itm = lbxAnimatedObjects.selection as array
if itm.count == 0 then print "Nothing is selected" else
(
for i = 1 to itm.count do
(
itmNum = itm[i] as integer
swap AnimObjs[itmNum] AnimObjs[itmNum-1]
lbxAnimatedObjects.items = for i in AnimObjs collect i.name -- update list with array
)
)
)
on btnMoveDownAnimObj pressed do
(
local itm = lbxAnimatedObjects.selection
if itm < lbxAnimatedObjects.items.count do
(
swap lbxAnimatedObjects.items[itm] lbxAnimatedObjects.items[itm+1]
lbxAnimatedObjects.items = lbxAnimatedObjects.items
swap AnimObjs[itm] AnimObjs[itm+1]
lbxAnimatedObjects.selection += 1
)
print AnimObjs
)
on btnClearAnimObjs pressed do lbxAnimatedObjects.items = (AnimObjs=#()) -- Clear List
)
createDialog rlD 140 225 )
Max 4 - 2012
Nvidia Quadro FX 3500
Duel Intel(R) Xeon(R) CPU X5355 2.66GHz, 8Gb Ram, DX9.0c.
Windows 7 64bit Operating System
|
|
|
|
You like opening cans of worms, don’t you :P
This is a minefield, because you have to try and account for every stupid thing a user may try and do - and believe me they will.
For example, select only the top item and click “Up"… (maxscript exception)
Select the top 2 items. Top one can’t move up because there’s nowhere for it to go. Second one could, but that would move the top one down, so the 2nd one down can only move up if the top one is not selected, otherwise it can’t move either.
I think that maybe a different approach is called for here - I’ll have a play over the weekend, bit busy today.
Max 4.2 through 2013.
XP-64 (SP2)
NVidia 9800GTX-512 (Driver 266.58).
Core 2 Quad Q6600 2.4GHz, 8Gb Ram, DX9.0c.
|
|
|
|
This could get you started:
fn changeIndex i count dir =
(
if (i == 1 AND dir == -1) then count
else if (i == count AND dir == 1) then 1
else i + dir )
on btnMoveUpAnimObj pressed do
(
local selectedItems = lbxAnimatedObjects.selection
local newSelection = #{} -- our new selection
local newItems = #()
newItems[selectedItems.count] = undefined -- fill the array with undefined vals
if selectedItems.isEmpty then messageBox "Nothing is selected"
else
(
for oldIndex in selectedItems do
(
local newIndex = changeIndex oldIndex selectedItems.count -1
newItems[newIndex] = AnimObjs[oldIndex] -- put object to its new location
newSelection[newIndex] = true -- this item will be selected
)
nonSelectedItems = -selectedItems -- get inverse of the selection
for i in nonSelectedItems do
newItems[findItem newItems undefined] = AnimObjs[i] -- replace empty items
AnimObjs = newItems
lbxAnimatedObjects.items = for i in AnimObjs collect i.name
lbxAnimatedObjects.selection = newSelection
)
)
It’s a bit rough around the edges as it’s more a proof of a concept (it would make more sense to make a function of it to be used also in the btnMoveDownAnimObj pressed event) but it works. Basically it goes through selected items and puts them in new positions in an array and then it fills the empty spaces in the array with leftover items. The changeIndex function can be used to change indices in the other direction as well, just pass it 1 as dir. The tompost item will move to the end of the list if selected, which to me feels quite natural (and makes moving things down easier than having to move them down the whole list).
Vojtech Cada
Max 6 - 2012
Blog :: LinkedIn profile
|
|
|
|
This, I think, does what you want, though as always with such things you need to test carefully, with lots of different selections, that it continues to do what is expected of it and that you can’t “crash” it no matter what you do.
on btnMoveUpAnimObj pressed do
(
local itm = lbxAnimatedObjects.selection
if itm.count == 0 then print "Nothing is selected" else
(
for t = 2 to itm.count do
(
if (itm[t] and not itm[t-1]) then
(
swap animObjs[t] animObjs[t-1]
deleteItem itm t
append itm (t-1)
)
)
lbxAnimatedObjects.items = for i in AnimObjs collect i.name -- update list with array
lbxAnimatedObjects.selection = itm
)
)
Max 4.2 through 2013.
XP-64 (SP2)
NVidia 9800GTX-512 (Driver 266.58).
Core 2 Quad Q6600 2.4GHz, 8Gb Ram, DX9.0c.
|
|
|
|
Thank you Steve for helping out on this and coming up with a solution. I’ll be sure to test this out and see what it does. I wish it was a simpler thing to do by default. Oh well I guess.
Great stuff.
Thanks
John
Max 4 - 2012
Nvidia Quadro FX 3500
Duel Intel(R) Xeon(R) CPU X5355 2.66GHz, 8Gb Ram, DX9.0c.
Windows 7 64bit Operating System
|
|
|
|
Just realised there is a potential problem if there is only 1 item in the list (can’t really go anywhere, can it?) - the loop starts from index 2 which wouldn’t exist - script error…
I would probably add an “on <listbox> selected” event which tested both the number of items in the list and the number selected. If there’s nothing selected, or the selection count = the item count (which covers the case of there being only 1 item), then disable the up/down buttons, else enable them. This would remove the need for the “if itm.count == 0” test because the button can’t be clicked in the first place.
Max 4.2 through 2013.
XP-64 (SP2)
NVidia 9800GTX-512 (Driver 266.58).
Core 2 Quad Q6600 2.4GHz, 8Gb Ram, DX9.0c.
|
|
|
|
Latest version - includes the btnDown processing and the enabling/disabling of the up/down buttons.
Max 4.2 through 2013.
XP-64 (SP2)
NVidia 9800GTX-512 (Driver 266.58).
Core 2 Quad Q6600 2.4GHz, 8Gb Ram, DX9.0c.
|
|
|
|
Great. This could work better. Thank you Steve for all the time you spent developing this and getting it to work. I would have never expected it to be such as much of a task as it was. I will greatly help what I am working on. Thanks again for the help.
I’ll be sure to let you know how things go with it.
Thanks
JokerMartini
Max 4 - 2012
Nvidia Quadro FX 3500
Duel Intel(R) Xeon(R) CPU X5355 2.66GHz, 8Gb Ram, DX9.0c.
Windows 7 64bit Operating System
|
|
|
|
|
Please do - always nice to see the finished result of something to which you have contributed, even in a small way :)
Author: Steve_Curley
|
| Replied: 23 May 2011 04:08 AM
|
|
|
|
|