// =========================================================================== // 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. // =========================================================================== // pull in the scripts that define routines needed for bevel source "performBevelPlus"; // most stuff is sitting in here source "bevelPlusToolScript"; // defines bevelPlusToolSetup proc setOptionVars (int $forceFactorySettings) { if ($forceFactorySettings || !`optionVar -exists illustratorCurvesType`) { optionVar -intValue illustratorCurvesType 1; // default is bevel } bevelPlusSetOptionVars($forceFactorySettings); } // // Procedure Name: // performCreateIllustratorCurves // // Description: // Perform the illustratorCurves command using the corresponding // option values. This command will also display option box dialog. // // Input Arguments: // 0 - Execute the command. // 1 - Show the option box dialog. // // Return Value: // None // global proc performCreateIllustratorCurves(int $action) { switch ($action) { case 0: setOptionVars(false); string $open = (uiRes("m_performCreateIllustratorCurves.kOpen")); fileBrowser("illustratorFileCB", $open, "Adobe(R) Illustrator(R)", 0); break; case 1: performCreateIllustratorCurvesOptions(); break; } } global proc illustratorFileCB(string $filename, string $fileType) { if (`window -ex projectViewerWindow`) { window -e -vis false projectViewerWindow; } int $curvesType = 1; setOptionVars( 0 ); if (`optionVar -exists illustratorCurvesType`) { $curvesType = `optionVar -q illustratorCurvesType`; } // get the global history flag value int $doHistory = `constructionHistory -q -tgl`; if ($curvesType == 0) { int $historyOnCurvesNeeded = 0; string $cmd = "illustratorCurves -ch " + $historyOnCurvesNeeded + " -ifn \"" + $filename + "\""; if ( catch( $textDag = evalEcho($cmd) ) ) { // if command failed then no need to continue since nothing was // created return; } if( ! $doHistory ) { delete $textDag[0]; } } else if ($curvesType == 1) { illustratorCurvesBevel($filename); } } // // Procedure Name: // makeIllustratorCurvesCallback // // Description: // Update the option values with the current state of the option box UI. // // Input Arguments: // parent - Top level parent layout of the option box UI. Required so // that UI object names can be successfully resolved. // // doIt - Whether the command should execute. // // Return Value: // None. // global proc makeIllustratorCurvesCallback(string $parent, int $doIt) { setParent $parent; // Set the optionVar's from the control values, and then perform the // command optionVar -intValue illustratorCurvesType (`radioButtonGrp -q -sl illustratorCreateTypeBtn` - 1); nurbsToPolyCallback( $parent, 0 ); bevelPlusCallback( $parent, 0, "" ); // no tool if ($doIt) { performCreateIllustratorCurves 0; addToRecentCommandQueue "performCreateIllustratorCurves 0" "createIllustratorCurves"; } } // // Procedure Name: // illustratorCurvesTabBasic // // Description: // Fill the contents of the option box for illustratorCurves command. // // Input Arguments: // The name of the parent layout. // // Return Value: // None. // global proc illustratorCurvesTabBasic(string $parent) { setParent $parent; string $tabForm = `columnLayout -adjustableColumn true`; radioButtonGrp -nrb 2 -label (uiRes("m_performCreateIllustratorCurves.kType")) -label1 (uiRes("m_performCreateIllustratorCurves.kCurves")) -label2 (uiRes("m_performCreateIllustratorCurves.kBevel")) -cc1 "tabLayout -e -st illustratorCurveOptionsNo illustratorCurveOptions" -cc2 "tabLayout -e -st illustratorCurveOptionsBevel illustratorCurveOptions" illustratorCreateTypeBtn; separator; tabLayout -tabsVisible false illustratorCurveOptions; columnLayout illustratorCurveOptionsNo; setParent ..; string $par = `columnLayout illustratorCurveOptionsOK`; nurbsToPolyAddOptions $par; setParent ..; string $par2 = `columnLayout illustratorCurveOptionsBevel`; setParent $par2; createBevelBasicOptions; setParent ..; setParent ..; } // // Procedure Name: // performCreateIllustratorCurvesOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // global proc performCreateIllustratorCurvesOptions() { setOptionVars( 0 ); string $commandName = "makeIllustratorCurves"; // Build the option box actions. // string $callback = ($commandName + "Callback"); string $setup = ($commandName + "Setup"); // Step 1: Get the option box. // ============================ string $layout = getOptionBox(); setParent $layout; // Step 2: Pass the command name to the option box. // ================================================= setOptionBoxCommandName($commandName); // Step 3: Activate the default UI template. // ========================================== setUITemplate -pushTemplate DefaultTemplate; // Step 4: Create option box contents. // =================================== // Turn on the wait cursor. // waitCursor -state 1; tabLayout -scr true -tv false; string $parent = `columnLayout -adjustableColumn 1`; illustratorCurvesTabBasic $parent; // Turn off the wait cursor. // waitCursor -state 0; // Step 5: Deactivate the default UI template. // =========================================== // setUITemplate -popTemplate; // Step 6: Customize the buttons. // ============================== // 'Apply' button. // string $applyBtn = getOptionBoxApplyBtn(); button -edit -label (uiRes("m_performCreateIllustratorCurves.kCreate")) -command ($callback + " " + $parent + " " + 1) $applyBtn; // 'Save' button. // string $saveBtn = getOptionBoxSaveBtn(); button -edit -command ($callback + " " + $parent + " " + 1 + "; hideOptionBox") $saveBtn; // 'Reset' button. // string $resetBtn = getOptionBoxResetBtn(); button -edit -command ($setup + " " + $parent + " " + 1) $resetBtn; // Step 7: Set the option box title. // ================================= // string $title = (uiRes("m_performCreateIllustratorCurves.kAdobeIllustratorObjectOptions")); setOptionBoxTitle($title); // Step 8: Customize the 'Help' menu item text. // ============================================ // setOptionBoxHelpTag( "makeIllustratorCurves" ); // Step 9: Set the current values of the option box. // ================================================= // eval (($setup + " " + $parent + " " + 0)); // Step 10: Show the option box. // ============================= // showOptionBox(); } // // Procedure Name: // makeIllustratorCurvesSetup // // Description: // Update the state of the option box UI to reflect the illustratorCurves // option values. // // Input Arguments: // parent - Top level parent layout of the option box UI. // Required so that UI object names can be // successfully resolved. // // forceFactorySettings - Whether the option values should be set to // default values. // // Return Value: // None. // global proc makeIllustratorCurvesSetup(string $parent, int $forceFactorySettings) { // Retrieve the option settings // setOptionVars($forceFactorySettings); setParent $parent; // Query the optionVar's and set the values into the controls int $localIntValue; string $localStringValue; $localIntValue = `optionVar -q illustratorCurvesType`; radioButtonGrp -e -sl ($localIntValue+1) illustratorCreateTypeBtn; if ( $localIntValue == 0 ) { tabLayout -e -st illustratorCurveOptionsNo illustratorCurveOptions; } else if ( $localIntValue == 1 ) { tabLayout -e -st illustratorCurveOptionsBevel illustratorCurveOptions; } nurbsToPolySetup( $parent, $forceFactorySettings ); bevelPlusBasicSetup( $parent, $forceFactorySettings, "" ); // no tool setup } // // Procedure Name: // illustratorCurvesBevel // // Description: // Create Adobe(R) Illustrator(R) objects with history feeding into bevel node // // Input Arguments: // filename - Input Adobe(R) Illustrator(R) file name // // Return Value: // None. // global proc illustratorCurvesBevel(string $filename) { setOptionVars( false ); // create Adobe(R) Illustrator(R) node and pass in file name value string $illustratorNode = evalEcho("createNode makeIllustratorCurves -n \"illustratorForBevel#\""); evalEcho("setAttr -type \"string\" " + $illustratorNode + ".illustratorFilename \"" + $filename + "\";"); // create bevel node and the two profile curves string $bevelNode = evalEcho("createNode bevelPlus"); string $innerStyleCurveNode = evalEcho("createNode styleCurve -n \"innerStyleCurve#\""); string $outerStyleCurveNode = evalEcho("createNode styleCurve -n \"outerStyleCurve#\""); // set style curve attributes int $outerBevelCurve = `optionVar -q outerStyleBevelCurve`; evalEcho("setAttr " + $outerStyleCurveNode + ".style " + $outerBevelCurve + ";"); int $sameAsOuter = `optionVar -q innerStyleSameAsOuter`; if($sameAsOuter) { evalEcho("setAttr " + $innerStyleCurveNode + ".style " + $outerBevelCurve + ";"); } else { int $innerBevelCurve = `optionVar -q innerStyleBevelCurve`; evalEcho("setAttr " + $innerStyleCurveNode + ".style " + $innerBevelCurve + ";"); } // get bevel attributes float $bevelPlusWidth = `optionVar -q bevelPlusWidth` ; float $bevelPlusDepth = `optionVar -q bevelPlusDepth` ; float $bevelPlusExtrudeHt = `optionVar -q bevelPlusExtrudeHeight` ; int $bevelPlusCaps = `optionVar -q bevelPlusCaps` ; int $bevelPlusInsideCurves = `optionVar -q bevelPlusInsideCurves` ; int $bevelPlusSides = `optionVar -q bevelPlusNSides` ; float $tol = `optionVar -q bevelPlusTolerance` ; if( `optionVar -q bevelPlusUseGlobalTol` ) { $tol = `optionVar -q positionalTolerance`; } // and set bevel attributes evalEcho("setAttr " + $bevelNode + ".width " + $bevelPlusWidth + ";"); evalEcho("setAttr " + $bevelNode + ".depth " + $bevelPlusDepth + ";"); evalEcho("setAttr " + $bevelNode + ".extrudeDepth " + $bevelPlusExtrudeHt + ";"); evalEcho("setAttr " + $bevelNode + ".capSides " + $bevelPlusCaps + ";"); evalEcho("setAttr " + $bevelNode + ".numberOfSides " + $bevelPlusSides + ";"); evalEcho("setAttr " + $bevelNode + ".tolerance " + $tol + ";"); evalEcho("setAttr " + $bevelNode + ".bevelInside " + $bevelPlusInsideCurves + ";"); // Note: the tolerance attribute is only used for planarTrim when // the output of bevel is NURBS, so we do not need to set it here // normalsOutwards always true (for >=v7.0 files) evalEcho("setAttr " + $bevelNode + ".normalsOutwards true"); // get all the poly tessellation attributes int $pFormat = `optionVar -q bevelPlusPolyFormat`; int $pCount = `optionVar -q bevelPlusPolyCount`; int $pUseChordRatio = `optionVar -q bevelPlusPolyUseChordRatio`; float $pChordRatio = `optionVar -q bevelPlusPolyChordRatio`; int $pUseChordHeight = `optionVar -q bevelPlusPolyUseChordHeight`; float $pChordHeight = `optionVar -q bevelPlusPolyChordHeight`; int $pTypeU = `optionVar -q bevelPlusPolyTypeU`; int $pNumberU = `optionVar -q bevelPlusPolyNumberU`; int $pTypeV = `optionVar -q bevelPlusPolyTypeV`; int $pNumberV = `optionVar -q bevelPlusPolyNumberV`; // disable chord height settings. These settings cause the poly // mesh to have non-quad faces, which is undesirable and also // causes problems with bevel caps evalEcho("setAttr " + $bevelNode + ".polyOutUseChordHeight false"); evalEcho("setAttr " + $bevelNode + ".polyOutUseChordHeightRatio false"); evalEcho("setAttr " + $bevelNode + ".orderedCurves true"); // create final output mesh node string $meshNode = evalEcho("createNode mesh"); string $surfaceNode[] = `listRelatives -p $meshNode`; // connect all inputs to bevel node, including the array of curves from the text node string $cmd; $cmd += ("connectAttr " + $illustratorNode + ".outputCurves " + $bevelNode + ".inputCurves;\n"); $cmd += ("connectAttr " + $illustratorNode + ".count " + $bevelNode + ".count;\n"); $cmd += ("connectAttr " + $illustratorNode + ".position " + $bevelNode + ".position;\n"); $cmd += ("connectAttr " + $innerStyleCurveNode + ".outCurve " + $bevelNode + ".innerStyleCurve;\n"); $cmd += ("connectAttr " + $outerStyleCurveNode + ".outCurve " + $bevelNode + ".outerStyleCurve;\n"); // connect the bevel node to the final mesh $cmd += ("connectAttr " + $bevelNode + ".outputPoly " + $meshNode + ".inMesh;\n"); // connect the final mesh to the initial shading group $cmd += ("sets -edit -forceElement initialShadingGroup " + $meshNode + ";\n"); // and position the pivot appropriately // $cmd += ("CenterPivot;\n"); // select the poly object for cleanup $cmd += ("select " + $meshNode + ";\n"); // do other bevellish stuff (from performBevelPlus) string $errorCheck = " int $intArr[] = `polyEvaluate -v`; "; $errorCheck += "int $numVerts = 0; "; $errorCheck += "if (size($intArr) > 0) $numVerts = $intArr[0]; "; // delete created nodes, if bevel is not formed string $errorCheckMsg = (uiRes("m_performCreateIllustratorCurves.kErrorFailedToCreateBevel")); $errorCheck += "if ($numVerts == 0) { catch(error(\""; $errorCheck += $errorCheckMsg + "\")); "; $errorCheck += "delete " + $illustratorNode + " " + $bevelNode + " " + $surfaceNode[0] + " "; $errorCheck += $innerStyleCurveNode + " " + $outerStyleCurveNode + " ; "; $errorCheck += "} "; $errorCheck += "else if ($numVerts > 0) { "; $cmd += $errorCheck; //select all faces with 0 map area and more than 4 sides - these //will be the caps //see polyCleanupArgList.mel for a complete list of the arguments $cmd = $cmd + "polyCleanupArgList 3 { \"0\",\"2\",\"1\",\"0\","; $cmd = $cmd + "\"1\",\"0\",\"0\",\"0\",\"0\",\"1e-005\",\"0\",\""; $cmd = $cmd + "1e-005\",\"1\",\"0\",\"0\",\"-1\",\"0\" };\n"; $cmd = $cmd + "polyProjection -ch 1 -type Planar -ibd off -icx 0.5 "; $cmd = $cmd + "-icy 0.5 -ra 0 -isu 1 -isv 1 -md z ;\n"; $cmd = $cmd + "select -r `listConnections -t \"shape\"`;\n"; $cmd = $cmd + "};\n"; // finally switch back to object mode $cmd = $cmd + "changeSelectMode -object;\n"; // let it rip evalEcho $cmd; // leave Adobe(R) Illustrator(R) node selected on the assumption the user will want // to work with the Adobe(R) Illustrator(R) attributes first if (`exists $illustratorNode`) { select $illustratorNode; } return; }