PDA

View Full Version : material editor help


dieselll
05-10-2009, 12:16 PM
hi all ....i am a beginner in 3d max and i want to do a simple task ...can any body help me plz :)
i want to :
1)go to material editor toolbar to get material
2)choose selected and double click on material
3)from basic parameters : diffuse and press the button beside the color
4)from co-ordinates : map channel =2
5)assign material to view port
6)show map in view port


plz guys i really need your help
thx in advance

Piflik
05-10-2009, 03:38 PM
Am I understanding you right? You want a script that changes the Map Channel of the current selected object's material to 2 and set it to be show in viewport?

In this case:

$.material.DiffuseMap.coords.MapChannel = 2
showTextureMap $.material $.material.diffuseMap true

(Works only with single selected objects and basic Materials...if you use Multi/Sub-Object or Blend Materials or any other Material that doesn't have a Diffuse Map Channel, it will fail.)

dieselll
05-10-2009, 03:48 PM
i meant to do it for multi -complicated- objects ... i want this script to do these changes for selected objects

Bobo
05-10-2009, 03:52 PM
hi all ....i am a beginner in 3d max and i want to do a simple task ...can any body help me plz :)
i want to :
1)go to material editor toolbar to get material
2)choose selected and double click on material
3)from basic parameters : diffuse and press the button beside the color
4)from co-ordinates : map channel =2
5)assign material to view port
6)show map in view port


plz guys i really need your help
thx in advance

While I applaud your attempt to list the steps you want to automate (which is usually the best way to get to a good script), you should describe WHAT should be done, not HOW it should be done because MAXScript does not necessarily work the way the UI and mouse are used in Max. It is a programming language so you will have to think at a different level.

1. Keep in mind you don't need to use the Material Editor to get a material from the scene, material library of even the Material Editor itself! (sounds crazy, but it is true). So if you want to let the user pick a material from a selected object (or many materials from many selected objects), there are simpler ways to do that. If you want to apply the mapping channel 2 change to any number of selected objects, you would simply need to loop through the selected objects with a FOR loop and apply the same operation to each one's material.

2. Keep in mind that not all materials have a valid Diffuse Map and not all Maps use Mapping Channels as default projection method, so it might be a good idea to check that accessing the diffuse channel of the material is even possible (if the object has a Multi/Sub material for example, it has many sub-materials which might have diffuse mpas, but the top level material does not).

3. If you are making the changes directly to the scene objects, applying the changes to the material will be reflected immediately without having to assign back. You would be working directly with the already assigned materials.

So a description of what you want to do would look more like

1. For every selected object in the scene
2. Get its material and if it is a valid material and not 'undefined'
3. Try to access the .DiffuseMap channel of the material and if this did not fail
4. Try to change the map channel to 2
5. Enable the Show Map In Viewport for the DiffuseMap of the current Material

This could be made even more advanced if you checked the class of the material and repeated the steps 3,4 and 5 for any sub-material in a MultiSub, DoubleSided, TopBottom etc. materials.

I know if did not solve your problem (Piflik almost did), but I am trying to help on a more general level of learning MAXScript.

dieselll
05-10-2009, 04:01 PM
i really dont know how to thank u ... u are a real expert bro :)....thx again
and i wish i didnt disturb you :)

Piflik
05-10-2009, 05:16 PM
That would be the basic translation for Bobo's advice. Still no support for Multi/Sub-Object Materials and the likes...but it should work fo selection sets and shouldn't produce errors if encountering a 'bad' Material...

for i in selection do
(
try
(
i.material.DiffuseMap.coords.MapChannel = 2
showTextureMap i.material i.material.diffuseMap true
)
catch()
)

