Need help with Materials

I need to be able to create a button that allows a user to pick an image of their choosing and have it applied to an object. So far i have done the code and i've had no errors come up, but the actual material will not show, i've even tried to have it show in viewport but that doesn't seem to work. But i think the code works to some extent as the object changes colour as soon as i click the button, just no material.

Heres what i have so far:

button custom_material "Custom Material" pos:[434,130]
on custom_material pressed do
(
v = $
mat_image = selectbitmap()
Filepath = mat_image.filename
v.material=standard diffusemap: (Bitmaptexture fileName:Filepath) showInViewport:true
showTextureMap v.material on
Filename = getFilenameFile Filepath
)

I'm not the best with Maxscript, but if anyone can help, many thanks!

Comments

Comment viewing options

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

...

Simply use this (one line code)

button custom_material "Custom Material" pos:[434,130]
on custom_material pressed do if selection.count != 0 do
(
	if (bmp = selectbitmap()) != undefined do selection.material = standard diffusemap:(Bitmaptex bitmap:bmp) showInViewport:on
)

barigazy

Comment viewing options

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