Materials Adding

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

Comment viewing options

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

The error is that you have

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
)
miauu's picture

This works:

(
	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_
)
Shade926's picture

I tried it work and it works

Thanks it seems to be working!! Legend!

miauu's picture

You can check this thread. In

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's picture

I can't exactly understand

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's picture

The thing i'm trying to

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!!??

barigazy's picture

...

I also not understand , u can not assigne texture to object but you can assigne material with that texture in some slot to the objects
Maybe this tool u can use for your concept http://www.scriptspot.com/3ds-max/scripts/mapdroper

barigazy

Shade926's picture

I might of been explaining it

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's picture

...

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

barigazy

Shade926's picture

That map droper is not really

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??

Comment viewing options

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