Notifications
Clear all

[Closed] material import script – sample slot

here is a snippet … shows almost everything that you need…


 try(destroydialog matLibsDialog) catch()
 rollout matLibsDialog "Material Libraries" width:200
 (
 	local def_path = getdir #temp + @"	estmatlibs\"
 	
 	dotnetcontrol tv "TreeView" width:196 height:260 pos:[2,2]
 	button load_bt "Load..." width:63 across:3 align:#left offset:[-10,0,0]
 	button save_bt "Save" width:64 align:#right offset:[3,0,0]
 	button update_bt "Update" width:63 align:#right offset:[10,0,0]
 
 	fn loadLibs path:def_path = if doesfileexist path do
 	(
 		tv.nodes.clear()
 		
 		ff = getfiles (path + @"\*.mat")
 		for f in ff do
 		(
 			item = filenamefrompath f
 			node = tv.nodes.add item item
 			lib = loadTempMaterialLibrary f
 			node.tag = dotnetmxsvalue #(ff, lib)
 			for mat in lib do 
 			(
 				m = node.nodes.add mat.name mat.name 
 				m.tag = dotnetmxsvalue mat
 			)
 		)
 		tv.sorted = on		
 	)
 	on load_bt pressed do 
 	(
 		if (path = getsavepath()) != undefined do
 		(
 			def_path = path
 			loadLibs()
 		)
 	)
 	on update_bt pressed do loadLibs()
 	on save_bt pressed do
 	(
 		for k=0 to tv.nodes.count-1 where (i = tv.nodes.item[k]).isselected do saveTempMaterialLibrary i.tag.value[2] i.tag.value[1]
 	)
 	on tv NodeMouseDoubleClick s e do if (tag = e.node.tag) != undefined do
 	(
 		if iskindof tag.value Material do medit.PutMtlToMtlEditor tag.value (medit.GetActiveMtlSlot())
 	)
 	on matLibsDialog open do loadLibs path:def_path
 )
 createdialog matLibsDialog
 
 

use double-click to load a material in the active ME slot

2 Replies
(@ice-boy)
Joined: 1 year ago

Posts: 0

wooow. thanks.

you should realese this on scriptspot.

(@denist)
Joined: 1 year ago

Posts: 0

this is not my market.

Denis can you tell me why when you need to assigne some tag you always use dotnetmxsvalue.
Like in this line for mxs array

node.tag = dotnetmxsvalue #(ff, lib)

This works also

node.tag = #(ff, lib)

Edit: Let’s say I need to store all form controls in form tag.
Can I use simple

form.tag = #(netBtn1, netBtn2, netBtn3)
--or 
form.tag = dotnetmxsvalue  #(netBtn1, netBtn2, netBtn3)
4 Replies
(@denist)
Joined: 1 year ago

Posts: 0

the last has not to work.
the Tag property needs .net System.Object. there are some types that max automatically converts (float, integer, string, some arrays). but for most other types it needs a wrapper object… which is dotnetmxsvalue

(@gazybara)
Joined: 1 year ago

Posts: 0

And what with array of dotNetObjects ei.controls like buttons, labels etc.
Do we need to use dotnetmxsvalue for this?
For tool that I sended you last time in PM, I not used dotnetmxsvalue and it works fine

(@denist)
Joined: 1 year ago

Posts: 0

an array of .net objects is OK. as well as a n array of things that can be converted to .net objects


#(dotnetobject "button", dotnetobject "System.Int32" 2)  -- good
#(1, "test") -- good
#(1, scenematerials) -- not good
#(1, dotnetmxsvalue scenematerials) -- good again

(@gazybara)
Joined: 1 year ago

Posts: 0

Thanks Denis now is everything clear.

Page 2 / 2