dotNet + MXS


#361

Hi,all.

I’m a new dotnet studente. there have a code that I test for getting a material.

but, there have a problem… just the button that you click first time can working… then other buttons cant working… I dont know why… Pls help me to have a look, thank you very much…

Note: you must load the materior… in my code, I load D:\1.mat…


fn PicBClick sender e = 
(
sender.BackColor =(DotNetClass "System.Drawing.Color").fromARGB 180 180 180
[color=lime]ml=loadTempMaterialLibrary"D:\1.mat"
setMeditMaterial activeMeditSlot ml[1]
[/color])
rollout materialib_rollout "test-25" width:650 height:412
(
dotNetControl FLP "System.Windows.Forms.FlowLayoutPanel" pos:[185,16] width:430 height:359
 
on materialib_rollout open do
( 
FLP.controls.clear()
for k =1 to 10 do 
(
buttonT =dotNetobject "System.Windows.Forms.Button"
buttonT.text = ("NO" +k as string ) 
dotnet.addeventhandler buttonT "Click" PicBClick
FLP.Controls.Add(buttonT) 
)
)
)
createdialog materialib_rollout
 


#362

It seems like everything works right. Check my a bit cleaned version (I didn’t change any basic things in your code):


try(destroydialog materialib_rollout) catch()
rollout materialib_rollout "test-25" width:650 height:412
(
dotNetControl FLP "System.Windows.Forms.FlowLayoutPanel" pos:[185,16] width:430 height:359
fn onClick sender arg = 
(
sender.BackColor =(DotNetClass "System.Drawing.Color").fromARGB 180 180 180
format "% \"%\"
" sender.tag sender.text
)
 
on materialib_rollout open do
( 
FLP.controls.clear()
for k=1 to 10 do 
(
bt = dotNetobject "System.Windows.Forms.Button"
bt.text = ("N " + k as string)
bt.tag = k 
dotnet.addeventhandler bt "Click" onClick
FLP.Controls.Add bt 
)
)
)
createdialog materialib_rollout
 

what do you want to get? Do you want to load material using button index? I added tag to every button which you can use as button’s index.


#363

Hi,denisT

Do you want to load material using button index?
-----------yes, that’s I want…

so I use :

ml=loadTempMaterialLibrary"D:\1.mat"
setMeditMaterial activeMeditSlot ml[1]

to get the materail… if delete this 2 row code. then the script run well. but, if I add this , then cant work…


#364

but you don’t need to load a library on every button click. Load it on rollout open e.g.


#365

Mike, I see your know TreeList pretty well. Is it possible to do multiple selection just dragging mouse (same way as in ListView e.g.)? … without using CTRL and SHIFT… Also deselect with ALT doesn’t work for me. Is it a feature or I’m doing anything wrong?


#366

Hi,denisT

pls try this code…


global  mats
try(destroydialog materialib_rollout) catch()
rollout materialib_rollout "test-25" width:650 height:412
(
dotNetControl FLP "System.Windows.Forms.FlowLayoutPanel" pos:[185,16] width:430 height:359
fn onClick sender arg = 
(
sender.BackColor =(DotNetClass "System.Drawing.Color").fromARGB 180 180 180
ml=loadTempMaterialLibrary mats[sender.tag]
setMeditMaterial activeMeditSlot ml[1]
)
 
on materialib_rollout open do
( 
FLP.controls.clear()
mats=getFiles ("F:\mymats"+"[\\*.mat](file://\*.mat)")
if mats.count >0 then 
for k=1 to mats.count do 
(
bt = dotNetobject "System.Windows.Forms.Button"
bt.text = ("N " + k as string)
bt.tag = k 
dotnet.addeventhandler bt "Click" onClick
FLP.Controls.Add bt 
)
else (messagebox "no mats in F:\mymats")
)
)
createdialog materialib_rollout


#367

zhouhouyu,

Please start new thread for your problem. This is not right place for your post. This thread is focused on dotNet (techniques, solutions, tricks, etc. which can be discussed). Your case is a simple bug not related to dotNet at all…


#368

zhouhouyu,

Please start new thread for your problem. This is not right place for your post. This thread is focused on dotNet (techniques, solutions, tricks, etc. which can be discussed). Your case is a simple bug not related to dotNet at all…

sorry,I dont know whether I can post there… I just think this is becuase of the dotnet sender event make the loadTempMaterialLibrary cant work well. so I put there…

Ok. I will delete my post. and start new thread … thank you for your help, denisT!


#369

Yeah, it’s a pretty sweet control.

I did search of these forums and there was already another reference to it.

http://forums.cgsociety.org/showthread.php?t=778244

If you aren’t familiare with DevExpress components, docs are available at:

http://www.devexpress.com/Help/?document=XtraTreeList

