Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk 3ds® Max® / MaxScript / BitArray - Count up?
  RSS 2.0 ATOM  

BitArray - Count up?
Rate this thread
 
56005
 
Permlink of this thread  
avatar
  • Total Posts: 114
  • Joined: 18 June 2009 01:05 AM

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

Replies: 0
avatar
  • Location: West Midlands, England, UK
  • Total Posts: 14445
  • Joined: 06 August 2007 11:06 PM
  • Permlink of this post

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.

Replies: 0
avatar

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 >= 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 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 
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

Replies: 0
avatar
  • Location: West Midlands, England, UK
  • Total Posts: 14445
  • Joined: 06 August 2007 11:06 PM
  • Permlink of this post

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.

Replies: 0
avatar

This could get you started:

fn changeIndex i count dir =
(
 if (
== AND dir == -1then count
 
else if (== count AND dir == 1then 1
 
else 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

Replies: 0
avatar
  • Location: West Midlands, England, UK
  • Total Posts: 14445
  • Joined: 06 August 2007 11:06 PM
  • Permlink of this post

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 
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.

Replies: 0
avatar

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

Replies: 0
avatar
  • Location: West Midlands, England, UK
  • Total Posts: 14445
  • Joined: 06 August 2007 11:06 PM
  • Permlink of this post

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.

Replies: 0
avatar
  • Location: West Midlands, England, UK
  • Total Posts: 14445
  • Joined: 06 August 2007 11:06 PM
  • Permlink of this post

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.

Attachment Attachment
Replies: 0
avatar

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

Replies: 1
/img/forum/dark/default_avatar.png

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