mapbutton - how to use in a material

mapbutton - how to use in a material

DEDE1709_2
Participant Participant
722 Views
5 Replies
Message 1 of 6

mapbutton - how to use in a material

DEDE1709_2
Participant
Participant
Hello,

I´m trying to make a "mapbutton" work like a normal map button in a standard material.

What I mean is a map button / slot where I can select a map from the map list when the
button is empty and go one level deeper to the map when a map is inside the button and
it´s clicked.

The current maxscript mapbutton can open the new maps selection dialog, but when a map
is assigned it´s not automatically acting like the usual map buttons in standard materials.

I´ve not been able to successfully use this button in a way that users are used to it. The only
thing that I found out was that assigning a variable to the button itself will help.

But there is still a problem with this method, as I cannot assign a specific map from a material
to the button, it´s always the same diffuse map that is connected to the button.

example:

parameters main rollout:mapbuttontest
(
source_map_name type:#string ui:source_map
)
rollout mapbuttontest "map button test"
(
mapbutton source_map "< Source Map >" tooltip:"Select Source Map" width:300 height:20 align:#center offset:
)


Does anyone know how this could be solved ?

Best,
Martin
0 Likes
723 Views
5 Replies
Replies (5)
Message 2 of 6

Swordslayer
Advisor
Advisor
A few things to note. First, the parameter definition type should definitely be type:#texturemap, not string. Second, is this a scripted material or a scripted texture map or just CA? In the first case it should do exactly what you want (and a bigger chunk of code showing the problem would be handy to find out why it doesn't), if it's just CA.. well, you could always have another button that would send the linked texturemap to the active slot of material editor, for example, but that's about it.
0 Likes
Message 3 of 6

DEDE1709_2
Participant
Participant
Thanks. This could be the problem. I will give it a try and let you know if it´s solved.
0 Likes
Message 4 of 6

DEDE1709_2
Participant
Participant
Ok, I´ve tried several methods, but I can´t manage to make it work. What I´m trying to achieve is a simple map button that triggers an event when a map is selected. Here is the simple script:

----------
plugin material mapbuttontest
name:"mapbutton test"
classID:#(0x4399744a, 0x3330f8d2)
extends:Standardmaterial replaceUI:false


(
parameters source rollout:source_picker
(
source_map_shader type:#texturemap ui:source_map
)

rollout source_picker "Pick Source Map"
(
mapbutton source_map "< Source Map >" tooltip:"Select Source Map" width:300 height:20 align:#center offset:
on source_map_shader changed map do
(
print "I´ve picked a source map!"
)
on source_map picked texmap do
(
print "I´ve picked a source map"
)

)
)
----------

While the mapbutton will act as expected, I cannot find a way to let it trigger an event. In this example, non of the two on events work and no print function will be executed. I´ve also tried on .... pressed and on .... selected but both don´t work.

I´m lost and I think that there is something pretty obvious that I´m missing.

Any help is really appreciated!
0 Likes
Message 5 of 6

Swordslayer
Advisor
Advisor
It is, it goes back to the CA vs scripted material/map differences. In the former case event handlers work as expected, in the latter you have to use the set event of the parameter itself. The relevant piece of code for you would be:

parameters source rollout:source_picker
(
source_map_shader type:#texturemap ui:source_map
on source_map_shader set val do
(
print "I´ve picked a source map!"
)
)


By the way, the code tag keeps indentation, classic quotes and other nice things, be sure to use it when including code next time 🙂
0 Likes
Message 6 of 6

DEDE1709_2
Participant
Participant
Thank you sooo much!!! This is exactly what I needed and it works perfectly. Really appreciated!

Here is my code:


plugin material mapbuttontest name:"mapbutton test"
classID:#(0x4399744a, 0x3330f8d2)
extends:Standardmaterial replaceUI:false

(
parameters source rollout:source_picker
(
source_map_shader type:#texturemap ui:source_map
on source_map_shader set val do
(
delegate.maps = val
delegate.maps = val
delegate.maps = val
)
)

rollout source_picker "Pick Source Map"
(
mapbutton source_map "< Source Map >" tooltip:"Select Source Map" width:300 height:20 align:#center offset:
)
)


BTW: If you are interested in any of my products at http://www.vizpark.com, drop me a personal message.
0 Likes