It only became useful in 2009, when the .NET type casting was improved. I’m not sure about the multi-select you wanted to use. I’ll have to poke around with it.

.biddle


#370

I knew about DevExpress things but I didn’t have time to really play with them in MAX. Thanks again.


#371

Here is snippet that shows how you can hook up item editors for column data in an XtraTreeList, I’m using something similar in a front end for an exporter. It allows me to display, select, and edit which bits and pieces need to be included for each LOD.

This sample is deliberately too narrow to show off how you can fix columns on the left/right.

I’ve only tested it in Max2010, it should run in 2009 too.

	rollout tltest "XtraTreeList Test" width: 300 height: 200
      	(
      		dotNetControl tl "DevExpress.XtraTreeList.TreeList" width: 274 height: 180
      		
      		on tltest open do
      		(
      			-- Set up the treelist 
      			
      			tl.OptionsSelection.MultiSelect = True
      			tl.OptionsView.ShowRoot =true
      			tl.OptionsView.ShowIndicator = false
      			tl.OptionsView.AutoWidth = false
      			
      			tl.BeginUpdate();
      			
      			-- Fixed the first column to the left. this is the column that contains the indented tree nodes
      			col = tl.Columns.Add()
      			col.visible = true
      			tl.Columns.item[0].Fixed = tl.Columns.item[0].Fixed.Left
      			
      			-- Set up the 2nd column with a combo box editor
      			col = tl.Columns.Add()
      			col.visible = true
      			riCombo = dotnetobject "DevExpress.XtraEditors.Repository.RepositoryItemComboBox"
      			riCombo.Items.AddRange #("lantern", "angel", "hat", "dog"  )
      			tl.RepositoryItems.Add riCombo
      			col.ColumnEdit =  riCombo  
      			
      			-- Set up the 3rd column with a spin editor
      			col = tl.Columns.Add()
      			col.visible = true
      			riSpin = dotnetobject "DevExpress.XtraEditors.Repository.RepositoryItemSpinEdit"
      			tl.RepositoryItems.Add riSpin
      			col.ColumnEdit =  riSpin
      		
      			col = tl.Columns.Add()
      			col.visible = true
      			
      			-- The 3 columns fixed to the right are all checkboxes
      			riCheck = dotnetobject "DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit"
      			tl.RepositoryItems.Add riCheck
      			for  i = 2 to 0 by -1 do 
      			(
      				col = tl.Columns.Add()
      				col.visible = true
      				col.caption =  (i as string)
      				col.ColumnEdit =  riCheck
      				col.Width = 5
      				col.Fixed = col.Fixed.Right
      			)
      			
      			tl.EndUpdate()
      			   
      			tl.BeginUnboundLoad()
      			
      			-- Four root level nodes 
      			n0 = tl.AppendNode #("green","lantern" ,0, "dog", false, true, false)  -1
      			n1 = tl.AppendNode #("blue", "angel"	,1, "rat", false, true, true)  -1
      			n2 = tl.AppendNode #("blue", "moon"	,2 , "hawk", false, true, true)  -1
      			n3 = tl.AppendNode #("blue", "mood"	,1, "horse", false, true, true)  -1
      			
      			-- Four child nodes
      			n00 = tl.AppendNode #("red", "hat"		,5, "turtle",false, false, true) n0		
      			n10 = tl.AppendNode #("yellow", "dog"	,3, "gull", true, false, true) n1		
      			n20 = tl.AppendNode #("red", "menace"   ,6, "fish",false, false, true) n2		
      			n30 = tl.AppendNode #("yellow", "streak"	,4, "rock", true, false, true) n3		
      			tl.EndUnboundLoad()
      			
      		
      		)
      			
      	)
      	
      	createdialog tltest
      
      

#372

Nice snippet. Thank you, Mike for the keeping up my interest in XtraTreeList. :slight_smile:

Is any way to have different editors in the same column?


