ScriptSpot

Forum topic · General Scripting

Material Randomizer +

By JokerMartini · 2011-01-06

Description

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

Attachments
Comments (6)

In the right direction

JokerMartini · 2011-01-07

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
)

compare the file names

Anubis · 2011-01-08

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
)

JokerMartini · 2011-01-06

Alright Great!
Thanks Anubis.

Anubis · 2011-01-06

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

Place

JokerMartini · 2011-01-06

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

Anubis · 2011-01-06

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