// =========================================================================== // 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. // =========================================================================== // // // // // // // Creation Date: December 8/2000 // // Description: // // This file contains a global procedure which can be called to import an // image file as a file texture. Callers have some options when asking for // the image file to be imported, such as whether the file texture node // which gets created should have a placement node attached, or whether // the image file should be used as a projection texture. // global proc string importImageFile( string $fileName, int $asProjection, int $asStencil, int $withPlacement) { // // Description: // This procedure is called when some piece of UI wants to import an // image file to be used as a file texture. // This procedure creates a file texture node and potentially other nodes // according to the options the caller specifies, and sets the // fileTextureName attribute of the created file texture node to the name // of the file which was imported. // string $fileTextureNode; $fileTextureNode = renderCreateNode( "-as2DTexture", "", "file", "", $asProjection, // projection $asStencil, // stencil $withPlacement, // placement 0, // shadingGroup 0, // createAndDrop "" // editor, for createAndDrop ); if (`nodeType $fileTextureNode` != "file") { // The result node was not a file texture, which means it was either a // projection or stencil node. We will look upstream to find the file // texture. // // ASSUMPTION: // We assume that the result node was either a projection or a stencil, // but we do not check. We also assume that the file texture we are // looking for is just upstream of the image attribute of the // projection or stencil node. // string $sources[] = `listConnections -source true -destination false -type "file" ($fileTextureNode + ".image")`; $fileTextureNode = $sources[0]; } string $tokenArray[]; tokenize($fileName, "/", $tokenArray); string $pathTail = $tokenArray[size($tokenArray) - 1]; tokenize($pathTail, ".", $tokenArray); string $fileNameRoot = $tokenArray[0]; if (`match "^[0-9]+" $fileNameRoot` != "") { // The file name begins in a number, which is invalid for the name of a // node in Maya, so we will prefix the name of the file texture node // with "file_". // // The rest of the file texture node name will be the name of the // file, suffixed with "_1". The effect of this naming is that if the // user loads the same image multiple times, the resulting file // texture nodes will be named with suffixes _1, _2, _3, etc. // $fileTextureNode = `rename $fileTextureNode ("file_" + $fileNameRoot + "_1")`; } else { // The file texture node name will be the name of the // file, suffixed with "_1". The effect of this naming is that if the // user loads the same image multiple times, the resulting file // texture nodes will be named with suffixes _1, _2, _3, etc. // $fileTextureNode = `rename $fileTextureNode ($fileNameRoot + "_1")`; } setAttr ($fileTextureNode + ".fileTextureName") -type "string" $fileName; string $msg = (uiRes("m_importImageFile.kImported")) ; print `format -stringArg $fileName $msg` ; return $fileTextureNode; }