// =========================================================================== // 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. // =========================================================================== // // // Description: // This script is executed when a new scene file is created. It will create // panels if required or use existing panels. // // Creation Date: Dec 1998 // global proc string setTemplateToCurrentBrush() { // No arguments. Takes selection list and finds // the first stroke on it, then copies that strokes' // brush to the template brush. // Returns the name of the brush copied to the Template. string $nodes[] = `ls -sl`; string $node; string $brush = ""; int $idx = size( $nodes ); int $i = 0; while ($i < $idx) { if (`nodeType $nodes[$i]` == "transform") { string $chillins[] = `listRelatives -c -s -f $nodes[$i]`; string $chillin; for ($chillin in $chillins) { string $type = `nodeType $chillin`; if ($type == "stroke" || $type == "pfxHair" || $type == "pfxToon") { // TODO if there are multiple strokes, we should get only // the first one!? $nodes[$i] = $chillin; } } } string $type = `nodeType $nodes[$i]`; if ($type == "stroke" || $type == "pfxHair" || $type == "pfxToon") { string $attr = $nodes[$i] + ".brush"; string $result = `connectionInfo -sfd $attr`; string $buffer[]; int $num = `tokenize $result "." $buffer`; $brush = $buffer[0]; $i = $idx; // Break out of loop. } else { if (`nodeType $nodes[$i]` == "brush") { $brush = $nodes[$i]; $i = $idx; // Break out of loop. } } ++$i; } if ($brush == "") { // No stroke or brush was on the selection list. warning((uiRes("m_setTemplateToCurrentBrush.kNoBrushSelected"))); return ""; } string $defaultBrush = `getDefaultBrush`; if( objExists($defaultBrush +".notes") ) { if( catch(`deleteAttr -at "notes" $defaultBrush`) ) { string $fmt = uiRes("m_brushPresetSetup.kCouldNotDeleteDynAttrNotes"); error( `format -s $defaultBrush $fmt`); } } copyNode $brush $defaultBrush; // transform brushscale to template brush space string $bscale = $defaultBrush + ".globalScale"; float $val = getAttr( $bscale ); int $sW = getAttr($defaultBrush + ".screenspaceWidth"); float $scalefac; if( $sW ) { $scalefac = getAttr( "strokeGlobals.canvasScale" ); } else { $scalefac = getAttr( "strokeGlobals.sceneScale" ); } if( $scalefac < 0.00001 ) { $scalefac = .00001; } setAttr( $bscale, $val / $scalefac ); return $brush; }