#373
       Yes, you can have per item (aka node) editors:
       
       [http://www.devexpress.com/Help/?document=XtraTreeList/CustomDocument5633.htm](http://www.devexpress.com/Help/?document=XtraTreeList/CustomDocument5633.htm)
       
     <Sorry for the extra spaces in the following snippet>

       rollout tltest "XtraTreeList Test" width: 300 height: 200
 (
 	   
 	   dotNetControl tl "DevExpress.XtraTreeList.TreeList" width: 274 height: 180
    
 	-- NOTE: I've split these long class strings because the CGTalk forums was inserting spaces...
 	local clsComboBox = dotNetClass ("DevExpress.XtraEditors.Repository."+"RepositoryItemComboBox")	   
 	local clsSpinEdit = dotNetClass ("DevExpress.XtraEditors.Repository."+"RepositoryItemSpinEdit")	   
 	local clsCheckEdit = dotNetClass ("DevExpress.XtraEditors.Repository."+"RepositoryItemCheckEdit")  
 	   
 	   -- Declare some custom editors for the CustomNodeCellEdit event
 	   local riCustOdd = dotnetobject clsComboBox
 	   local  riCustEven = dotnetobject clsComboBox
 	 
 	   on tltest open do
 	   (
 		   -- Set up the treelist			   
 		   tl.OptionsSelection.MultiSelect = True
 		   tl.OptionsView.ShowRoot =true
 		   tl.OptionsView.ShowIndicator = false
 		   tl.OptionsView.AutoWidth = false
    
 		   tl.BeginUpdate();
    
 		   -- Fixed the first column to the left. this is the column that contains the indented tree nodes
 		   col = tl.Columns.Add()
 		   col.visible = true
 		   tl.Columns.item[0].Fixed = tl.Columns.item[0].Fixed.Left
    
 		   -- Set up the 2nd column with a combo box editor
 		   col = tl.Columns.Add()
 		   col.visible = true
 		   riCombo = dotnetobject clsComboBox
 		   riCombo.Items.AddRange #("lantern", "angel", "hat", "dog"  )
 		   tl.RepositoryItems.Add riCombo
 		   col.ColumnEdit =  riCombo  
    
 		   -- Set up the 3rd column with a spin editor
 		   col = tl.Columns.Add()
 		   col.visible = true
 		   riSpin = dotnetobject clsSpinEdit
 		   tl.RepositoryItems.Add riSpin
 		   col.ColumnEdit =  riSpin
 			 col.Caption = "Custom Edit"
    
 		   col = tl.Columns.Add()
 		   col.visible = true
    
 		   -- The 3 columns fixed to the right are all checkboxes
 		   riCheck = dotnetobject clsCheckEdit
 		   tl.RepositoryItems.Add riCheck
 		   for  i = 2 to 0 by -1 do 
 		   (
 			   col = tl.Columns.Add()
 			   col.visible = true
 			   col.caption =  (i as string)
 			   col.ColumnEdit =  riCheck
 			   col.Width = 5
 			   col.Fixed = col.Fixed.Right
 		   )
    
 		   tl.EndUpdate()
 			
 		   tl.BeginUnboundLoad()
    
 		   -- Four root level nodes 
 		   n0 = tl.AppendNode #("green","lantern" ,0, "dog", false, true, false)  -1
 		   n1 = tl.AppendNode #("blue", "angel"	,1, "rat", false, true, true)  -1
 		   n2 = tl.AppendNode #("blue", "moon"	,2 , "hawk", false, true, true)  -1
 		   n3 = tl.AppendNode #("blue", "mood"	,1, "horse", false, true, true)  -1
    
 		   -- Four child nodes
 		   n00 = tl.AppendNode #("red", "hat"		,5, "turtle",false, false, true) n0		
 		   n10 = tl.AppendNode #("yellow", "dog"	,3, "gull", true, false, true) n1		
 		   n20 = tl.AppendNode #("red", "menace"   ,6, "fish",false, false, true) n2		
 		   n30 = tl.AppendNode #("yellow", "streak"	,4, "rock", true, false, true) n3		
 		   tl.EndUnboundLoad()
    
 		   -- Fill out the item editors used to handle 
 		   riCustEven.Items.AddRange #("111", "222", "333", "444"  )
 		   riCustOdd.Items.AddRange #("AAA", "BBB", "CCC", "DDD"  )
 	  
 	   )
 	
 	   on tl CustomNodeCellEdit sender evt do
 	   (
 		   -- Use a custom editor the 3rd column, alternating editors based on node id
 		   -- Notice how the editor follows the node when you sort the column 
 		   if (evt.column.AbsoluteIndex == 2) do
 		   (
 			   evt.RepositoryItem = if mod evt.node.id 2 == 0 then riCustEven else riCustOdd
 		   )
 	   )		
 )
    
 createdialog tltest
 
       Imagine what you can do with a dynamically constructed per-node-popup-container-editor!
       
       [http://www.devexpress.com/Help/?document=XtraEditors/clsDevExpressXtraEditorsPopupContainerEdittopic.htm](http://www.devexpress.com/Help/?document=XtraEditors/clsDevExpressXtraEditorsPopupContainerEdittopic.htm)
     
     .biddle

EDIT: I just noticed that the custom editor follows the column as you drag a header around to reorder columns. Which is just what you'd expect of course since I was already testing the columns absoluteindex -- but it's cool to see it work properly right out of the can. Ya gotta love this control :)

EDIT #2: Split up the long strings in the snippet so that extra spaces wouldn’t get inserted by the code foramatter


#374

To get that script to work does something have to be purchased?


#375

I didn’t need any license key to use it through maxscript.

Max itself loads (and presumably unlocks) the assembly.

I guess it a “try it and see” situation. Let me know if it doesn’t run for you.


#376

PEN

the code has extra spaces … remove them and it will work

biddle

thanks mate , Extra Cool !


#377

Wow that is great, good find. Thanks for the heads up Cyfer. I’m just about to do a major tool in dot net and was looking at using dataGridView but I’m thinking that I could use some of what this has to beef it up.


#378

hey guys, i did a treeVieew and for the nodes i have simple functions like :
Add/Remove/ExpandAll/CollapseAll/Rename

since i´m not 100% familiar with dotNET yet, i don´t know how to :

1- sort all items and its properties (Relative to the TreeView), e.g

 
Total_Items= 20 
 
Item_Name= "foo"
Item_Index = 2

2- dynamically create arrays and append nodes (i´m using string values for this case, no objects) into it based on their treeView hirarchies, eg (see also screen attached)

 
root = #(root)
one = #(a,b,c,f)
two = #(d,e,g,h)
three = #(i,j)

any ideas ?
thanks in advance


#379

if you want to use addRange you have to add a collection of Tree Nodes:


try(destroydialog treeRol) catch()
rollout treeRol "Tree View" 
(
dotNetControl tv "TreeView" width:190 height:190 pos:[4,4]
 
local root = "root"
local a = "a", b = "b", c = "c", d = "d", e = "e", f = "f", g = "g", h = "h", i = "i", j = "j"
fn initTreeView =
(
root = #(root)
one = #(a,b,c,f)
two = #(d,e)
three = #(g,h)
four = #(i,j)
 
roots = for n in root collect (dotNetObject "TreeNode" n)
 
ones = for n in one collect (dotNetObject "TreeNode" n)
roots[1].nodes.addRange ones
twos = for n in two collect (dotNetObject "TreeNode" n)
ones[3].nodes.addRange twos
threes = for n in three collect (dotNetObject "TreeNode" n)
ones[4].nodes.addRange threes
fours = for n in four collect (dotNetObject "TreeNode" n)
threes[2].nodes.addRange fours
 
n = tv.nodes.addRange roots
)
 
on treeRol open do 
(
tv.beginUpdate()
initTreeView()
tv.expandAll()
tv.endUpdate()
)
)
createdialog treeRol width:200 height:200 


#380

thanks for your input denisT, but i´m still lost… take a look what i have so far :

 try(destroydialog treeRol) catch() 
 rollout treeRol "Tree View" 
 (
 dotNetControl tv "TreeView" width:190 height:190 pos:[4,4]
  
 ------HERE IS THE ARRAY I WANT TO PUT ALL THE TREENODES NAME -------------
 local hierarchy_ARRAY = #() 
  
  
 fn populateTreeView theTv =
 (
 --dotNET Tree View nodes
 a = (dotNetObject "System.Windows.Forms.TreeNode" "root")
 theTv.nodes.add a
  
 b = (dotNetObject "System.Windows.Forms.TreeNode" "a")
 a.nodes.add b
  
 	b_1 = (dotNetObject "System.Windows.Forms.TreeNode" "b")
 	b.nodes.add b_1
  
 	b_2 = (dotNetObject "System.Windows.Forms.TreeNode" "c")
 	b.nodes.add b_2
  
 c = (dotNetObject "System.Windows.Forms.TreeNode" "d")
 a.nodes.add c
  
 	f_1 = (dotNetObject "System.Windows.Forms.TreeNode" "e")
 	c.nodes.add f_1
  
 g = (dotNetObject "System.Windows.Forms.TreeNode" "f")
 a.nodes.add g
  
 	g_1 = (dotNetObject "System.Windows.Forms.TreeNode" "g")
 	g.nodes.add g_1
  
 	 g_01 = (dotNetObject "System.Windows.Forms.TreeNode" "h")
 	 g_1.nodes.add g_01
  
 	 g_02 = (dotNetObject "System.Windows.Forms.TreeNode" "i")
 	 g.nodes.add g_02
 )
  
 
 on treeRol open do 
 (
 tv.beginUpdate()
 populateTreeView tv
 tv.expandAll()
 tv.endUpdate()
 print (tv.GetNodeCount)
 format "% % % % 
" (tv.AutoSize = false) (tv.AllowDrop = false) (tv.ItemHeight = 19) (tv.ShowNodeToolTips = true)
 
 )
 )
 createdialog treeRol width:200 height:200 
 

i need a way to dinamically read all the treeView/treeNodes and append it to the hierarchy_ARRAY…

maybe a refresh function (clean the array and assign the nodes) by a button handler, so i always have the ability to manager a free-form based nodes…

i don´t know…
any ideas ?