ScriptSpot

Forum topic · General Scripting

Materials Adding

By Shade926 · 2013-04-15

Description

I'm trying to add to my rollout an option for the user to add a material of there choice to the selected object.
Whenever i try to do it, it wont convert the image so it will work on the box.

My code is:

button openbox "Add Material"
on openbox pressed do
(
myMap = getOpenFileName \
caption:"Open A Test File:" \
filename:"c:"

myMap = uvwMap mapType:4
addmodifier selection myMap
m = myMap

selection.material = m
)

Comments (10)

miauu · 2013-04-15

The error is that you have ")" where it should not be:


)
button closeinterface "Exit"

You don't need of the ")"

Use this:


(
	global test_button
	try(destroyDialog test_button)catch()
	rollout test_button ""
	(
		local usersimage

		button btn_browse "Select folder with textures"
		button btn_aplyMat "Apply Material"
		button closeinterface "Exit"

		on btn_browse pressed do
		(
			usersimage = getOpenFileName caption: "Select Your Image" filename:maxFilepath types: "Images (*.bmp;)|*.bmp"
		)
		on btn_aplyMat pressed do
		(
			selection[1].material = standardMaterial diffuseMap: (Bitmaptexture fileName:usersimage) showInViewport:true
		)
		
		on closeinterface pressed do
		(
			destroydialog test_button
		)
	)
	createDialog test_button 500 600
)

This works:

miauu · 2013-04-15


(
	global rol_
	try(destroyDialog rol_)catch()
	rollout rol_ "miauu"
	(
		local usersimage
 
		button btn_browse "Select folder with textures"
		button btn_aplyMat "Apply Material"
 
		on btn_browse pressed do
		(
			usersimage = getOpenFileName caption: "Select Your Image" filename:maxFilepath types: "Images (*.bmp;)|*.bmp"
		)
 
		on btn_aplyMat pressed do
		(		
			selection[1].material = standardMaterial  diffuseMap: (Bitmaptexture fileName:usersimage) showInViewport:true
		)
 
	)
	createdialog rol_
)

I tried it work and it works

Shade926 · 2013-04-15

Thanks it seems to be working!! Legend!

You can check this thread. In

miauu · 2013-04-15

You can check this thread. In the code that I provided you can see how to get bitmap from the HDD and how to assign bitmaptexture to the diffuse slot of standard material.

miauu · 2013-04-15

I can't exactly understand what you want to acheive, but...
first you assign to myMap a filepath(file, which is not a material), then you assign to myMap a uvwMap modifier(which is not a material). Then m = myMap, so the m is uvwMap modifier, and finaly you assign, as material, to the selection of objects a modifier. Modifiers are not materials. Where is the material?

Shade926 · 2013-04-15

The thing i'm trying to achieve is that I want the user to be able to select a bitmap from their computer and then be able to apply it to the selected object as a texture.

The code above was my way of trying to achieve that so it might be totally wrong. If you have any ideas on how i would code the thing im trying to achieve that would be amazing!!??

Shade926 · 2013-04-15

I might of been explaining it wrong.

Im trying to allow the user to select a bitmap image from thier computer and then apply that image as a material to the selected object?

barigazy · 2013-04-15

Yup. Script that I suggested does that in similar way.

Shade926 · 2013-04-15

That map droper is not really what i want but i tried this piece of code instead

button openbox "Add Material"
on openbox pressed do
(
usersimage = getOpenFileName caption: "Select Your Image" filename: maxFilepath types: "Images (*.bmp;)|*.bmp"
)
button applyMat "Apply Material"
on applyMat pressed do
(
m = standardmaterial()
material = m
m.diffusemap = Bitmaptexture fileName:usersimage
)

Although when i run it i come up with an error any ideas??