PDA

View Full Version : recursively list materials?


softocean
03-14-2008, 06:47 PM
Hi All,

I've been working on a script to recrusively list materials in a scene to check that all textures are present- before uploading a scene to the renderfarm.

However, I get stuck on scene files which have materials with layers in the color channel. Do you guys have any ideas on how I can recursively navigate into the layers in the Material manager using scripting?

thanks in advance --softocean


var doc = GetActiveDocument();

// Activates the bump channel for a material
var mat = doc->GetFirstMaterial();
//mat->SetChannelState(CHANNEL_BUMP, TRUE);

var max_count = 100;
var j;
for(j=0; (j < max_count) && (mat != NULL); j++) {

println("object:",j," name:",mat#ID_BASELIST_NAME);


// Sets a texture for it
var bump = mat->GetChannel(CHANNEL_BUMP);

if (bump != NULL) {
var bumpBc = bump->GetContainer();

// get data from Base Channel Class
var file = bumpBc->GetData(CH_TEXTURE);

if (file != NULL) {
println(" bump:",file);
}

}


var color1 = mat->GetChannel(CHANNEL_COLOR);
if (color1 != NULL) {
var colorC = color1->GetContainer();
var file = colorC->GetData(CH_TEXTURE);
if (file != NULL) {
println(" color:",file);
}
}

var alpha = mat->GetChannel(CHANNEL_ALPHA);
if (alpha != NULL) {
var alphaC = alpha->GetContainer();
var file = alphaC->GetData(CH_TEXTURE);
if (file != NULL) {
println(" alpha:",file);
}
}

mat = mat->GetNext();
}

softocean
03-15-2008, 12:35 AM
well digging through the documentation today, I've discovered GetShaderContainer
for when layershader, or fusion shaders are used in the color channel, etc.

I don't know how to get the get the id's for the values in the container data yet...


var colorSc = color1->GetShaderContainer();
if (colorSc != NULL) {
println(" shader:");
}

bandini
03-16-2008, 02:42 AM
If you're working in C++, you have far more options.

In the BaseDocument class, for instance, you have GetAllTextures(), which will give you a copy of all texture paths in the document. Note that this is a copy, not an instance, so you can't modify them, but if all you are doing is checking to see if they are there, then you can easily accomplish that.

In BaseList 2D, you also have PluginShader* GetFirstShader(), which you can use with GetUp(), GetDown(), GetNext(), GetPred() to navigate through the shaders. All you have to do is look for bitmap shaders with GetTypeName(). Keep in mind, though, that some shaders are on materials, some are on objects, and some are on Xpresso nodes, and you'll need a way to go through all of those. Also, some objects, such as the Relief object, do not use shaders, only a string file path reference.

In COFFEE, I'm not really sure how this would be done...

Hope that helps.

Lex1968
03-17-2008, 08:24 AM
...to list materials in a scene to check that all textures are present- before uploading a scene to the renderfarm


Why write a script if you have this option?

Window/Selection-Structure Info/Textures/Mark Missing Textures

Cheers, Lex

CGTalk Moderation
03-17-2008, 08:24 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.