PDA

View Full Version : Loading Material Library (Newbie)


womble1234
04-22-2008, 12:18 AM
Hi everyone,

I just got started with Maxscript today, and have been playing around with it. It's pretty addictive!

I've mostly been taking other peoples scripts and editing them to my own needs and I think i'm learning quite a bit this was and with the Maxscript references.

What i'm having a huge amount of trouble with however is loading material libraries.

On button press I would like to load a single material library from a UNC path (\\material (file://\material) library\), apply it to the current selected object and apply it to the current material editor slot.

Would anyone be able to help me with this? I've been pulling my hair out all day!

Cheers,
Gary.

ZeBoxx2
04-22-2008, 01:58 AM
-- load the material library into a temporary construction
-- (so it doesn't replace the active one)
tempLib = loadTempMaterialLibrary "\\\\machinename\\sharedfolder\\somefile.mat"

-- get the currently selected objects
objs = getCurrentSelection()

-- get just the first one? You said 'object'
obj = objs[1]

-- the material library itself may have more than one material/map in it. Get the first one?
mat = tempLib[1]

-- apply this material to the object
obj.material = mat

-- or to all the selected objects
-- objs.material = mat

-- and toss it in the active material editor slot
meditmaterials[activeMeditSlot] = mat


So some things you need to consider...
- Do you want it only on the currently selected object (what if you have multiple selected), or all selected objects
- Do you know which material from the material library you want (what if there is more than 1 in there)


I hope this helps anyway :)

ZeBoxx2
04-22-2008, 02:03 AM
and with added buttony-user interface-y goodness...


rollout fetchMatLib "fetchMatLib" (
button btn_loadmat "fetch material library"
on btn_loadmat pressed do (
local sel = getCurrentSelection()
if (sel.count == 0) then ( messagebox "No object(s) selected" title:"Error 001 - No objects selected" )
else (
local libFile = getOpenFileName caption:"Select a material library file" types:"Material Libraries (*.mat)|*.mat"
if (libFile != undefined) then (
local tempLib = loadTempMaterialLibrary libFile
if (tempLib == undefined) then ( messagebox "Could not load material library file" title:"Error 002 - Could not load matlib file" )
else (
local mat = tempLib[1]
sel.material = mat
meditmaterials[activeMeditSlot] = mat
)
)
)
)
)
createDialog fetchMatLib

Teirz
04-22-2008, 02:30 AM
on btnLoadMaterial pressed do
(
tempMatLib = loadMaterialLibrary "<Your Path>"
$<Object>.material = tempMatLib["<MaterialName>"]
)


Just something i can think of when you already know the material name you need and apply it straight to the object.

CGTalk Moderation
04-22-2008, 02:30 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.