January 28, 2012

dotNet Treeview MultiSelect for MaxScript

Recently I've been working on a MaxScript project that required a dotNet Treeview and the ability to select multiple items. I was really troubled that the default treeview doesn't support multiselect, only ancient looking check boxes. However, I was happy to find that someone else bumped into this problem and made their solution available. Unfortunately, there were no example on how to use it with MaxScript. Here's how to get it working:


  • Step 1 is to download the DLL control from here: http://sourceforge.net/projects/mulsel-treeview/
  • Step 2 is to unzip the DLL to a folder you can remember easily. I chose the UserMacro folder. You can get to it quickly by typing the following into the MaxScript Listener:
shelllaunch "$usermacros" ""
  • Step 3 is to remove the periods from the file name of the DLL or Max won't load it.
  • Step 4 below is an example how to load and use the plugin with MaxScript.



--LOAD THE CUSTOM PLUGIN FIRST
--NOTE THAT THERE ARE NO PERIODS IN THE FILE NAME OF THE DLL
dotnet.loadAssembly ((pathConfig.normalizepath "$usermacros") + "CodersLabWindowsControlsTreeView.dll")

--BASIC MAXSCRIPT ROLLOUT
rollout TreeViewMultiSelect "MultiSelect" width:300 height:200
(
   --THIS IS A BASIC DOTNET TREE VIEW CONTROL
   --dotNetControl tv "system.windows.forms.treeView" height:200 width:300
 
   --USE THIS INSTEAD AFTER YOU INSTALL THE DLL
   dotNetControl treeviewObjectList "CodersLab.Windows.Controls.treeView" height:192 width:292 pos:[4,4]
 
   on TreeViewMultiSelect open do
   (     
       --THIS TELLS THE TREEVIEW TO ENABLE MULTISELECT
       ms = (dotnetclass "CodersLab.Windows.Controls.TreeViewSelectionMode")
       treeviewObjectList.SelectionMode = ms.MultiSelect
     
       --HERE ARE THE OTHER MODES AVAILABLE:
--               .MultiSelect
--               .MultiSelectSameLevel
--               .MultiSelectSameLevelAndRootBranch
--               .MultiSelectSameParent
--               .MultiSelectSameRootBranch
--               .SingleSelect
     
       --LETS ADD SOME NODES TO THE TREE VIEW
       for obj in objects do
       (
           --CREATE A NEW DOTNET TREE NODE
           newNode = (dotNetObject "System.Windows.Forms.TreeNode" obj.name)
         
           --ADD IT TO THE TREEVIEW
           treeviewObjectList.nodes.add newNode
       )
   )
)
--OPEN THE ROLLOUT AS A DIALOG
createDialog TreeViewMultiSelect

  • Step 5 proof that it works!

The only issue I bumped into after replacing the default treeview is that the selectedNode property no longer seems to work. But I replaced it with selectedNodes.item[0]. Note the S in selectedNodes. Leave a comment if this helped!




Post a Comment