// =========================================================================== // Copyright 2018 Autodesk, Inc. All rights reserved. // // Use of this software is subject to the terms of the Autodesk license // agreement provided at the time of installation or download, or which // otherwise accompanies this software in either electronic or hard copy form. // =========================================================================== // // // // // // // string hypergraphConvertPsdToFile(string $psdFileNode) // // // Converts the PSD file node to a file texture node with // the image from the active layer set. // // // string $psdFileNode The PSD file node name. // // // string : The newly created file node name. // // // // global proc string hypergraphConvertPsdToFile(string $psdFileNode) { if(size($psdFileNode) == 0) return ""; source "createRenderNode.mel"; string $layerSetName = `getAttr ($psdFileNode + ".layerSetName")`; string $psdFileName = `getAttr ($psdFileNode + ".fileTextureName")`; if(size($psdFileName) == 0) { string $msg = (uiRes("m_hypergraphConvertPsdToFile.kNoFileTexture")); error (`format -stringArg $psdFileNode $msg`); return ""; } string $images = `workspace -q -fileRuleEntry "images"`; string $imageDir; if($images == ""){ string $rootDir = `workspace -q -rootDirectory`; $imageDir = $rootDir + "images"; if (!`filetest -d $imageDir`){ sysFile -makeDir $imageDir; } }else{ $imageDir = `workspace -expandName $images` ; } string $fileTexName = basenameEx($psdFileName); string $tempPath = $fileTexName + "_" + $layerSetName + ".iff"; $tempPath = $imageDir + "/" + $tempPath; psdExport -ifn $psdFileName -ofn $tempPath -lsn $layerSetName -for "iff" -bpc 0; string $fileNode = `shadingNode -asTexture file`; setAttr -type "string" ($fileNode + ".fileTextureName") $tempPath; // Get the input and output connections of the PSD node selected. // If input connections exist, then consider those connections or else // just create a file node and connect it. string $psdInputConnections[] = `listConnections -source on -destination off -connections true -plugs true $psdFileNode`; string $psdOutputConnections[] = `listConnections -source off -destination on -connections true -plugs true $psdFileNode`; int $index; if(size($psdInputConnections) > 0){ for ($index = 0; $index < size($psdInputConnections); $index += 2){ string $tokens[]; tokenize $psdInputConnections[$index] "." $tokens; disconnectAttr $psdInputConnections[$index +1] $psdInputConnections[$index ] ; // Destination node is the PSD node and the source node is usually // place2d node. $destinationConnection = $fileNode + "." + $tokens[1]; $sourceConnection = $psdInputConnections[$index + 1]; connectAttr -force $sourceConnection $destinationConnection; } } for ($index = 0; $index < size($psdOutputConnections); $index += 2) { string $tokens[]; tokenize $psdOutputConnections[$index] "." $tokens; $sourceConnection = $fileNode + "." + $tokens[1]; $destinationConnection = $psdOutputConnections[$index + 1]; connectAttr -force $sourceConnection $destinationConnection; } return $fileNode; }