Notifications
Clear all

[Closed] No "select" fnc for undefined in listbox

I’m having a weird problem when working with a list. What I have planned is, that the user is able to create new materials where name and diffuse color values are stored in a list.
Afterwards, the user can then just select objects and assign the currently selected material from the listbox to the viewport object selection.

I can already create materials (at the same time for debug purpose it just also assigns the material righ away on the selected object upon material creation), but as soon as I want to select a different material from the listbox, I get this error:

Spoiler

-- MAXScript Rollout Handler Exception:
-- No ""select"" function for undefined
-- MAXScript callstack:
--   thread data: threadID:18024
--   ------------------------------------------------------
--   [stack level: 0]
--   In s3d_LBX_IDMaterialList.selected(); filename: [pathtofile]\ListboxTest.ms; position: 1457; line: 46
--   member of: Rollout:s3d_MATERIALTEST
--      Parameters:
--         nameIndex: 1
--      Locals:
--         nameIndex: 1
--      Externals:
--         s3d_LBX_IDMaterialList: RolloutControl:s3d_LBX_IDMaterialList in rollout:s3d_MATERIALTEST : ListBoxControl:s3d_LBX_IDMaterialList
--         s3d_MATERIALTEST: Rollout:s3d_MATERIALTEST
--         owner: Rollout:s3d_MATERIALTEST
--   ------------------------------------------------------
--   [stack level: 1]
--   called from top-level


I do think I know why this is as the material itself is not a propper node (please correct me here if I’m wrong). If I assign objects to the list and select those, it works. So I guess the issue lies somewhere here:


on s3d_LBX_IDMaterialList selected nameIndex do
   (
      select (getNodeByName s3d_LBX_IDMaterialList.items[nameIndex])
   )

So – How can I fix this? Any help is very appreciated!

Thanks

Full code:

Spoiler


try(destroydialog ::s3d_MATERIALTEST)catch()
ClearListener()
--global ColorIDArray = #(#(),#())
 rollout s3d_MATERIALTEST "" width:200 height:400
 (
   button s3d_BTN_SwitchToIDMat "Switch to ColorID"  height: 45
    listbox s3d_LBX_IDMaterialList "Color ID Materials:" 
   colorPicker s3d_CPL_ColorID "Color ID"  align:#center color:(color 0 0 0) alpha:false
   edittext s3d_EDT_ColorIDName "ColorID Material Name"  labelOnTop:true text:""
   button s3d_BTN_CreateIDMaterial "Create ColorID Material"  width:150
    button s3d_BTN_RemoveIDMaterial "Remove ColorID Material" width:150
   button s3d_BTN_SaveAllMaterials "Save All Materials To Disk" width:150 height:45
    fn s3d_fn_AddMaterialToList mat =
    (
      
    )
    fn s3d_fn_DeleteMaterialFromList  mat =
    (
       if not mat.selection.isEmpty do
       (
         
       )
    )
   on s3d_BTN_CreateIDMaterial pressed do
   (
      tempColorIDMaterial = standardMaterial name:s3d_EDT_ColorIDName.text diffuse:s3d_CPL_ColorID.color
      newIDColor = tempColorIDMaterial.name+", "+ s3d_CPL_ColorID.color as string      
      s3d_LBX_IDMaterialList.items = append(s3d_LBX_IDMaterialList.items) (newIDColor)      
      
      for j in selection do
      (
         j.material = tempColorIDMaterial
      )      
         
   )
    --on s3d_BTN_RemoveIDMaterial pressed do s3d_fn_DeleteMaterialFromList s3d_LBX_IDMaterialList
   
   on s3d_LBX_IDMaterialList selected nameIndex do
   (
      select (getNodeByName s3d_LBX_IDMaterialList.items[nameIndex])
   )
 )
 createDialog s3d_MATERIALTEST

2 Replies

Here’s another way to try it out. The only difference in both is how the item array of the listbox is filled – one time with the names of the objects, and the other time with the names of their materials.

This works:


ClearListener()
rollout objectKiller "Object Killer"
(
   listbox objectToKill "Objects:" items:(for o in objects collect o.name)
   on objectToKill selected nameIndex do
   (
      select (getNodeByName objectToKill.items[nameIndex])
      print objectToKill.items[nameIndex]
   )
)
createDialog objectKiller--create a dialog from the rolloutParameters

This doesn’t work.


ClearListener()
rollout objectKiller "Object Killer"
(
   listbox objectToKill "Objects:" items:(for o in objects collect o.material as string)
   on objectToKill selected nameIndex do
   (
      select (getNodeByName objectToKill.items[nameIndex])
      print objectToKill.items[nameIndex]
   )
)
createDialog objectKiller--create a dialog from the rolloutParameters

D’oh… Isn’t it nice when you can answer your own questi0n?

Anyway, it was sort of my own problem and a friend of mine pointed me in the right direction:
getNodeByName looks for nodes, and as my materials arent connected to any node they cant find it.

So instead i just took out the whole line, working with listbox.selection now and that works fine.