ScriptSpot

Forum topic · General Scripting

pick material button

By jos · 2011-12-29

Description

hello,
I try to find a button te get a material. okay, there's the materialbutton. but once picked you cannot modify the material. also you can't drag and drop it in the materiallib or copy it. I've made a copy material button (mat = meditMaterials[spnMatSlot.value]) but not exactly what I want.. so does anyone knows how i can gat such a getmaterial button? thanx

Comments (3)

where is the problem?

Anubis · 2011-12-29

What you mean by "once picked you cannot modify the material"? If your MaterialButton is named for example

matBtn1

then the picked material is stored in it #material property, so to access it just say:

matBtn1.materail

.

As for the drag-n-drop, yep, no such feature for any of the scripted rollouts controllers, but where is the problem?

The MaterialButton just popup Mat/Map Browser dialog and there you can specify from where to pick the material (library, editor, active slot, scene, selected object, or even from new).

Well, if you want to control the Mat/Map Browser dialog then you'll need regular ui Button and call to

materialBrowseDlg

and

mtlBrowser.browseFrom

.

Here is an examples, but check the help file for detals.

-- call stored material in MaterialButton
if IsKindOf matBtn1.materail Material then
(
	case ClassOf matBtn1.materail of
	(
		Standard  : matBtn1.materail.diffuse = red
		DxMaterial: matBtn1.materail.k_d = red
		default   : messageBox "Unsupported material type"
	)
)
else messageBox "No stored material" title:"My Tool"

-- using materialBrowseDlg()
myMat = materialBrowseDlg #mats #instanceOnly
mtlBrowser.browseFrom #mtlLibrary

a more userfriendly approach

jos · 2011-12-29

thanx for reply Anubis. yes I know calling the materialBrowseDlg.
I was wondering if there was a drag and drop possibility.
it's not a problem that i can't get it working,
but more user-friendly.. sorry if I wasn't clear enough
is it possibly with the sdk?

ok ;)

Anubis · 2011-12-29

yep, with the sdk drag-n-drop is built-in.