PDA

View Full Version : Select File Node by Image File Path


ColinKennedy
12-15-2011, 07:41 PM
Quick question: I baked an object using convertLightmapSetup and I wanted to get a selection of the resulting file node to store into a string. All I can get when I try to do this though is users/documents/maya/default/images etc etc/bake.tiff instead of the actual node in Maya, file1.

How do you select a file node based on the image path assigned to it? So far, I can only find information on how to do the opposite. Thank you for your replies in advance!

Azrail
12-15-2011, 08:02 PM
You can't do that directly. The image path is an attribute of the file node so you have to iterate over al file nodes, inspect their fileTextureName attribute, and if it's value is equal to the path you have than you got what you are looking for. It's tricky though, because sometimes paths are stored as absolute, and sometimes as relative.

ColinKennedy
12-16-2011, 12:37 AM
That's unfortunate, I was hoping that wouldn't be the case. It's strange because just doing something similar to this

$selectedTexture = `convertLightmapSetup -camera persp -sh -ulb -showcv`;
will display the file path and not the file node

but ConvertSolidTx works behaves as expected. It must be the way the commands are handled between Maya/Mental Ray that changes the output. At any rate, I can't use SolidTx, I need the LightmapSetup for baking.


The only other way to get the file that I can think of is query the selected geometry's currently assigned shading group and then find the shader - the default lambert output shader that the baked file creates - and then find the shader's connection to the baked file node. In my case, it seems to default to incandescence as its input. I'm sure there's a way to find that info so I'll be sure to do some research unless you happen to know a way to script this. Any thoughts on the idea?

Azrail
12-16-2011, 09:39 AM
Check this one, it's actually quite simple and quick to write. You need to set the $fname variable to the file string you're looking for.

string $files[] = `ls -type "file"`;
string $fname = "sourceimages/checker1-body.tga";
int $absPath = 0;
string $myFile;
for ($file in $files)
{
string $tex = `getAttr ($file + ".ftn")`;
if (!$absPath)
{
// Strip only the filename without extension and folder
$fname = basenameEx($fname);
$tex = basenameEx($tex);
}
if ( $fname == $tex)
{
$myFile = $file;
break;
}
}
print ("Your file is: " + $myFile + "\n");

ColinKennedy
12-21-2011, 03:00 PM
Sorry for the late reply. I'm getting a few simple errors that I just can't seem to fix when I try to use that script.

when I store the output of convertLightmapSetup as a variable, (like this: $shadMap_bake = `convertLightmapSetup -camera persp -sh -bakeSetOverride camCov_textSet -ulb -showcpv`;)

Maya keeps it as a string[] array. So when I put $fname = $shadMap_bake Maya gives me the cannot convert string[] to string.

If I change one or another to try and compensate for this, the script that you provide me fails saying that == is an illegal operation.

Was I using your script incorrectly or is there an error in it that is keeping it from functioning as expected?

Azrail
12-21-2011, 04:21 PM
you should just use:
$fname = $shadMap_bake[0];
this means to use the first string of the string array as the search file name. I can't test right now what exactly the return of the convertLightMap looks like, but you can use the element from the array that you need by changing the index in the square brackets. Bear in mind that array indices are zero based i.e. $array[0] is element 1, $array[1] is 2 etc.

ColinKennedy
12-22-2011, 04:48 AM
Wow, I can't believe that I didn't think to try that. I knew that important bit too, I can't believe I forgot. It is my first script after all, thank you very much for the help, it worked perfectly!

CGTalk Moderation
12-22-2011, 04:48 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.