material texture exporting?

Is is possible to know if a material is been used and if so, how can I export the texture of it? Can someone give an example?

 

Thanks

Comments

Comment viewing options

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

You can use

You can use 'refs.dependents' to know if your a material is in use.
It send back to you a list of what depends on him. If the material is in use then the list will contain the objects which use it.

For example: (select an object before run the script)

(
local theMat = selection[1].material
local refDepMat = refs.dependents theMat
if refDepMat != undefined do (
for obj in refDepMat where superclassof obj == GeometryClass do format "obj: %\n" obj
)
)

 

An another way is to test if the material is present in the scene materials.

(
local theMat = selection[1].material
format "theMat=%\n" theMat
for m in sceneMaterials do (
if theMat == m do format ">>> Material found!\n"
)
)

 

alexmbr's picture

And how do I export the

And how do I export the materials, or to be more precise, the textures of an object? That is what I really need to do: To know every texture an object has and export them.

arketip's picture

selection[1].material will

selection[1].material will give you the current material of an object.
The place of the texture file depends of the material type and the slot you want.
In fact i don't understand exactly you want to mean when saying "export the texture"
What do you want to export exactly ? All ?
They are many parameter to export !

Type in the listener (with an object selected)

showproperties selection[1].material

You will view all the parameters of the material. And they are not all there.
It is only the specifics parameters. The commons parameter are not listed.

Look in the maxscript reference. It is very weel explained.
menu: help menu/Maxscript reference...
(if you don't have the reference files instaled on your computer, you can download it here:
http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=5659551)

Another example if you have a standart material and you want the diffuse bitmap.

showproperties selection[1].material.diffuseMap

selection[1].material.diffuseMap.fileName

alexmbr's picture

Lets say that I have a model

Lets say that I have a model with four different textures. How do I know the name and location of those textures? Because I will export the model and I need to export its textures also.

Look in the maxscript reference. It is very weel explained.
menu: help menu/Maxscript reference...

I looked and I didn't find any example of this.

thanks

arketip's picture

Four textures in the same

Four textures in the same model ?
You mean : diffuse, bumpmap, opacity, ... ?
or a multimaterial of 4 IDs ?
When you say 'a model' you mean one single object or a group of 4 objects ?
The meaning of 'model' can vary depending on the software which you normally use.

alexmbr's picture

I mean one single object

I mean one single object with four different diffuse maps and perhaps one bumpmap.

arketip's picture

 I don't know the

 I don't know the composition of your material but there is a way to loop through a complex material using a recursive function.
If that is what you want, then try this code:

 

fn printMat mat = (
    case classof mat of
    (
        blend: (printMat mat.map1; printMat mat.map2)
        compositematerial: (for thisMat in mat.materiallist where thisMat!=undefined do printMat thisMat)
        multimaterial: (for thisMat in mat.materiallist where thisMat!=undefined do printMat thisMat)
        standardmaterial:
        (
            format "mat.name = % \n" mat.name
            if mat.diffuseMapEnable and classof mat.diffuseMap == Bitmaptexture do (
                format "diffuseMap = % \n" mat.diffuseMap.fileName
                )
            if mat.bumpMapEnable and classof mat.bumpMap == Bitmaptexture do (
                format "bumpMap = % \n" mat.bumpMap.fileName
                )
        )
    )
)

(
clearlistener()
    for obj in selection where isKindOf obj GeometryClass do (
        local mat = obj.material
        printMat mat
        )
)

alexmbr's picture

Thank you. That help me to

Thank you. That help me to understand.

mike.edel's picture

if you just want to collect

if you just want to collect all textures of the scene into a new directory you could simply use the collect ressources utility in the utlities tab

 it will move/copy all used scene textures into a folder of your choice and can also adjust your materials to match the new location

 

cheers,

 

mike 

Comment viewing options

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