CGTalk > Software Specific Forums > Autodesk 3ds max > 3dsMax SDK and MaxScript
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 11-13-2010, 10:17 AM   #1
elfin25
New Member
 
elfin25's Avatar
portfolio
Efim Armand
3d artist / compositor
Miami, United%2BStates
 
Join Date: Dec 2006
Posts: 19
Thumbs down multilistbox vs render elements problem

hello everyone, I'm asking for help again
i have a multilistbox collecting channels in render elements dialog as array items.
pressing the delete button with one item selected working fine, but 2 or more selected items don't work correctly. it deletes every second render element of multilistbox selection . here's the code
Code:
( local re = maxOps.GetCurRenderElementMgr() local elementlist = #(VRay_Atmosphere,VRay_Background,VRay_BumpNormals ,VRay_Caustics,VRay_DiffuseFilter, \ VRay_GlobalIllumination,VRay_Lighting,VRay_MatteSh adow,VRay_Normals,VRay_Reflection, \ VRay_ReflectionFilter,VRay_Refraction,VRay_Refract ionFilter,VRay_SelfIllumination,VRay_Specular,VRay _MtlID, \ VRay_ObjectID,VRay_RenderID, VRay_WireColor) local theManager = maxOps.GetRenderElementMgr #Production local els = #() fn renderElementsList = ( for y = 0 to (theManager.numrenderelements() - 1) do ( el = re.getrenderelement y append els (el.elementname as string) ) ) rollout renderElements "Render Elements" width:184 height:408 ( button elem_add "Add" pos:[8,8] width:56 height:24 button elem_del "Delete" pos:[64,8] width:56 height:24 button elem_clear "Clear" pos:[120,8] width:56 height:24 multilistbox elem_list "" pos:[8,40] width:168 height:25 button elem_ok "OK" pos:[8,376] width:84 height:24 button elem_cancel "Cancel" pos:[92,376] width:84 height:24 on renderElements open do ( els = #() renderElementsList() elem_list.items = els ) on elem_add pressed do ( re.removeallrenderelements() setsilentmode true for n in elementlist do re.addrenderelement (n elementname:(n as string)) els = #() renderElementsList() elem_list.items = els ) on elem_del pressed do ( for i in elem_list.selection do ( delID = re.GetRenderElement (i-1) re.RemoveRenderElement delID ) elem_list.selection = #() els = #() renderElementsList() elem_list.items = els ) on elem_clear pressed do ( re.removeallrenderelements() re.SetElementsActive false els = #() renderElementsList() elem_list.items = els ) ) createdialog renderElements style:#(#style_toolwindow, #style_sysmenu) )
please help to solve this problem

Last edited by elfin25 : 11-13-2010 at 11:26 AM.
 
Old 11-13-2010, 01:00 PM   #2
JHN
maxscript/c# lover
 
JHN's Avatar
Johan Boekhoven
Technical Artist
nmtrix.com
Netherlands
 
Join Date: Apr 2002
Posts: 1,714
Try this
Code:
for i in elem_list.selection as array do ...etc...


Multilist box uses a bitarray value for the list. Convert it to array and it should work,

-Johan
__________________
Online: LinkedIn | blog | nmtrix.com
Code: mxs+.net | c# | mb-python | php | html+js | mysql | python
 
Old 11-13-2010, 01:09 PM   #3
elfin25
New Member
 
elfin25's Avatar
portfolio
Efim Armand
3d artist / compositor
Miami, United%2BStates
 
Join Date: Dec 2006
Posts: 19
Quote:
Originally Posted by JHN
Try this
Code:
for i in elem_list.selection as array do ...etc...


Multilist box uses a bitarray value for the list. Convert it to array and it should work,

-Johan



the problem hasn't gone
i select first 4 items (VRay_Atmosphere, VRay_Background, VRay_BumpNormals, VRay_Caustics), next item's name is VRay_DiffuseFilter (not currently selected). then click "delete" - VRay_Atmosphere and VRay_BumpNormals are gone, so do VRay_DiffuseFilter! but VRay_Background and VRay_Caustics stay in the list...

UPD and if i select all the items and delete them, only the half of list is gone.
here's the simplified example
Code:
( rollout unnamedRollout "Untitled" width:162 height:300 ( multilistBox lbx1 "ListBox" pos:[12,13] width:133 height:15 button btn1 "Button" pos:[13,250] width:132 height:30 on unnamedRollout open do lbx1.items = #("a1","a2","a3","a4","a5","a6","a7","a8","a9","a0") on btn1 pressed do ( for i in lbx1.selection as array do ( lbx1.items = deleteitem lbx1.items i ) lbx1.selection = #() ) ) createdialog unnamedRollout )

Last edited by elfin25 : 11-13-2010 at 05:29 PM.
 
Old 11-13-2010, 05:37 PM   #4
JHN
maxscript/c# lover
 
JHN's Avatar
Johan Boekhoven
Technical Artist
nmtrix.com
Netherlands
 
Join Date: Apr 2002
Posts: 1,714
You have to reverse delete the items as well. When you delete an item from an array from the beginning the array gets shorter. So the numbers in the higher parts won't match either.

Code:
fn reverse v1 v2 = if v1 > v2 then -1 else 1 local theitems = elem_list.selection as array qsort theItems reverse for i in theItems do ... etc.


Not behind max, so you have to check, but the principle is good, walk the array in reverse.

-Johan
__________________
Online: LinkedIn | blog | nmtrix.com
Code: mxs+.net | c# | mb-python | php | html+js | mysql | python
 
Old 11-13-2010, 06:29 PM   #5
elfin25
New Member
 
elfin25's Avatar
portfolio
Efim Armand
3d artist / compositor
Miami, United%2BStates
 
Join Date: Dec 2006
Posts: 19
Quote:
Originally Posted by JHN
You have to reverse delete the items as well. When you delete an item from an array from the beginning the array gets shorter. So the numbers in the higher parts won't match either.

Code:
fn reverse v1 v2 = if v1 > v2 then -1 else 1 local theitems = elem_list.selection as array qsort theItems reverse for i in theItems do ... etc.


Not behind max, so you have to check, but the principle is good, walk the array in reverse.

-Johan


great. thanks a lot!
here's the final example working code
Code:
( rollout unnamedRollout "Untitled" width:162 height:300 ( multilistBox lbx1 "ListBox" pos:[12,13] width:133 height:15 button btn1 "Button" pos:[13,250] width:132 height:30 on unnamedRollout open do lbx1.items = #("a1","a2","a3","a4","a5","a6","a7","a8","a9","a0") on btn1 pressed do ( fn fixItems v1 v2 = if v1 > v2 then -1 else 1 local theitems = lbx1.selection as array qsort theItems fixItems for i in theItems do ( fixItems i (i+1) lbx1.items = deleteitem lbx1.items i ) lbx1.selection = #() ) ) createdialog unnamedRollout )
 
Old 11-13-2010, 06:29 PM   #6
CGTalk Moderation
Lord of the posts
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,481
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 05:50 AM.


Powered by vBulletin
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.