Material Randomizer +

Everything here is working except for the Load and Append button.
I was hoping to get some additional help on here.
I want the Load option to essentialy load the Temporary Library into the Multilist and if users press Append it will allow users to load in/add additional material libraries to the Multilist. I'm having trouble figuring out how to load just the .mat (Temporary Material Library) into the multilist view then appending to it.

Any help would be greatly appreciated. It's a great useful script.
Thanks in advance.
JokerMartini

AttachmentSize
v2-02.ms2.13 KB
materials.jpg72.19 KB

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
JokerMartini's picture

In the right direction

Alright so the Load radiobutton works properly. When it is selected it completely replaces the array with the new matlib file and displays it properly in the listview.

The problem: When the "Append" button is chosen it is suppose to add the materials from the selected mat file to the current array displayed in the listview. I want to have a check on this function so it does not load the same mat file twice. Unfortunately it is not working properly.

(
	rollout RO "Random Material" width:170
	(
		local mats = #()
 
		radiobuttons typeSel "" labels:#("Material Editor","Scene Materials","Load: (.matlib)") width:(ro.width-10) align:#center
		multiListbox mlb "Materials" width:(ro.width-10) align:#center
		button btnrandomwire "Apply Random Materials" width:(ro.width-10) align:#center
		button btnAppend "Append" width:(ro.width-100) height:14 pos:[95,36] enabled:false
 
		fn fnAppendMatLib doAppend:false =
		(
			currItems = mlb.items
			newItems = for i in currentMaterialLibrary where superClassof i == material collect i.name
			if doAppend then join currItems newItems else currItems = newItems
			mlb.items = currItems
			newMats = for i in currentMaterialLibrary where superClassof i == material collect i
			if doAppend then join mats newMats else mats = newMats
		)		
 
		on RO open do
		(
			mlb.items = for i in meditMaterials collect i.name
			mats = for i in meditMaterials collect i
		)
 
		on typeSel changed i do
		(
			case i of
			(
				1 : 
				(
					mlb.items = for i in meditMaterials where superClassof i == material  collect i.name
					mats = for i in meditMaterials where superClassof i == material collect i
				)
 
				2 : 
				(
					mlb.items = for i in sceneMaterials where superClassof i == material  collect i.name
					mats = for i in sceneMaterials where superClassof i == material  collect i
				)
 
				3 : 
				(
					fileOpenMatLib()
					fnAppendMatLib()
					btnAppend.enabled = true
				)
			)
		)
 
		on btnappend pressed do
		(
			local oldMtlLib = currentMaterialLibrary
			fileOpenMatLib()
			if oldMtlLib != currentMaterialLibrary do fnAppendMatLib doAppend:true
		)
 
 
		on btnrandomwire pressed do
		(
			local mats2
 
			case typeSel.state of
			(
				1 : 
				(
					mats2 = for i = 1 to meditMaterials.count where mlb.selection[i] AND superClassof meditMaterials[i] == material collect meditMaterials[i]
				)
 
				2 : 
				(
					mats2 = for i = 1 to sceneMaterials.count where mlb.selection[i] AND superClassof sceneMaterials[i] == material  collect sceneMaterials[i]
				)
				3 : 
				(
					mats2 = for i = 1 to currentMaterialLibrary.count where mlb.selection[i] AND superClassof currentMaterialLibrary[i] == material  collect currentMaterialLibrary[i]
				)
			)
 
			local userSel = selection as array
 
			for bar in userSel where isValidNode bar while mats2.count > 0 do
			(
				bar.material = mats2[random 1 mats2.count]
			)
		)
	)
 
	createDialog RO
)

John Martini
Digital Artist
http://www.JokerMartini.com (new site)

Anubis's picture

compare the file names

You can't compare directly 2 MaterialLibrary if they equal.
Compare the file names insted with getMatLibFileName()

on btnappend pressed do
(
  oldMtlLib = getMatLibFileName()
  fileOpenMatLib()
  if oldMtlLib != getMatLibFileName()
     do fnAppendMatLib doAppend:true
)

my recent MAXScripts RSS (archive here)

JokerMartini's picture

Alright

Alright Great!
Thanks Anubis.

John Martini
Digital Artist
http://www.JokerMartini.com (new site)

Anubis's picture

When using fileOpenMatLib()

When using fileOpenMatLib() get mats from currentMaterialLibrary

currItems = mlb.items
newItems = for i in currentMaterialLibrary where \
	superClassof i == material collect i.name
join currItems newItems
mlb.items = currItems
newMats = for i in currentMaterialLibrary where \
	superClassof i == material collect i
join mats newMats

my recent MAXScripts RSS (archive here)

JokerMartini's picture

Place

So where in the script am I placing these lines of code?
I'm not quite seeing where they go.

John Martini
Digital Artist
http://www.JokerMartini.com (new site)

Anubis's picture

You can put the code in your

You can put the code in your fnAppendMatLib() function.
Also edit "on typeSel changed i do" in case 3 leave only:

fnLoadMatLib() -- or just fileOpenMatLib()
btnappend.enabled = true

my recent MAXScripts RSS (archive here)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.