// =========================================================================== // 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. // =========================================================================== // Example Script that shows painting the dynamically created attribute by the User. // It uses "setValueCmd()" and "getValueCmd()" to set and get the values to the dynamically created attribute // instead of "getAttrValueCmd()" in Script Paint Tool. global string $objNameList[]; global int $freeSlotInObjList = 0; global int $nFreeSlots = 0; // This is the "Initialize Cmd". This procedure is called once // for every selected surface when an intial click is received // on any surface. The argument is the name of the surface. This // procedure returns a string which indicates to the scriptable // tool how to behave for the duration of the stroke. // global proc string initDynamicAttrbPaint( string $name ) { // It Creates a poly plane and attaches an attribute "testAttr" dynamically and initializes the value at all vertices to 0. // global string $objNameList[]; global int $freeSlotInObjList; global int $nFreeSlots; int $slot; // find a free slot for this surface in the global arrays // for ( $slot = $freeSlotInObjList; $slot < $nFreeSlots; $slot++ ) { string $message1 = (uiRes("m_dynamicAttrbPaint.kOneSlot")); print (`format -s $slot $message1`); if ( $objNameList[$slot] == "" ) { string $message = (uiRes("m_dynamicAttrbPaint.kTwoSlot")); print (`format -s $slot $message`); break; } } if ( $slot == $nFreeSlots ) { $nFreeSlots++; $freeSlotInObjList = $nFreeSlots; } string $message2 = (uiRes("m_dynamicAttrbPaint.kThreeSlot")); print (`format -s $slot $message2`); $objNameList[$slot] = $name ; string $cmd = "objExists " + $name + ".testAttr" ; if ( eval($cmd) == 0) { addAttr -longName "testAttr" -dt doubleArray pPlaneShape1; setAttr pPlaneShape1.testAttr -type doubleArray 36 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; } //print ("name = " + $name + " with id = " + $slot+ "\n") ; return ( "-id " + $slot); } // This is the "Finalize Cmd". This procedure is called at the // end of the stroke. It is passed the surface ID, that was // generated by the "Initialize Cmd". // global proc finishDynamicAttrbPaint( int $slot ) { global string $objNameList[]; global int $freeSlotInObjList; // clear out the slot that was used for this surface // string $message = (uiRes("m_dynamicAttrbPaint.kFourSlot")); print (`format -s $slot $message`); $objNameList[$slot] = ""; if ( $slot < $freeSlotInObjList ) { $freeSlotInObjList = $slot; } } // This is the "Set Value Cmd". It is called everytime a value // on the surface is changed. A surface ID, a grid index // on the surface and the value associated with that grid index // is passed. There can be additional arguments depending on the // options generated by the return value of the "Initialize Cmd". // In this case no additional arguments are passed. // global proc setDynamicAttrbPaintValue( int $slot, int $index, float $val ) { global string $objNameList[]; string $objname ; //print ( "\n setting value = " + $val + " at index " + $index + "\n") ; string $message = (uiRes("m_dynamicAttrbPaint.kFiveSlot")); print (`format -s $slot $message`); if ( $objNameList[$slot] != "" ) { // determine the name of the sphere associated with this // grid location // $objname = $objNameList[$slot] ; } string $cmd = "getAttr " + $objname + ".testAttr" ; float $attrValues[] = eval($cmd) ; $attrValues[$index] = $val ; string $newAttrValues = "36 "; for ( $attrValue in $attrValues ) { $newAttrValues += ($attrValue + " "); } //print ( "\n newAttrValues = (" + $newAttrValues + ")\n") ; $cmd = "setAttr " +$objname + ".testAttr -type doubleArray " + $newAttrValues ; //print $cmd ; eval($cmd) ; } // This is the "Get Value Cmd". It is called everytime a value // on the surface is needed by the scriptable paint tool. A // surface ID and a grid index is passed in. This procedure should // return the value for this grid location on the specified surface. // global proc float getDynamicAttrbPaintValue( int $slot, int $index ) { global string $objNameList[]; string $objname ; string $message = (uiRes("m_dynamicAttrbPaint.kSixSlot")); print (`format -s $slot $message`); if ( $objNameList[$slot] != "" ) { // determine the name of the sphere associated with this // grid location // $objname = $objNameList[$slot] ; } string $cmd = "getAttr " + $objname + ".testAttr" ; float $attrValues[] = eval($cmd) ; //print ("Value at " + $index + " = " + $attrValues[$index]) ; return $attrValues[$index] ; } proc string setupTool() { string $context =`eval "artUserPaintCtx -i1 \"userPaint.png\" -cf false -dl true -whichTool \"userPaint\" "`; resetTool $context ; artUserPaintCtx -e -ic "initDynamicAttrbPaint" -fc "finishDynamicAttrbPaint" -svc "setDynamicAttrbPaintValue" -gvc "getDynamicAttrbPaintValue" -gsc "" -cc "" -tcc "" -gac "" $context; setToolTo $context; toolPropertyWindow; return $context ; } // This procedure should be set as the "Tool Setup Cmd" in the // Setup tab of the Maya Artisan Script Paint tool's tool settings // window. The tool context is supplied as an argument. // global proc dynamicAttrbPaint( string $context ) { file -f -new ; $shapeNames = `polyPlane -w 1 -h 1 -sx 5 -sy 5 -ax 0 1 0 -tx 1 -ch 1 ` ; //print ("shapeNames = ") ; print $shapeNames[0]; print("\n") ; fitPanel -selected; $context = setupTool() ; // set radius of brush artAttrCtx -e -radius 0.1 $context ; //set opacity artAttrCtx -e -opacity 1 $context ; // select the brush to use artAttrCtx -e -stampProfile "solid" $context ; // set the value to be painted artUserPaintCtx -e -value 1.0 $context; artUserPaintCtx -e -colorfeedback true $context; }