I tried to construct a script that does all of what Bobo suggested, but it is entirely untested...(and still doesn't support all Materials).

It tests the Material of every selected Object and if it is a Blend, Composite, Multi/Sub-Object, Shellac or Top/Bottom Material, it repeats the test for all of their Submaps. When the Material is none of the above, it tries to set the Material's Diffuse Map to Map Channel 2. Obviously it doesn't work for Materials that don't use a Diffuse Map (just like the Script posted above).


fn MapChannel2 MyMat
(
try
(
MyMat.diffuseMap.coords.mapChannel = 2
showTextureMap MyMat MyMat.diffuseMap true
)
catch()
)


fn MatTest MyTestMat
(
case of
(
(MyTestMat == BlendMaterial):
(
MatTest MyTestMat.Map1
MatTest MyTestMat.Map2
)

(MyTestMat == CompositeMaterial):
(
for m in MyTestMat.materialList do MatTest m
)

(MyTestMat == MultiMaterial):
(
for m in MyTestMat.materialList do MatTest m
)

(MyTestMat == Shellac):
(
MatTest MyTestMat.shellacMtl1
MatTest MyTestMat.shellacMtl2
)

(MyTestMat == TopBottom):
(
MatTest MyTestMat.topMaterial
MatTest MyTestMat.bottomMaterial
)

default: MapChannel2 MyTestMat
)
)

for i in selection do MatTest i.Material

floopyb
05-11-2009, 06:45 AM
My script does this stuff pretty easily:
http://www.scriptspot.com/3ds-max/modifier-modifier-zorb

I used the method of using getclassinstances and then refs.dependantnodes to check if it was associated with the selected objects.

Can be slower but is seems to be a much more accurite way of getting materials.

floopyb
05-11-2009, 07:12 AM
Opps, miss-read a little, it can do it for different texture map classes on an object, not explicitly the diffuse channel

DaveWortley
05-11-2009, 10:02 AM
Wouldn't something like this work?

Just get all the standard materials, if they have a diffusemap then change the mapping channel to 2 and show in viewport, no need to itterate through Blends/multisubs etc...

for o in getclassinstances StandardMaterial do
(
try
(
o.diffusemap.coords.mapchannel = 2
Showtexturemap o o.diffusemap on
)
catch()
)

dieselll
05-11-2009, 10:49 AM
guys why doesnt the channel change when i use any of these scripts ?

DaveWortley
05-11-2009, 10:56 AM
Mine does.

you have to use diffusemap.coords.mapchannel not diffusemap.mapchannel

Piflik
05-11-2009, 11:18 AM
Sorry...my bad... :blush:

Corrected the scripts...

dieselll
05-11-2009, 12:37 PM
guys these scripts are not working with me .... am going crazyyyyyyyyyy
plz i want u to understand what i want .... all what i want is to :

for each object selected in scene .... do the following :
1)add UVW mapping modifier
2)from parameters :mapping ,,,,choose BOX
3)map channel = 2
4)go to material editor and press get material
5)choose selected and click on material
6)from basic parameters :diffuse; change map channel = 2
7)assign material to selection
8)show map in view port






and i used this code but i didnt work exactly like what i want:

for s in selection do addModifier s (UVWMap())
s.modifiers[#UVW_Mapping].maptype = 4
s.modifiers[#UVW_Mapping].mapChannel = 2
mtlBrowser.browseFrom #selected
myMat = meditmaterials[1]
01 - Default:Standard
myMap = Noise()
Noise:Noise
myMat.diffuseMap = myMap
Noise:Noise

so plz try to help me guys i should show my work to my manager and i did nothing till now :(
and this is all what i need ...nothing more ...nothing less
thx in advance

dieselll
05-11-2009, 12:41 PM
and by the way ... am working on vray materials not standard materials :)

DaveWortley
05-11-2009, 12:55 PM
Well if it's Vray then it should be something like this instead.

for o in getclassinstances VrayMtl do
(
try
(
o.texmap_diffuse.coords.mapchannel = 2
Showtexturemap o o.texmap_diffuse on
)
catch()
)

Piflik
05-11-2009, 01:06 PM
Yeah...if you replace the code in the first function in my script with the one Dave posted, it should work with VRay. Also, if you use single VRay Mats only, you don't really need the material test part....


fn MapChannel2 MyMat
(
try
(
MyMat.texmap_diffuse.coords.mapChannel = 2
showTextureMap MyMat MyMat.texmap_diffuse true
)
catch()
)


for i in selection do
(
MapChannel2 i.Material
addModifier i (uvwmap maptype:4 MapChannel:2)
)

Hope it works...

dieselll
05-12-2009, 09:38 AM
dude this is exactly what i want ...i only want to ask a last question

i want to write a for loop which chooses sertain objects according to their name instead of selecting objects .... example
i want to select all objects will name box like box01 box02 box 03 ..... but if their is sphere01 it will not be selected in the loop ....
thx in advance

Piflik
05-12-2009, 10:19 AM
All you have to change is instead of
for i in selection do
you write
for i in $box* do

dieselll
05-12-2009, 10:25 AM
lool....dats prety easy :)....thx dude

CGTalk Moderation
05-12-2009, 10:25 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.