diff --git a/docs/README.md b/docs/README.md index 6a3ebd17..6bd3181f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -100,7 +100,6 @@ If you want, you can now delete the downloaded/extracted files (as they have alr In case you need/want to manually install the scripts. It's also a pretty straightforward process. -
  1. Close Maya (in case it's opened).
  2. Download the latest release (or clone this repository).
  3. @@ -354,7 +353,6 @@ In case you need/want to manually install the scripts. It's easy..
  4. PATCH: Small changes used to fix issues or improve existing scripts.
  5. -


    @@ -491,7 +489,6 @@ with the provided prefix "Left Side Tag".

    -

    GT World Space Baker

    @@ -954,8 +951,6 @@ If painting the skin weights with "ngSkinTools" (third party plugin) you might h
    2. If the character is found, the FK/IK buttons will light up according to the current state.
    3. Use the desired function to animate or pose your character.

    - -

    FK/IK Tab:

    -

    GT Morphing Attributes

    @@ -1141,7 +1135,6 @@ If painting the skin weights with "ngSkinTools" (third party plugin) you might h GT Morphing Attributes GUI -

    This script automates the creation of attributes used to drive blend shapes.

    Load Morphing Object: @@ -1455,7 +1448,8 @@ Added attributes don't affect your attribute holder in any way, it's up to you d

    Moves the selected objects to the center of the grid (0,0,0) origin point.

    Reset Transforms

    -

    Resets translate, rotate and scale back to zero. For example, you can select all controls of a character and reset its pose.

    +

    Resets translate, rotate and scale back to zero. For example, you can select all controls of a character and reset its pose. +
    This pose will not reset translate for joints.

    Reset Joints Display

    Resets the visibility of all joints. It sets the radius of all joints to one. (Unless the channel is locked) and sets the visibility to "On". It also changes the global joint display scale (multiplier) back to one.

    @@ -1653,7 +1647,6 @@ Do not change the resolution of the image file or crop the image or it might not
    -

    GT Render Calculator

    @@ -1674,7 +1667,6 @@ Do not change the resolution of the image file or crop the image or it might not
    The number of computers rendering the same job.
    The render time may vary per machine based on the available setup.

    -
    diff --git a/mel-scripts/gt_tools_menu.mel b/mel-scripts/gt_tools_menu.mel index 782dc07c..16fb5978 100644 --- a/mel-scripts/gt_tools_menu.mel +++ b/mel-scripts/gt_tools_menu.mel @@ -72,23 +72,23 @@ // Added "gt_sphere_types.py" to the uninstaller. // Created "gt_check_updates.py" to better handle updates. // Changed the "Check For Updates" button in the main menu to call "gt_check_updates.py" instead of a link. -// Fixed issue where unloaded references wouldn't import when using "gtu_import_references" (#15) -// Added"gtu_remove_references" (#16) +// Fixed issue where unloaded references wouldn't import when using "references_import" (#15) +// Added"references_remove" (#16) // Added a missing reload to "gt_tools_menu.mel" // // 1.5.5 // Started storing changelog directly on github. Everything here is now about this menu specifically. // https://github.com/TrevisanGMW/gt-tools/releases -// Added "gtu_convert_bif_to_mesh" +// Added "convert_bif_to_mesh" // // 1.5.6 -// Moved "gtu_convert_bif_to_mesh" to the modeling submenu +// Moved "convert_bif_to_mesh" to the modeling submenu // Added "gt_color_manager" // // 1.5.7 // Renamed "gt_create_ctrl_auto_fk" to "gt_create_auto_fk" // Renamed "gt_create_ctrl_simple_IK_leg" to "gt_create_ik_leg" -// Added "gtu_delete_nucleus_nodes" +// Added "delete_nucleus_nodes" // // 1.5.8 // Added "gt_startup_booster" @@ -116,10 +116,10 @@ // Updated Make IK Stretchy // // 1.6.5 -// Added gtu_uniform_jnt_label_toggle to GT Utilities +// Added toggle_uniform_jnt_label to GT Utilities // // 1.6.6 -// Updated icons for "GTU Uniform LRA Toggle" and "GTU Uniform Label Toggle" to avoid MacOS/Linux compatibility issues +// Updated icons for "Uniform LRA Toggle" and "Uniform Label Toggle" to avoid MacOS/Linux compatibility issues // // 1.6.7 // Added Add Sine Attributes @@ -132,7 +132,7 @@ // No changes to this menu, only version // // 1.7.1 -// Added GTU Select Non-unique Objects +// Added Select Non-unique Objects // // 1.7.2 // Updated Scripts so they are compatible with Python 3 (Maya 2022+) @@ -142,7 +142,7 @@ // Added "gt_transfer_uvs" // // 1.7.8 -// Added "gtu_full_hud_toggle" +// Added "toggle_full_hud" // // 1.7.10 // Added optionVar "gt_check_for_updates_interval_days" and set it to 15 in case it doesn't exist (default value) @@ -151,7 +151,7 @@ // Added World Space Baker // // 1.7.22 -// Added "gtu_generate_udim_previews()" +// Added "generate_udim_previews()" // // 1.7.23 - 4 2022-07-13 // Renamed Auto Biped Rigger to Biped Auto Rigger @@ -299,13 +299,13 @@ menuItem -l "Curves" -sm true -to true -image "out_stroke.png"; menuItem -l ("Combine Curves") - -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'gtu_combine_curves')\");") + -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'curves_combine')\");") -ann ("Combine curves by moving all the shape objects inside one single transform.") -image "nurbsCurve.svg"; menuItem -l ("Separate Curves") - -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'gtu_separate_curves')\");") + -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'curves_separate')\");") -ann ("Separate curves by moving every shape object to their own separated transform.") -image "curveEditor.png"; @@ -328,18 +328,18 @@ menuItem -l "Modeling" -sm true -to true -image "mesh.svg"; //out_stroke.png -image "blinn.svg" ; - // GTU Functions + // GT Utility Functions menuItem -divider true ; menuItem -l ("Preview All UDIMs") - -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'gtu_generate_udim_previews')\");") + -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'generate_udim_previews')\");") -ann ("Generates UDIM previews for all file nodes.") -image "textureToGeom.png"; menuItem -l ("Convert Bif to Mesh") - -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'gtu_convert_bif_to_mesh')\");") + -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'convert_bif_to_mesh')\");") -ann ("Converts Bifrost Geometry into Maya Geometry (Mesh). If used with volume or particles the output will be empty.") -image "nurbsToPolygons.png"; @@ -348,13 +348,13 @@ menuItem -l "Modeling" -sm true -to true -image "mesh.svg"; //out_stroke.png menuItem -l ("Copy Material") - -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'gtu_copy_material')\");") + -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'material_copy')\");") -ann ("Copies material to clipboard.") -image "polyBakeSetAssign.png"; menuItem -l ("Paste Material") - -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'gtu_paste_material')\");") + -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'material_paste')\");") -ann ("Pastes material from clipboard.") -image "polyBakeSetEdit.png"; @@ -457,71 +457,79 @@ menuItem -l "Utilities" -sm true -to true -image "bsd-head.png"; menuItem -l ("Reload File") - -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'gtu_reload_file')\");") + -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'force_reload_file')\");") -ann ("Reopens the opened file (to revert back any changes done to the file since it was first opened)") -image "openLoadGeneric.png"; menuItem -l ("Resource Browser") - -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'gtu_open_resource_browser')\");") + -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'open_resource_browser')\");") -ann ("Opens Maya's Resource Browser. A good way to find icons or elements you may want to use.") -image "bsd-head.png"; menuItem -l ("Unlock Default Channels") - -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'gtu_unlock_default_channels')\");") + -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'unlock_default_channels')\");") -ann ("Unlocks the default channels of the selected objects. (Default channels : Translate, Rotate, Scale and Visibility)") -image "Lock_OFF_grey.png"; menuItem -l ("Unhide Default Channels") - -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'gtu_unhide_default_channels')\");") + -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'unhide_default_channels')\");") -ann ("Unhides the default channels of the selected objects. (Default channels : Translate, Rotate, Scale and Visibility)") -image "RS_filter_list.png"; menuItem -l ("Uniform LRA Toggle") - -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'gtu_uniform_lra_toggle')\");") + -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'toggle_uniform_lra')\");") -ann ("Makes the visibility of the Local Rotation Axis uniform among the selected objects according to the current state of the majority of them.") -image "srt.png"; menuItem -l ("Uniform Joint Label Toggle") - -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'gtu_uniform_jnt_label_toggle')\");") + -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'toggle_uniform_jnt_label')\");") -ann ("Makes the visibility of the joint labels uniform according to the current state of the majority of them.") -image "QR_xRay.png"; - - menuItem - -l ("Convert Joints to Mesh") - -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'gtu_convert_joints_to_mesh')\");") - -ann ("Converts joints to mesh. (Helpful when sending references to other applications)") - -image "HIKCharacterToolSkeleton.png"; - - + menuItem -l ("Select Non-Unique Objects") - -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'gtu_select_non_unique_objects')\");") + -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'select_non_unique_objects')\");") -ann ("Selects all objects with the same short name. (non-unique objects)") -image "gotoLine.png"; - menuItem - -l ("Full HUD Toggle") - -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'gtu_full_hud_toggle')\");") + menuItem + -l ("Complete HUD Toggle") + -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'toggle_full_hud')\");") -ann ("Toggles most of the Heads-Up Display (HUD) options according to the state of the majority of them. (Keeps default elements intact when toggling it off)") -image "channelBox.png"; + + // Convert + menuItem -divider true; + + menuItem + -l ("Convert Joints to Mesh") + -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'convert_joints_to_mesh')\");") + -ann ("Converts joints to mesh. (Helpful when sending references to other applications)") + -image "HIKCharacterToolSkeleton.png"; + + menuItem + -l ("Convert to Locators") + -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'convert_to_locators')\");") + -ann ("Converts transforms to locators. Function doesn't affect selected objects.") + -image "locator.svg"; // References menuItem -divider true ; menuItem -l ("Import References") - -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'gtu_import_references')\");") + -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'references_import')\");") -ann ("Imports all references.") -image "reference.svg"; menuItem -l ("Remove References") - -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'gtu_remove_references')\");") + -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'references_remove')\");") -ann ("Removes all references.") -image "referenceProxy.png"; @@ -531,19 +539,19 @@ menuItem -l "Utilities" -sm true -to true -image "bsd-head.png"; menuItem -l ("Move Pivot to Top") - -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'gtu_move_pivot_to_top')\");") + -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'move_pivot_top')\");") -ann ("Moves pivot point to the top of the boundingbox of every selected object.") -image "moveLayerUp.png"; menuItem -l ("Move Pivot to Base") - -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'gtu_move_pivot_to_base')\");") + -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'move_pivot_base')\");") -ann ("Moves pivot point to the base of the boundingbox of every selected object.") -image "moveLayerDown.png"; menuItem -l ("Move Object to Origin") - -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'gtu_move_to_origin')\");") + -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'move_to_origin')\");") -ann ("Moves selected objects to origin according to their pivot point.") -image "grid.svg"; @@ -552,19 +560,19 @@ menuItem -l "Utilities" -sm true -to true -image "bsd-head.png"; menuItem -l ("Reset Transforms") - -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'gtu_reset_transforms')\");") + -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'reset_transforms')\");") -ann ("Reset transforms. It checks for incomming connections, then set the attribute to 0 if there are none. Currently affects Joints, meshes and transforms. (Only Rotation)") -image "CenterPivot.png"; menuItem -l ("Reset Joints Display") - -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'gtu_reset_joint_sizes')\");") + -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'reset_joint_display')\");") -ann ("Resets the radius attribute back to one in all joints, then changes the global multiplier (jointDisplayScale) back to one.") -image "kinJoint.png"; menuItem -l ("Reset \"persp\" Camera") - -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'gtu_reset_persp_shape_attributes')\");") + -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'reset_persp_shape_attributes')\");") -ann ("If persp camera exists (default camera), reset its attributes.") -image "camera.svg"; @@ -574,27 +582,33 @@ menuItem -l "Utilities" -sm true -to true -image "bsd-head.png"; menuItem -l ("Delete Namespaces") - -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'gtu_delete_namespaces')\");") + -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'delete_namespaces')\");") -ann ("Deletes all namespaces in the scene.") -image "renamePreset.png"; menuItem -l ("Delete Display Layers") - -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'gtu_delete_display_layers')\");") + -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'delete_display_layers')\");") -ann ("Deletes all display layers.") -image "displayLayer.svg"; menuItem -l ("Delete Nucleus Nodes") - -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'gtu_delete_nucleus_nodes')\");") + -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'delete_nucleus_nodes')\");") -ann ("Deletes all nodes related to particles. (Nucleus, nHair, nCloth, nConstraints, Emitter, etc...)") -image "nParticle.svg"; menuItem -l ("Delete Keyframes") - -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'gtu_delete_keyframes')\");") + -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'delete_keyframes')\");") -ann ("Deletes all nodes of the type \"animCurveTA\" (keyframes).") -image "keyIntoclip.png"; + + menuItem + -l ("Delete Unused Nodes") + -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'delete_unused_nodes')\");") + -ann ("Deletes unused nodes.") + -image "nodeGrapherRemoveNodes.png"; setParent -menu ".." ; @@ -670,7 +684,7 @@ menuItem -l "Miscellaneous" -sm true -to true -image "bin.png"; -image "defaultOutliner.svg"; menuItem -l "About" - -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'gtu_build_gui_about_gt_tools')\");") + -c ("python(\"gt_tools.execute_script('gt_maya_utilities', 'build_gui_about_gt_tools')\");") -ann ("Opens about menu.") -image "help.png" ; diff --git a/python-scripts/__init__.py b/python-scripts/__init__.py index 710628fd..00372715 100644 --- a/python-scripts/__init__.py +++ b/python-scripts/__init__.py @@ -6,7 +6,7 @@ import os # Global Vars -PACKAGE_VERSION = "2.2.3" +PACKAGE_VERSION = "2.3.0" # Initial Setup - Add path and initialize logger if __name__ != '__main__': diff --git a/python-scripts/gt_maya_utilities.py b/python-scripts/gt_maya_utilities.py index 7e6e6b06..73ed5979 100644 --- a/python-scripts/gt_maya_utilities.py +++ b/python-scripts/gt_maya_utilities.py @@ -2,83 +2,135 @@ GT Maya Utilities github.com/TrevisanGMW - 2020-09-13 - 1.1 - 2020-10-17 + - 2020-10-17 Added move pivot to bottom/top Added copy/paste material Added move to origin - 1.2 - 2020-10-21 + - 2020-10-21 Updated reset transform to better handle translate Added Uniform LRA Toggle Changed the order of the functions to match the menu - 1.3 - 2020-11-11 - Updates "gtu_import_references" to better handle unloaded references - Added "gtu_remove_references" - Added "gtu_combine_curves" - Added "gtu_separate_curves" + - 2020-11-11 + Updates "references_import" to better handle unloaded references + Added "references_remove" + Added "curves_combine" + Added "curves_separate" - 1.4 - 2020-11-13 + - 2020-11-13 Updated combine and separate functions to work with Bezier curves - 1.5 - 2020-11-14 - Added "gtu_convert_bif_to_mesh" + - 2020-11-14 + Added "convert_bif_to_mesh" - 1.6 - 2020-11-16 - Added "gtu_delete_nucleus_nodes" - Updated "gtu_delete_display_layers" to have inView feedback - Updated "gtu_delete_keyframes" to have inView feedback + - 2020-11-16 + Added "delete_nucleus_nodes" + Updated "delete_display_layers" to have inView feedback + Updated "delete_keyframes" to have inView feedback - 1.7 - 2020-11-22 + - 2020-11-22 Updated about window text - 1.8 - 2020-12-03 + - 2020-12-03 Changed the background color for the title in the "About" window Changed the order of a few functions Added function to unlock/unhide default channels - 1.9 - 2021-01-05 + - 2021-01-05 Added Uniform Joint Label Toggle - 2.0 - 2021-02-05 + - 2021-02-05 Added "Select Non-Unique Objects" Utility - 2.1 - 2021-05-12 + - 2021-05-12 Made script compatible with Python 3 (Maya 2022+) Added refresh to combine curves function as they were not automatically updating after re-parenting shapes - 2.2 - 2021-06-25 + - 2021-06-25 Updated bif to mesh to work with newer versions of bifrost Updated bif to mesh to delete empty meshes (objects that weren't geometry) Added function to delete all locators - 2.2 - 2021-10-25 + - 2021-10-25 Updated bif to mesh to work with newer versions of bifrost Updated bif to mesh to delete empty meshes (objects that weren't geometry) Added function to delete all locators - 2.3 - 2021-10-10 + - 2021-10-10 Created Full HUD Toggle - 2.4 - 2021-10-10 + - 2021-10-10 Fixed gtu full hud toggle as it would return an error if xGen was not loaded - 2.5 - 2022-01-04 + - 2022-01-04 Renamed script to "gt_maya_utilities" - 2.6 - 2022-01-04 + - 2022-01-04 Renamed script to "gt_maya_utilities" - 2.7 - 2022-06-29 + - 2022-06-29 Added string to notepad (txt) Renamed functions + - 2022-07-30 + Removed version (only dates now) + Made inView messages unique + Removed prefix "gtu_" from functions + - Added or updated feedback for: + - Force Reload File + - Unlock Default Channels + - Unhide Default Channels + - Uniform LRA Toggle + - Full Hud Toggle + - Select Non-Unique Objects + - Import References + - Remove References + + - Added validation + - Uniform LRA Toggle + - Uniform Joint Label Toggle + - Reset Transforms + + - 2022-07-31 + - Added or updated feedback for: + - Generate UDIM Previews + - Move Pivot to Top + - Move Pivot to Base + - Move Object To Origin + + - Added validation + - Move Pivot to Top + - Move Pivot to Base + - Move Object To Origin + + - 2022-08-01 + - Added "Delete Unused Nodes" + - Added "Convert to Locators" + - Fixed "Reset Transforms" so it works with multiple objects again + - Added scale to "Reset "persp" Camera" + - Added or updated feedback for: + - Reset Transforms + - Reset Joint Display + - Reset "persp" Camera + - Combine Curves + - Separate Curves + + - Added validation + - Reset Joint Display + - Reset Transforms + - Reset Joint Display + + = Added more validation + - Move Pivot to Top + - Move Pivot to Base + - Move Object To Origin + - Combine Curves + - Separate Curves + + TODO: - Add proper error handling to all functions through logging New functions: - Reset Display Type and Color - Find/Rename non-unique names - Enforce unique names - Remove Custom Colors - select object types, outliner or viewport. Use string to determine a list of types Assign lambert to everything function (Maybe assign to object missing shaders) Add Unlock all attributes Add unhide attributes (provide list?) @@ -98,6 +150,7 @@ import maya.cmds as cmds import maya.mel as mel import logging +import random import sys from maya import OpenMayaUI as OpenMayaUI @@ -120,17 +173,17 @@ ''' ____________________________ General Functions ____________________________''' -def gtu_reload_file(): +def force_reload_file(): """ Reopens the opened file (to revert any changes done to the file) """ if cmds.file(query=True, exists=True): # Check to see if it was ever saved file_path = cmds.file(query=True, expandName=True) if file_path is not None: cmds.file(file_path, open=True, force=True) else: - cmds.warning('File was never saved.') + cmds.warning('Unable to force reload. File was never saved.') -def gtu_open_resource_browser(): +def open_resource_browser(): """ Opens Maya's Resource Browser """ try: import maya.app.general.resourceBrowser as resourceBrowser @@ -139,12 +192,13 @@ def gtu_open_resource_browser(): logger.debug(str(e)) -def gtu_unlock_default_channels(): +def unlock_default_channels(): """ Unlocks Translate, Rotate, Scale for the selected objects """ function_name = 'GTU Unlock Default Channels' errors = '' cmds.undoInfo(openChunk=True, chunkName=function_name) # Start undo chunk selection = cmds.ls(selection=True, long=True) + selection_short = cmds.ls(selection=True) unlocked_counter = 0 try: for obj in selection: @@ -171,21 +225,29 @@ def gtu_unlock_default_channels(): finally: cmds.undoInfo(closeChunk=True, chunkName=function_name) - message = '' + str(unlocked_counter) + ' ' + in_view_message = '<' + str(random.random()) + '>' + in_view_message += '' + str(unlocked_counter) + ' ' is_plural = 'objects had their' if unlocked_counter == 1: is_plural = 'object had its' - message += is_plural + ' default channels unlocked.' + description = ' default channels unlocked.' + in_view_message += is_plural + description - cmds.inViewMessage(amg=message, pos='botLeft', fade=True, alpha=.9) + cmds.inViewMessage(amg=in_view_message, pos='botLeft', fade=True, alpha=.9) + + if unlocked_counter == 1: + sys.stdout.write('\n"' + str(selection_short[0]) + '" ' + is_plural + description) + else: + sys.stdout.write('\n' + str(unlocked_counter) + ' ' + is_plural + description) -def gtu_unhide_default_channels(): - """ Unhides Translate, Rotate, Scale for the selected objects """ +def unhide_default_channels(): + """ Un-hides Translate, Rotate, Scale for the selected objects """ function_name = 'GTU Unhide Default Channels' errors = '' cmds.undoInfo(openChunk=True, chunkName=function_name) # Start undo chunk selection = cmds.ls(selection=True, long=True) + selection_short = cmds.ls(selection=True) unlocked_counter = 0 try: for obj in selection: @@ -212,16 +274,22 @@ def gtu_unhide_default_channels(): finally: cmds.undoInfo(closeChunk=True, chunkName=function_name) - message = '' + str(unlocked_counter) + ' ' + in_view_message = '<' + str(random.random()) + '>' + in_view_message += '' + str(unlocked_counter) + ' ' is_plural = 'objects had their' if unlocked_counter == 1: is_plural = 'object had its' - message += is_plural + ' default channels made visible.' + description = ' default channels made visible.' + in_view_message += is_plural + description - cmds.inViewMessage(amg=message, pos='botLeft', fade=True, alpha=.9) + cmds.inViewMessage(amg=in_view_message, pos='botLeft', fade=True, alpha=.9) + if unlocked_counter == 1: + sys.stdout.write('\n"' + str(selection_short[0]) + '" ' + is_plural + description) + else: + sys.stdout.write('\n' + str(unlocked_counter) + ' ' + is_plural + description) -def gtu_uniform_lra_toggle(): +def toggle_uniform_lra(): """ Makes the visibility of the Local Rotation Axis uniform among the selected objects according to the current state of the majority of them. @@ -231,10 +299,14 @@ def gtu_uniform_lra_toggle(): cmds.undoInfo(openChunk=True, chunkName=function_name) try: errors = '' - selection = cmds.ls(selection=True) + selection = cmds.ls(selection=True, long=True) or [] + if not selection: + cmds.warning('Select at least one object and try again.') + return inactive_lra = [] active_lra = [] + operation_result = 'off' for obj in selection: try: @@ -250,6 +322,7 @@ def gtu_uniform_lra_toggle(): for obj in inactive_lra: try: cmds.setAttr(obj + '.displayLocalAxis', 1) + operation_result = 'on' except Exception as e: errors += str(e) + '\n' elif len(inactive_lra) == 0: @@ -262,6 +335,7 @@ def gtu_uniform_lra_toggle(): for obj in inactive_lra: try: cmds.setAttr(obj + '.displayLocalAxis', 1) + operation_result = 'on' except Exception as e: errors += str(e) + '\n' else: @@ -271,6 +345,12 @@ def gtu_uniform_lra_toggle(): except Exception as e: errors += str(e) + '\n' + in_view_message = '<' + str(random.random()) + '>' + in_view_message += 'LRA Visibility set to: ' + in_view_message += '' + operation_result + '' + cmds.inViewMessage(amg=in_view_message, pos='botLeft', fade=True, alpha=.9) + sys.stdout.write('\n' + 'Local Rotation Axes Visibility set to: "' + operation_result + '"') + if errors != '': print('#### Errors: ####') print(errors) @@ -281,7 +361,7 @@ def gtu_uniform_lra_toggle(): cmds.undoInfo(closeChunk=True, chunkName=function_name) -def gtu_uniform_jnt_label_toggle(): +def toggle_uniform_jnt_label(): """ Makes the visibility of the Joint Labels uniform according to the current state of the majority of them. """ @@ -294,6 +374,7 @@ def gtu_uniform_jnt_label_toggle(): inactive_label = [] active_label = [] + operation_result = 'off' for obj in joints: try: @@ -309,6 +390,7 @@ def gtu_uniform_jnt_label_toggle(): for obj in inactive_label: try: cmds.setAttr(obj + '.drawLabel', 1) + operation_result = 'on' except Exception as e: errors += str(e) + '\n' elif len(inactive_label) == 0: @@ -321,6 +403,7 @@ def gtu_uniform_jnt_label_toggle(): for obj in inactive_label: try: cmds.setAttr(obj + '.drawLabel', 1) + operation_result = 'on' except Exception as e: errors += str(e) + '\n' else: @@ -330,6 +413,19 @@ def gtu_uniform_jnt_label_toggle(): except Exception as e: errors += str(e) + '\n' + if len(joints) > 0: + in_view_message = '<' + str(random.random()) + '>' + in_view_message += 'Joint Label Visibility set to: ' + in_view_message += '' + operation_result + in_view_message += '' + cmds.inViewMessage(amg=in_view_message, pos='botLeft', fade=True, alpha=.9) + sys.stdout.write('\n' + 'Joint Label Visibility set to: "' + operation_result + '"') + else: + unique_message = '<' + str(random.random()) + '>' + message = 'No joints found in the scene.' + cmds.inViewMessage(amg=unique_message + message, pos='botLeft', fade=True, alpha=.9) + sys.stdout.write('\n' + message) + if errors != '': print('#### Errors: ####') print(errors) @@ -341,7 +437,146 @@ def gtu_uniform_jnt_label_toggle(): cmds.undoInfo(closeChunk=True, chunkName=function_name) -def gtu_select_non_unique_objects(): +def toggle_full_hud(): + """ Toggles common HUD options so all the common ones are either active or inactive """ + hud_current_state = {} + + # 1 - Animation Details + hud_current_state['animationDetailsVisibility'] = int(mel.eval('optionVar -q animationDetailsVisibility;')) + # 2 - Cache + try: + from maya.plugin.evaluator.CacheUiHud import CachePreferenceHud + hud_current_state['CachePreferenceHud'] = int(CachePreferenceHud().get_value() or 0) + except Exception as e: + logger.debug(str(e)) + hud_current_state['CachePreferenceHud'] = 0 + # 3 - Camera Names + hud_current_state['cameraNamesVisibility'] = int(mel.eval('optionVar -q cameraNamesVisibility;')) + # 4 - Caps Lock + hud_current_state['capsLockVisibility'] = int(mel.eval('optionVar -q capsLockVisibility;')) + # 5 - Current Asset + hud_current_state['currentContainerVisibility'] = int(mel.eval('optionVar -q currentContainerVisibility;')) + # 6 - Current Frame + hud_current_state['currentFrameVisibility'] = int(mel.eval('optionVar -q currentFrameVisibility;')) + # 7 - Evaluation + hud_current_state['evaluationVisibility'] = int(mel.eval('optionVar -q evaluationVisibility;')) + # 8 - Focal Length + hud_current_state['focalLengthVisibility'] = int(mel.eval('optionVar -q focalLengthVisibility;')) + # 9 - Frame Rate + hud_current_state['frameRateVisibility'] = int(mel.eval('optionVar -q frameRateVisibility;')) + # 10 - HumanIK Details + hud_current_state['hikDetailsVisibility'] = int(mel.eval('optionVar -q hikDetailsVisibility;')) + # 11 - Material Loading Details + hud_current_state['materialLoadingDetailsVisibility'] = int( + mel.eval('optionVar -q materialLoadingDetailsVisibility;')) + # 12 - Object Details + hud_current_state['objectDetailsVisibility'] = int(mel.eval('optionVar -q objectDetailsVisibility;')) + # 13 - Origin Axis - Ignored as non-hud element + # hud_current_state['originAxesMenuUpdate'] = mel.eval('optionVar -q originAxesMenuUpdate;') + # 14 - Particle Count + hud_current_state['particleCountVisibility'] = int(mel.eval('optionVar -q particleCountVisibility;')) + # 15 - Poly Count + hud_current_state['polyCountVisibility'] = int(mel.eval('optionVar -q polyCountVisibility;')) + # 16 - Scene Timecode + hud_current_state['sceneTimecodeVisibility'] = int(mel.eval('optionVar -q sceneTimecodeVisibility;')) + # 17 - Select Details + hud_current_state['selectDetailsVisibility'] = int(mel.eval('optionVar -q selectDetailsVisibility;')) + # 18 - Symmetry + hud_current_state['symmetryVisibility'] = int(mel.eval('optionVar -q symmetryVisibility;')) + # 19 - View Axis + hud_current_state['viewAxisVisibility'] = int(mel.eval('optionVar -q viewAxisVisibility;')) + # 20 - Viewport Renderer + hud_current_state['viewportRendererVisibility'] = int(mel.eval('optionVar -q viewportRendererVisibility;')) + # ------- Separator ------- + # 21 - In-view Messages + hud_current_state['inViewMessageEnable'] = int(mel.eval('optionVar -q inViewMessageEnable;')) + # 22 - In-view Editors + hud_current_state['inViewEditorVisible'] = int(mel.eval('optionVar -q inViewEditorVisible;')) + # Conditional - XGen Info + hud_current_state['xgenHUDVisibility'] = int(mel.eval('optionVar -q xgenHUDVisibility;')) + + # Check if toggle ON or OFF + toggle = True + count = 0 + for item_state in hud_current_state: + if hud_current_state.get(item_state): + count += 1 + # More than half is on, so OFF else ON (Default) + if count > len(hud_current_state) / 2: + toggle = False + + # Toggles non-standard hud elements + if toggle: + mel.eval('setAnimationDetailsVisibility(true)') + try: + from maya.plugin.evaluator.CacheUiHud import CachePreferenceHud + CachePreferenceHud().set_value(True) + except Exception as e: + logger.debug(str(e)) + mel.eval('setCameraNamesVisibility(true)') + mel.eval('setCapsLockVisibility(true)') + mel.eval('setCurrentContainerVisibility(true)') + mel.eval('setCurrentFrameVisibility(true)') + mel.eval('SetEvaluationManagerHUDVisibility(1)') + mel.eval('setFocalLengthVisibility(true)') + mel.eval('setFrameRateVisibility(true)') + if not hud_current_state.get('hikDetailsVisibility'): + cmds.ToggleHikDetails() + mel.eval('catchQuiet(setHikDetailsVisibility(true));') + mel.eval('ToggleMaterialLoadingDetailsHUDVisibility(true)') + mel.eval('setObjectDetailsVisibility(true)') + mel.eval('setParticleCountVisibility(true)') + mel.eval('setPolyCountVisibility(true)') + mel.eval('setSceneTimecodeVisibility(true)') + mel.eval('setSelectDetailsVisibility(true)') + mel.eval('setSymmetryVisibility(true)') + mel.eval('setViewAxisVisibility(true)') + mel.eval('setViewportRendererVisibility(true)') + mel.eval('catchQuiet(setXGenHUDVisibility(true));') + + if not hud_current_state.get('inViewMessageEnable'): + cmds.ToggleInViewMessage() + if not hud_current_state.get('inViewEditorVisible'): + cmds.ToggleInViewEditor() + else: + mel.eval('setAnimationDetailsVisibility(false)') + try: + from maya.plugin.evaluator.CacheUiHud import CachePreferenceHud + CachePreferenceHud().set_value(False) + except Exception as e: + logger.debug(str(e)) + mel.eval('setCurrentContainerVisibility(false)') + mel.eval('setCurrentFrameVisibility(false)') + mel.eval('SetEvaluationManagerHUDVisibility(0)') + mel.eval('setFocalLengthVisibility(false)') + mel.eval('setFrameRateVisibility(false)') + if hud_current_state.get('hikDetailsVisibility'): + cmds.ToggleHikDetails() + mel.eval('catchQuiet(setHikDetailsVisibility(false));') + mel.eval('catchQuiet(hikDetailsKeyingMode());') + mel.eval('ToggleMaterialLoadingDetailsHUDVisibility(false)') + mel.eval('setObjectDetailsVisibility(false)') + mel.eval('setParticleCountVisibility(false)') + mel.eval('setPolyCountVisibility(false)') + mel.eval('setSceneTimecodeVisibility(false)') + mel.eval('setSelectDetailsVisibility(false)') + mel.eval('setViewportRendererVisibility(false)') + mel.eval('catchQuiet(setXGenHUDVisibility(false));') + # Default states are preserved: camera names, caps lock, symmetry, view axis, in-view messages and in-view editor + print("?") + # Give feedback + operation_result = 'off' + if toggle: + operation_result = 'on' + in_view_message = '<' + str(random.random()) + '>' + in_view_message += 'Hud Visibility set to: ' + in_view_message += '' + operation_result + in_view_message += '' + cmds.inViewMessage(amg=in_view_message, pos='botLeft', fade=True, alpha=.9) + sys.stdout.write('\n' + 'Hud Visibility set to: "' + operation_result + '"') + + +def select_non_unique_objects(): """ Selects all non-unique objects (objects with the same short name) """ def get_short_name(full_name): @@ -373,23 +608,32 @@ def get_short_name(full_name): cmds.select(non_unique_transforms, r=True) if len(non_unique_transforms) > 0: - message = '' + str( - len(non_unique_transforms)) + ' non-unique objects were selected.' + in_view_message = '<' + str(random.random()) + '>' + in_view_message += '' + in_view_message += str(len(non_unique_transforms)) + ' non-unique objects were selected.' + message = '\n' + str(len(non_unique_transforms)) + ' non-unique objects were found in this scene. ' \ + 'Rename them to avoid conflicts.' else: - message = 'All objects seem to have unique names in this scene.' - cmds.inViewMessage(amg=message, pos='botLeft', fade=True, alpha=.9) + in_view_message = '<' + str(random.random()) + '>' + in_view_message += 'All objects seem to have unique names in this scene.' + message = 'No repeated names found in the scene.' + cmds.inViewMessage(amg=in_view_message, pos='botLeft', fade=True, alpha=.9) + sys.stdout.write(message) -def gtu_import_references(): +def references_import(): """ Imports all references """ errors = '' r_file = '' + refs = [] + refs_imported_counter = 0 try: - refs = cmds.ls(rf=True) + refs = cmds.ls(rf=True) or [] for i in refs: try: r_file = cmds.referenceQuery(i, f=True) cmds.file(r_file, importReference=True) + refs_imported_counter += 1 except Exception as e: errors += str(e) + '(' + r_file + ')\n' except Exception as e: @@ -400,18 +644,36 @@ def gtu_import_references(): print(('#' * 50) + '\n') print(errors) print('#' * 50) - - -def gtu_remove_references(): + else: + in_view_message = '<' + str(random.random()) + '>' + if len(refs) == 0: + in_view_message += 'No references in the scene.' + sys.stdout.write('No references found in the scene. Nothing was imported.') + else: + is_plural = 'references were' + affected = str(refs_imported_counter) + if refs_imported_counter == 1: + is_plural = 'reference was' + affected = '"' + str(refs[0]) + '"' + in_view_message += '' + in_view_message += affected + ' ' + is_plural + ' imported.' + sys.stdout.write(affected + ' ' + is_plural + ' imported.') + cmds.inViewMessage(amg=in_view_message, pos='botLeft', fade=True, alpha=.9) + + +def references_remove(): """ Removes all references """ errors = '' r_file = '' + refs = [] + refs_imported_counter = 0 try: refs = cmds.ls(rf=True) for i in refs: try: r_file = cmds.referenceQuery(i, f=True) cmds.file(r_file, removeReference=True) + refs_imported_counter += 1 except Exception as e: errors += str(e) + '(' + r_file + ')\n' except Exception as e: @@ -422,25 +684,48 @@ def gtu_remove_references(): print(('#' * 50) + '\n') print(errors) print('#' * 50) + else: + in_view_message = '<' + str(random.random()) + '>' + if len(refs) == 0: + in_view_message += 'No references in the scene.' + sys.stdout.write('No references found in the scene. Nothing removed.') + else: + is_plural = 'references were' + affected = str(refs_imported_counter) + if refs_imported_counter == 1: + is_plural = 'reference was' + affected = '"' + str(refs[0]) + '"' + in_view_message += '' + in_view_message += affected + ' ' + is_plural + ' removed.' + sys.stdout.write(affected + ' ' + is_plural + ' removed.') + cmds.inViewMessage(amg=in_view_message, pos='botLeft', fade=True, alpha=.9) """ ____________________________ Material Functions ____________________________""" -def gtu_generate_udim_previews(): +def generate_udim_previews(): """ Generates UDIM previews for all file nodes """ + errors = '' all_file_nodes = cmds.ls(type='file') for file_node in all_file_nodes: try: mel.eval('generateUvTilePreview ' + file_node + ';') except Exception as e: - print(e) - message = 'Previews generated for all ' \ - 'UDIM file nodes.' + errors += str(e) + '\n' + + if errors: + print(('#' * 50) + '\n') + print(errors) + print('#' * 50) + + unique_message = '<' + str(random.random()) + '>' + message = unique_message + 'Previews generated for all ' \ + 'UDIM file nodes.' cmds.inViewMessage(amg=message, pos='botLeft', fade=True, alpha=.9) -def gtu_copy_material(): +def material_copy(): """ Copies selected material to clipboard """ selection = cmds.ls(selection=True) try: @@ -453,7 +738,7 @@ def gtu_copy_material(): cmds.select(selection) -def gtu_paste_material(): +def material_paste(): """ Copies selected material to clipboard """ try: cmds.polyClipboard(paste=True, shader=True) @@ -466,42 +751,127 @@ def gtu_paste_material(): """ ____________________________ Layout Functions ____________________________""" -def gtu_move_pivot_to_top(): +def move_pivot_top(): """ Moves pivot point to the top of the boundary box """ - selection = cmds.ls(selection=True) + selection = cmds.ls(selection=True, long=True) + selection_short = cmds.ls(selection=True) + + if not selection: + cmds.warning('Nothing selected. Please select at least one object and try again.') + return + counter = 0 + errors = '' for obj in selection: - bbox = cmds.exactWorldBoundingBox(obj) # extracts bounding box - top = [(bbox[0] + bbox[3]) / 2, bbox[4], (bbox[2] + bbox[5]) / 2] # find top - cmds.xform(obj, piv=top, ws=True) + try: + bbox = cmds.exactWorldBoundingBox(obj) # extracts bounding box + top = [(bbox[0] + bbox[3]) / 2, bbox[4], (bbox[2] + bbox[5]) / 2] # find top + cmds.xform(obj, piv=top, ws=True) + counter += 1 + except Exception as e: + errors += str(e) + '\n' + if errors: + print(('#' * 50) + '\n') + print(errors) + print('#' * 50) -def gtu_move_pivot_to_base(): + if counter > 0: + pivot_pos = 'top' + is_plural = 'pivots were' + affected = str(counter) + if counter == 1: + is_plural = 'pivot was' + affected = '"' + selection_short[0] + '"' + in_view_message = '<' + str(random.random()) + '>' + in_view_message += '' + affected + in_view_message += ' ' + is_plural + ' moved to the ' + in_view_message += ' ' + pivot_pos + '' + message = affected + ' ' + is_plural + ' moved to the ' + pivot_pos + cmds.inViewMessage(amg=in_view_message, pos='botLeft', fade=True, alpha=.9) + sys.stdout.write(message) + + +def move_pivot_base(): """ Moves pivot point to the base of the boundary box """ - selection = cmds.ls(selection=True) + selection = cmds.ls(selection=True, long=True) + selection_short = cmds.ls(selection=True) + + if not selection: + cmds.warning('Nothing selected. Please select at least one object and try again.') + return + counter = 0 + errors = '' for obj in selection: - bbox = cmds.exactWorldBoundingBox(obj) # extracts bounding box - bottom = [(bbox[0] + bbox[3]) / 2, bbox[1], (bbox[2] + bbox[5]) / 2] # find bottom - cmds.xform(obj, piv=bottom, ws=True) # sends pivot to bottom + try: + bbox = cmds.exactWorldBoundingBox(obj) # extracts bounding box + bottom = [(bbox[0] + bbox[3]) / 2, bbox[1], (bbox[2] + bbox[5]) / 2] # find bottom + cmds.xform(obj, piv=bottom, ws=True) # sends pivot to bottom + counter += 1 + except Exception as e: + errors += str(e) + '\n' + if errors: + print(('#' * 50) + '\n') + print(errors) + print('#' * 50) -def gtu_move_to_origin(): + if counter > 0: + pivot_pos = 'base' + is_plural = 'pivots were' + affected = str(counter) + if counter == 1: + is_plural = 'pivot was' + affected = '"' + selection_short[0] + '"' + in_view_message = '<' + str(random.random()) + '>' + in_view_message += '' + affected + in_view_message += ' ' + is_plural + ' moved to the ' + in_view_message += ' ' + pivot_pos + '' + message = affected + ' ' + is_plural + ' moved to the ' + pivot_pos + cmds.inViewMessage(amg=in_view_message, pos='botLeft', fade=True, alpha=.9) + sys.stdout.write(message) + + +def move_to_origin(): """ Moves selected objects back to origin """ function_name = 'GTU Move to Origin' - errors = '' cmds.undoInfo(openChunk=True, chunkName=function_name) # Start undo chunk selection = cmds.ls(selection=True) + selection_short = cmds.ls(selection=True) + + if not selection: + cmds.warning('Nothing selected. Please select at least one object and try again.') + return + + counter = 0 + errors = '' try: for obj in selection: try: cmds.move(0, 0, 0, obj, a=True, rpr=True) # rpr flag moves it according to the pivot + counter += 1 except Exception as e: errors += str(e) + '\n' if errors != '': print('#### Errors: ####') print(errors) cmds.warning('Some objects could not be moved to the origin. Open the script editor for a list of errors.') + + if counter > 0: + pivot_pos = 'origin' + is_plural = 'objects were' + affected = str(counter) + if counter == 1: + is_plural = ' was' + affected = '"' + selection_short[0] + '"' + in_view_message = '<' + str(random.random()) + '>' + in_view_message += '' + affected + in_view_message += ' ' + is_plural + ' moved to the ' + in_view_message += ' ' + pivot_pos + '' + message = affected + ' ' + is_plural + ' moved to the ' + pivot_pos + cmds.inViewMessage(amg=in_view_message, pos='botLeft', fade=True, alpha=.9) + sys.stdout.write(message) except Exception as e: logger.debug(str(e)) finally: @@ -511,19 +881,26 @@ def gtu_move_to_origin(): """ ____________________________ Reset Functions ____________________________""" -def gtu_reset_transforms(): +def reset_transforms(): """ Reset transforms. It checks for incoming connections, then set the attribute to 0 if there are none It resets transforms, but ignores translate for joints. """ function_name = 'GTU Reset Transforms' - errors = '' cmds.undoInfo(openChunk=True, chunkName=function_name) # Start undo chunk + output_errors = '' + output_counter = 0 + current_selection = cmds.ls(selection=True, long=True) or [] + current_selection_short = cmds.ls(selection=True) or [] - selection = cmds.ls(selection=True) + if not current_selection: + cmds.warning('Nothing selected. Please select at least one object and try again.') + return - def reset_transforms(): + def reset_trans(selection): + errors = '' + counter = 0 for obj in selection: try: type_check = cmds.listRelatives(obj, children=True) or [] @@ -567,73 +944,134 @@ def reset_transforms(): if not len(obj_connection_sz) > 0: if cmds.getAttr(obj + '.scaleZ', lock=True) is False: cmds.setAttr(obj + '.scaleZ', 1) + counter += 1 except Exception as exception: logger.debug(str(exception)) errors += str(exception) + '\n' + return errors, counter try: - reset_transforms() + output_errors, output_counter = reset_trans(current_selection) except Exception as e: logger.debug(str(e)) finally: cmds.undoInfo(closeChunk=True, chunkName=function_name) - if errors != '': + if output_counter > 0: + affected = str(output_counter) + if output_counter == 1: + affected = '"' + current_selection_short[0] + '"' + in_view_message = '<' + str(random.random()) + '>' + in_view_message += '' + affected + in_view_message += ' transforms were reset.' + message = '\n' + affected + ' transforms were reset.' + cmds.inViewMessage(amg=in_view_message, pos='botLeft', fade=True, alpha=.9) + sys.stdout.write(message) + + if output_errors != '': cmds.warning("Some objects couldn't be reset. Open the script editor for a list of errors.") -def gtu_reset_joint_sizes(): +def reset_joint_display(): """ - Resets the radius attribute back to one in all joints, + Resets the radius and drawStyle attributes for all joints, then changes the global multiplier (jointDisplayScale) back to one """ - try: - desired_size = 1 - all_joints = cmds.ls(type='joint') - for obj in all_joints: + errors = '' + target_radius = 1 + counter = 0 + all_joints = cmds.ls(type='joint', long=True) + all_joints_short = cmds.ls(type='joint') + for obj in all_joints: + try: if cmds.objExists(obj): if cmds.getAttr(obj + ".radius", lock=True) is False: cmds.setAttr(obj + '.radius', 1) if cmds.getAttr(obj + ".v", lock=True) is False: cmds.setAttr(obj + '.v', 1) - cmds.jointDisplayScale(desired_size) - except Exception as exception: - raise exception + if cmds.getAttr(obj + ".drawStyle", lock=True) is False: + cmds.setAttr(obj + '.drawStyle', 0) + counter += 1 + except Exception as exception: + logger.debug(str(exception)) + errors += str(exception) + '\n' + cmds.jointDisplayScale(target_radius) + + if counter > 0: + affected = str(counter) + is_plural = 'joints had their' + if counter == 1: + is_plural = 'had its' + affected = '"' + all_joints_short[0] + '"' + in_view_message = '<' + str(random.random()) + '>' + in_view_message += '' + affected + in_view_message += ' ' + is_plural + ' display reset.' + message = '\n' + affected + ' ' + is_plural + ' "radius", "drawStyle" and "visibility" attributes reset.' + cmds.inViewMessage(amg=in_view_message, pos='botLeft', fade=True, alpha=.9) + sys.stdout.write(message) + else: + in_view_message = '<' + str(random.random()) + '>' + in_view_message += 'No joints found in this scene.' + cmds.inViewMessage(amg=in_view_message, pos='botLeft', fade=True, alpha=.9) + + if errors: + print(('#' * 50) + '\n') + print(errors) + print('#' * 50) + cmds.warning('A few joints were not fully reset. Open script editor for more details.') -def gtu_reset_persp_shape_attributes(): +def reset_persp_shape_attributes(): """ If persp shape exists (default camera), reset its attributes """ - if cmds.objExists('perspShape'): - try: - cmds.setAttr('perspShape' + ".focalLength", 35) - cmds.setAttr('perspShape' + ".verticalFilmAperture", 0.945) - cmds.setAttr('perspShape' + ".horizontalFilmAperture", 1.417) - cmds.setAttr('perspShape' + ".lensSqueezeRatio", 1) - cmds.setAttr('perspShape' + ".fStop", 5.6) - cmds.setAttr('perspShape' + ".focusDistance", 5) - cmds.setAttr('perspShape' + ".shutterAngle", 144) - cmds.setAttr('perspShape' + ".locatorScale", 1) - cmds.setAttr('perspShape' + ".nearClipPlane", 0.100) - cmds.setAttr('perspShape' + ".farClipPlane", 10000.000) - cmds.setAttr('perspShape' + ".cameraScale", 1) - cmds.setAttr('perspShape' + ".preScale", 1) - cmds.setAttr('perspShape' + ".postScale", 1) - cmds.setAttr('perspShape' + ".depthOfField", 0) - except Exception as e: - logger.debug(str(e)) + camera_transform = 'persp' + camera_shape = 'perspShape' + try: + if cmds.objExists(camera_transform): + cmds.setAttr(camera_transform + ".sx", 1) + cmds.setAttr(camera_transform + ".sy", 1) + cmds.setAttr(camera_transform + ".sz", 1) + except Exception as e: + logger.debug(str(e)) + + try: + if cmds.objExists(camera_shape): + cmds.setAttr(camera_shape + ".focalLength", 35) + cmds.setAttr(camera_shape + ".verticalFilmAperture", 0.945) + cmds.setAttr(camera_shape + ".horizontalFilmAperture", 1.417) + cmds.setAttr(camera_shape + ".lensSqueezeRatio", 1) + cmds.setAttr(camera_shape + ".fStop", 5.6) + cmds.setAttr(camera_shape + ".focusDistance", 5) + cmds.setAttr(camera_shape + ".shutterAngle", 144) + cmds.setAttr(camera_shape + ".locatorScale", 1) + cmds.setAttr(camera_shape + ".nearClipPlane", 0.100) + cmds.setAttr(camera_shape + ".farClipPlane", 10000.000) + cmds.setAttr(camera_shape + ".cameraScale", 1) + cmds.setAttr(camera_shape + ".preScale", 1) + cmds.setAttr(camera_shape + ".postScale", 1) + cmds.setAttr(camera_shape + ".depthOfField", 0) + cmds.viewFit(allObjects=True) + in_view_message = '<' + str(random.random()) + '>' + in_view_message += '"persp" camera ' + in_view_message += 'attributes were reset.' + cmds.inViewMessage(amg=in_view_message, pos='botLeft', fade=True, alpha=.9) + sys.stdout.write('"' + camera_transform + '" camera attributes were reset back to default values.') + except Exception as e: + print(e) + logger.debug(str(e)) """ ____________________________ Delete Functions ____________________________""" -def gtu_delete_namespaces(): +def delete_namespaces(): """Deletes all namespaces in the scene""" function_name = 'GTU Delete All Namespaces' cmds.undoInfo(openChunk=True, chunkName=function_name) + counter = 0 try: default_namespaces = ['UI', 'shared'] @@ -647,18 +1085,34 @@ def num_children(namespace): # Reverse List namespaces.sort(key=num_children, reverse=True) # So it does the children first - print(namespaces) + logger.debug(namespaces) for namespace in namespaces: if namespace not in default_namespaces: mel.eval('namespace -mergeNamespaceWithRoot -removeNamespace "' + namespace + '";') + counter += 1 except Exception as e: cmds.warning(str(e)) finally: cmds.undoInfo(closeChunk=True, chunkName=function_name) + if counter > 0: + is_plural = 'namespaces were' + if counter == 1: + is_plural = 'namespace was' + in_view_message = '<' + str(random.random()) + '>' + in_view_message += '' + str(counter) + in_view_message += ' ' + is_plural + ' deleted.' + message = '\n' + str(counter) + ' ' + is_plural + ' merged with the "root".' + cmds.inViewMessage(amg=in_view_message, pos='botLeft', fade=True, alpha=.9) + sys.stdout.write(message) + else: + in_view_message = '<' + str(random.random()) + '>' + in_view_message += 'No namespaces found in this scene.' + cmds.inViewMessage(amg=in_view_message, pos='botLeft', fade=True, alpha=.9) + -def gtu_delete_display_layers(): +def delete_display_layers(): """ Deletes all display layers """ function_name = 'GTU Delete All Display Layers' cmds.undoInfo(openChunk=True, chunkName=function_name) @@ -682,7 +1136,7 @@ def gtu_delete_display_layers(): cmds.undoInfo(closeChunk=True, chunkName=function_name) -def gtu_delete_keyframes(): +def delete_keyframes(): """Deletes all keyframes. (Doesn't include Set Driven Keys)""" function_name = 'GTU Delete All Keyframes' cmds.undoInfo(openChunk=True, chunkName=function_name) @@ -716,7 +1170,7 @@ def gtu_delete_keyframes(): cmds.undoInfo(closeChunk=True, chunkName=function_name) -def gtu_delete_nucleus_nodes(): +def delete_nucleus_nodes(): """ Deletes all elements related to particles """ errors = '' function_name = 'GTU Delete Nucleus Nodes' @@ -786,7 +1240,7 @@ def gtu_delete_nucleus_nodes(): print(errors) -def gtu_delete_user_defined_attributes(): +def delete_user_defined_attributes(): """ Deletes all User defined attributes for the selected objects. """ function_name = 'GTU Delete User Defined Attributes' cmds.undoInfo(openChunk=True, chunkName=function_name) @@ -823,10 +1277,70 @@ def gtu_delete_user_defined_attributes(): cmds.undoInfo(closeChunk=True, chunkName=function_name) +def delete_unused_nodes(): + """ + Deleted unused nodes (such as materials not connected to anything or nodes without any connections) + This is done through a Maya MEL function "MLdeleteUnused()" but it's called here again for better feedback. + """ + num_deleted_nodes = mel.eval('MLdeleteUnused();') + logger.debug('Number of unused nodes: ' + str(num_deleted_nodes)) + if num_deleted_nodes > 0: + is_plural = 'unused nodes were' + if num_deleted_nodes == 1: + is_plural = 'unused node was' + in_view_message = '<' + str(random.random()) + '>' + in_view_message += '' + str(num_deleted_nodes) + in_view_message += ' ' + is_plural + ' deleted.' + message = '\n' + str(num_deleted_nodes) + ' ' + is_plural + ' deleted. Open' + cmds.inViewMessage(amg=in_view_message, pos='botLeft', fade=True, alpha=.9) + sys.stdout.write(message) + else: + in_view_message = '<' + str(random.random()) + '>' + in_view_message += 'No unused nodes found in this scene.' + cmds.inViewMessage(amg=in_view_message, pos='botLeft', fade=True, alpha=.9) + + +def delete_all_locators(): + """ Deletes all locators """ + errors = '' + function_name = 'GTU Delete All Locators' + try: + cmds.undoInfo(openChunk=True, chunkName=function_name) + + # With Transform + locators = cmds.ls(typ='locator') + + deleted_counter = 0 + for obj in locators: + try: + parent = cmds.listRelatives(obj, parent=True) or [] + cmds.delete(parent[0]) + deleted_counter += 1 + except Exception as e: + logger.debug(str(e)) + + message = '' + str(deleted_counter) + ' ' + is_plural = 'locators were' + if deleted_counter == 1: + is_plural = 'locator was' + message += is_plural + ' deleted.' + + cmds.inViewMessage(amg=message, pos='botLeft', fade=True, alpha=.9) + + except Exception as e: + errors += str(e) + '\n' + cmds.warning('An error occurred when deleting locators. Open the script editor for more information.') + finally: + cmds.undoInfo(closeChunk=True, chunkName=function_name) + if errors != '': + print('######## Errors: ########') + print(errors) + + """ ____________________________ External Functions ____________________________""" -def gtu_combine_curves(): +def curves_combine(): """ Moves the shape objects of all selected curves under a single group (combining them) """ errors = '' function_name = 'GTU Combine Curves' @@ -878,19 +1392,20 @@ def gtu_combine_curves(): cmds.select(group, add=True) cmds.parent(relative=True, shape=True) cmds.delete(selection) + sys.stdout.write('\nSelected curves were combined into: "' + group + '".') + cmds.select(group) except Exception as e: errors += str(e) + '\n' cmds.warning('An error occurred when combining the curves. Open the script editor for more information.') finally: - cmds.undoInfo(closeChunk=True, chunkName=function_name) if errors != '': print('######## Errors: ########') print(errors) -def gtu_separate_curves(): +def curves_separate(): """ Moves the shapes instead of a curve to individual transforms (separating curves) """ @@ -915,7 +1430,7 @@ def get_short_name(full_name): function_name = 'GTU Separate Curves' try: cmds.undoInfo(openChunk=True, chunkName=function_name) - selection = cmds.ls(sl=True) + selection = cmds.ls(sl=True, long=True) valid_selection = True curve_shapes = [] @@ -926,6 +1441,7 @@ def get_short_name(full_name): cmds.warning('You need to select at least one curve.') if valid_selection: + new_transforms = [] for obj in selection: shapes = cmds.listRelatives(obj, shapes=True, fullPath=True) or [] for shape in shapes: @@ -943,6 +1459,7 @@ def get_short_name(full_name): cmds.makeIdentity(par, apply=True, rotate=True, scale=True, translate=True) group = cmds.group(empty=True, world=True, name=get_short_name(obj).replace('Shape', '')) cmds.parent(obj, group, relative=True, shape=True) + new_transforms.append(group) else: cmds.warning('The selected curve contains only one shape.') @@ -950,6 +1467,8 @@ def get_short_name(full_name): shapes = cmds.listRelatives(obj, shapes=True, fullPath=True) or [] if cmds.objExists(obj) and cmds.objectType(obj) == 'transform' and len(shapes) == 0: cmds.delete(obj) + cmds.select(new_transforms) + sys.stdout.write('\n' + str(len(curve_shapes)) + ' shapes extracted.') except Exception as e: errors += str(e) + '\n' @@ -961,7 +1480,7 @@ def get_short_name(full_name): print(errors) -def gtu_convert_bif_to_mesh(): +def convert_bif_to_mesh(): """ Converts Bifrost geometry to Maya geometry """ @@ -1036,11 +1555,119 @@ def gtu_convert_bif_to_mesh(): print(errors) -""" ____________________________ About Window ____________________________""" - - -def gtu_build_gui_about_gt_tools(): - """ Creates "About" window for the GT Tools menu """ +def convert_joints_to_mesh(combine_mesh=True): + """ + Converts a joint hierarchy into a mesh representation of it (Helpful when sending it to sculpting apps) + Args: + combine_mesh: Combines generated meshes into one + + Returns: + A list of generated meshes + """ + selection = cmds.ls(selection=True, type='joint') + if len(selection) != 1: + cmds.warning('Please selection only the root joint and try again.') + return + cmds.select(selection[0], replace=True) + cmds.select(hierarchy=True) + joints = cmds.ls(selection=True, type='joint') + + generated_mesh = [] + for obj in reversed(joints): + if cmds.objExists(obj): + joint_name = obj.split('|')[-1] + radius = cmds.getAttr(obj + '.radius') + joint_sphere = cmds.polySphere(radius=radius * .5, + subdivisionsAxis=8, + subdivisionsHeight=8, + axis=[1, 0, 0], + name=joint_name + 'JointMesh', + ch=False) + generated_mesh.append(joint_sphere[0]) + cmds.delete(cmds.parentConstraint(obj, joint_sphere)) + joint_parent = cmds.listRelatives(obj, parent=True) or [] + if joint_parent: + joint_cone = cmds.polyCone(radius=radius * .5, + subdivisionsAxis=4, + name=joint_name + 'BoneMesh', + ch=False) + generated_mesh.append(joint_cone[0]) + bbox = cmds.exactWorldBoundingBox(joint_cone) + bottom = [(bbox[0] + bbox[3]) / 2, bbox[1], (bbox[2] + bbox[5]) / 2] + cmds.xform(joint_cone, piv=bottom, ws=True) + cmds.move(1, joint_cone, moveY=True) + cmds.rotate(90, joint_cone, rotateX=True) + cmds.rotate(90, joint_cone, rotateY=True) + cmds.makeIdentity(joint_cone, rotate=True, apply=True) + + cmds.delete(cmds.parentConstraint(joint_parent, joint_cone)) + cmds.delete(cmds.aimConstraint(obj, joint_cone)) + + child_pos = cmds.xform(obj, t=True, ws=True, query=True) + cmds.xform(joint_cone[0] + '.vtx[4]', t=child_pos, ws=True) + if combine_mesh: + cmds.select(generated_mesh, replace=True) + mesh = cmds.polyUnite() + cmds.select(clear=True) + cmds.delete(mesh, constructionHistory=True) + mesh = cmds.rename(mesh[0], selection[0] + 'AsMesh') + return [mesh] + else: + return generated_mesh + + +def convert_to_locators(): + """ + Converts transforms to locators without deleting them. + Essentially places a locator where every transform is. + """ + selection = cmds.ls(selection=True, long=True) + selection_short = cmds.ls(selection=True) + errors = '' + counter = 0 + if not selection: + cmds.warning('Nothing selected. Please select at least one object and try again.') + return + + locators_grp = 'transforms_as_locators_grp' + if not cmds.objExists(locators_grp): + locators_grp = cmds.group(name=locators_grp, world=True, empty=True) + + for obj in selection: + try: + loc = cmds.spaceLocator(name=obj + '_loc')[0] + cmds.parent(loc, locators_grp) + cmds.delete(cmds.parentConstraint(obj, loc)) + cmds.delete(cmds.scaleConstraint(obj, loc)) + counter += 1 + except Exception as exception: + errors += str(exception) + '\n' + + if errors: + print(('#' * 50) + '\n') + print(errors) + print('#' * 50) + + if counter > 0: + affected = str(counter) + is_plural = 'locators were' + if counter == 1: + is_plural = 'locator was' + affected = '"' + selection_short[0] + '"' + in_view_message = '<' + str(random.random()) + '>' + in_view_message += '' + affected + in_view_message += ' ' + is_plural + ' created.' + message = affected + ' ' + is_plural + ' created. Find them inside the group "' + str(locators_grp) + '".' + cmds.inViewMessage(amg=in_view_message, pos='botLeft', fade=True, alpha=.9) + sys.stdout.write(message) + cmds.select(selection) + + +""" ____________________________ About Window ____________________________""" + + +def build_gui_about_gt_tools(): + """ Creates "About" window for the GT Tools menu """ stored_gt_tools_version_exists = cmds.optionVar(exists="gt_tools_version") @@ -1050,7 +1677,7 @@ def gtu_build_gui_about_gt_tools(): else: gt_version = '?' - window_name = "gtu_build_gui_about_gt_tools" + window_name = "build_gui_about_gt_tools" if cmds.window(window_name, exists=True): cmds.deleteUI(window_name, window=True) @@ -1118,232 +1745,6 @@ def close_help_gui(): cmds.deleteUI(window_name, window=True) -def gtu_delete_all_locators(): - """ Deletes all locators """ - errors = '' - function_name = 'GTU Delete All Locators' - try: - cmds.undoInfo(openChunk=True, chunkName=function_name) - - # With Transform - locators = cmds.ls(typ='locator') - - deleted_counter = 0 - for obj in locators: - try: - parent = cmds.listRelatives(obj, parent=True) or [] - cmds.delete(parent[0]) - deleted_counter += 1 - except Exception as e: - logger.debug(str(e)) - - message = '' + str(deleted_counter) + ' ' - is_plural = 'locators were' - if deleted_counter == 1: - is_plural = 'locator was' - message += is_plural + ' deleted.' - - cmds.inViewMessage(amg=message, pos='botLeft', fade=True, alpha=.9) - - except Exception as e: - errors += str(e) + '\n' - cmds.warning('An error occurred when deleting locators. Open the script editor for more information.') - finally: - cmds.undoInfo(closeChunk=True, chunkName=function_name) - if errors != '': - print('######## Errors: ########') - print(errors) - - -def gtu_full_hud_toggle(): - """ Toggles common HUD options so all the common ones are either active or inactive """ - hud_current_state = {} - - # 1 - Animation Details - hud_current_state['animationDetailsVisibility'] = int(mel.eval('optionVar -q animationDetailsVisibility;')) - # 2 - Cache - try: - from maya.plugin.evaluator.CacheUiHud import CachePreferenceHud - hud_current_state['CachePreferenceHud'] = int(CachePreferenceHud().get_value() or 0) - except Exception as e: - logger.debug(str(e)) - hud_current_state['CachePreferenceHud'] = 0 - # 3 - Camera Names - hud_current_state['cameraNamesVisibility'] = int(mel.eval('optionVar -q cameraNamesVisibility;')) - # 4 - Caps Lock - hud_current_state['capsLockVisibility'] = int(mel.eval('optionVar -q capsLockVisibility;')) - # 5 - Current Asset - hud_current_state['currentContainerVisibility'] = int(mel.eval('optionVar -q currentContainerVisibility;')) - # 6 - Current Frame - hud_current_state['currentFrameVisibility'] = int(mel.eval('optionVar -q currentFrameVisibility;')) - # 7 - Evaluation - hud_current_state['evaluationVisibility'] = int(mel.eval('optionVar -q evaluationVisibility;')) - # 8 - Focal Length - hud_current_state['focalLengthVisibility'] = int(mel.eval('optionVar -q focalLengthVisibility;')) - # 9 - Frame Rate - hud_current_state['frameRateVisibility'] = int(mel.eval('optionVar -q frameRateVisibility;')) - # 10 - HumanIK Details - hud_current_state['hikDetailsVisibility'] = int(mel.eval('optionVar -q hikDetailsVisibility;')) - # 11 - Material Loading Details - hud_current_state['materialLoadingDetailsVisibility'] = int( - mel.eval('optionVar -q materialLoadingDetailsVisibility;')) - # 12 - Object Details - hud_current_state['objectDetailsVisibility'] = int(mel.eval('optionVar -q objectDetailsVisibility;')) - # 13 - Origin Axis - Ignored as non-hud element - # hud_current_state['originAxesMenuUpdate'] = mel.eval('optionVar -q originAxesMenuUpdate;') - # 14 - Particle Count - hud_current_state['particleCountVisibility'] = int(mel.eval('optionVar -q particleCountVisibility;')) - # 15 - Poly Count - hud_current_state['polyCountVisibility'] = int(mel.eval('optionVar -q polyCountVisibility;')) - # 16 - Scene Timecode - hud_current_state['sceneTimecodeVisibility'] = int(mel.eval('optionVar -q sceneTimecodeVisibility;')) - # 17 - Select Details - hud_current_state['selectDetailsVisibility'] = int(mel.eval('optionVar -q selectDetailsVisibility;')) - # 18 - Symmetry - hud_current_state['symmetryVisibility'] = int(mel.eval('optionVar -q symmetryVisibility;')) - # 19 - View Axis - hud_current_state['viewAxisVisibility'] = int(mel.eval('optionVar -q viewAxisVisibility;')) - # 20 - Viewport Renderer - hud_current_state['viewportRendererVisibility'] = int(mel.eval('optionVar -q viewportRendererVisibility;')) - # ------- Separator ------- - # 21 - In-view Messages - hud_current_state['inViewMessageEnable'] = int(mel.eval('optionVar -q inViewMessageEnable;')) - # 22 - In-view Editors - hud_current_state['inViewEditorVisible'] = int(mel.eval('optionVar -q inViewEditorVisible;')) - # Conditional - XGen Info - hud_current_state['xgenHUDVisibility'] = int(mel.eval('optionVar -q xgenHUDVisibility;')) - - # Check if toggle ON or OFF - toggle = True - count = 0 - for item_state in hud_current_state: - if hud_current_state.get(item_state): - count += 1 - # More than half is on, so OFF else ON (Default) - if count > len(hud_current_state) / 2: - toggle = False - - # Toggles non-standard hud elements - if toggle: - mel.eval('setAnimationDetailsVisibility(true)') - try: - from maya.plugin.evaluator.CacheUiHud import CachePreferenceHud - CachePreferenceHud().set_value(True) - except Exception as e: - logger.debug(str(e)) - mel.eval('setCameraNamesVisibility(true)') - mel.eval('setCapsLockVisibility(true)') - mel.eval('setCurrentContainerVisibility(true)') - mel.eval('setCurrentFrameVisibility(true)') - mel.eval('SetEvaluationManagerHUDVisibility(1)') - mel.eval('setFocalLengthVisibility(true)') - mel.eval('setFrameRateVisibility(true)') - if not hud_current_state.get('hikDetailsVisibility'): - cmds.ToggleHikDetails() - mel.eval('catchQuiet(setHikDetailsVisibility(true));') - mel.eval('ToggleMaterialLoadingDetailsHUDVisibility(true)') - mel.eval('setObjectDetailsVisibility(true)') - mel.eval('setParticleCountVisibility(true)') - mel.eval('setPolyCountVisibility(true)') - mel.eval('setSceneTimecodeVisibility(true)') - mel.eval('setSelectDetailsVisibility(true)') - mel.eval('setSymmetryVisibility(true)') - mel.eval('setViewAxisVisibility(true)') - mel.eval('setViewportRendererVisibility(true)') - mel.eval('catchQuiet(setXGenHUDVisibility(true));') - - if not hud_current_state.get('inViewMessageEnable'): - cmds.ToggleInViewMessage() - if not hud_current_state.get('inViewEditorVisible'): - cmds.ToggleInViewEditor() - else: - mel.eval('setAnimationDetailsVisibility(false)') - try: - from maya.plugin.evaluator.CacheUiHud import CachePreferenceHud - CachePreferenceHud().set_value(False) - except Exception as e: - logger.debug(str(e)) - mel.eval('setCurrentContainerVisibility(false)') - mel.eval('setCurrentFrameVisibility(false)') - mel.eval('SetEvaluationManagerHUDVisibility(0)') - mel.eval('setFocalLengthVisibility(false)') - mel.eval('setFrameRateVisibility(false)') - if hud_current_state.get('hikDetailsVisibility'): - cmds.ToggleHikDetails() - mel.eval('catchQuiet(setHikDetailsVisibility(false));') - mel.eval('catchQuiet(hikDetailsKeyingMode());') - mel.eval('ToggleMaterialLoadingDetailsHUDVisibility(false)') - mel.eval('setObjectDetailsVisibility(false)') - mel.eval('setParticleCountVisibility(false)') - mel.eval('setPolyCountVisibility(false)') - mel.eval('setSceneTimecodeVisibility(false)') - mel.eval('setSelectDetailsVisibility(false)') - mel.eval('setViewportRendererVisibility(false)') - mel.eval('catchQuiet(setXGenHUDVisibility(false));') - # Default states are preserved: camera names, caps lock, symmetry, view axis, in-view messages and in-view editor - - -def gtu_convert_joints_to_mesh(combine_mesh=True): - """ - Converts a joint hierarchy into a mesh representation of it (Helpful when sending it to sculpting apps) - Args: - combine_mesh: Combines generated meshes into one - - Returns: - A list of generated meshes - """ - selection = cmds.ls(selection=True, type='joint') - if len(selection) != 1: - cmds.warning('Please selection only the root joint and try again.') - return - cmds.select(selection[0], replace=True) - cmds.select(hierarchy=True) - joints = cmds.ls(selection=True, type='joint') - - generated_mesh = [] - for obj in reversed(joints): - if cmds.objExists(obj): - joint_name = obj.split('|')[-1] - radius = cmds.getAttr(obj + '.radius') - joint_sphere = cmds.polySphere(radius=radius * .5, - subdivisionsAxis=8, - subdivisionsHeight=8, - axis=[1, 0, 0], - name=joint_name + 'JointMesh', - ch=False) - generated_mesh.append(joint_sphere[0]) - cmds.delete(cmds.parentConstraint(obj, joint_sphere)) - joint_parent = cmds.listRelatives(obj, parent=True) or [] - if joint_parent: - joint_cone = cmds.polyCone(radius=radius * .5, - subdivisionsAxis=4, - name=joint_name + 'BoneMesh', - ch=False) - generated_mesh.append(joint_cone[0]) - bbox = cmds.exactWorldBoundingBox(joint_cone) - bottom = [(bbox[0] + bbox[3]) / 2, bbox[1], (bbox[2] + bbox[5]) / 2] - cmds.xform(joint_cone, piv=bottom, ws=True) - cmds.move(1, joint_cone, moveY=True) - cmds.rotate(90, joint_cone, rotateX=True) - cmds.rotate(90, joint_cone, rotateY=True) - cmds.makeIdentity(joint_cone, rotate=True, apply=True) - - cmds.delete(cmds.parentConstraint(joint_parent, joint_cone)) - cmds.delete(cmds.aimConstraint(obj, joint_cone)) - - child_pos = cmds.xform(obj, t=True, ws=True, query=True) - cmds.xform(joint_cone[0] + '.vtx[4]', t=child_pos, ws=True) - if combine_mesh: - cmds.select(generated_mesh, replace=True) - mesh = cmds.polyUnite() - cmds.select(clear=True) - cmds.delete(mesh, constructionHistory=True) - mesh = cmds.rename(mesh[0], selection[0] + 'AsMesh') - return [mesh] - else: - return generated_mesh - - def output_string_to_notepad(string, file_name='tmp'): """ Creates a txt file and writes a list of objects to it (with necessary code used to select it, in Mel and Python) @@ -1364,46 +1765,49 @@ def output_string_to_notepad(string, file_name='tmp'): mel.eval(notepad_command) -""" ____________________________ Functions Calls ____________________________""" +# """ ____________________________ Functions Calls ____________________________""" if __name__ == '__main__': pass - # gtu_reload_file() - # gtu_open_resource_browser() - # gtu_unlock_default_channels() - # gtu_unhide_default_channels() - # gtu_import_references() - # gtu_remove_references() - # gtu_uniform_lra_toggle() - # gtu_uniform_jnt_label_toggle() - # gtu_select_non_unique_objects() - - # gtu_generate_udim_previews() - # gtu_copy_material() - # gtu_paste_material() - - # gtu_move_pivot_to_top() - # gtu_move_pivot_to_base() - # gtu_move_to_origin() - - # gtu_reset_joint_sizes() - # gtu_reset_transforms() - # gtu_reset_persp_shape_attributes() - - # gtu_delete_namespaces() - # gtu_delete_display_layers() - # gtu_delete_keyframes() - # gtu_delete_nucleus_nodes() - # gtu_delete_user_defined_attributes() - - # --- Outside Utilities --- - # gtu_combine_curves() - # gtu_separate_curves() - # gtu_convert_bif_to_mesh() - - # gtu_build_gui_about_gt_tools() - - # --- Other Functions --- - # gtu_delete_all_locators() - # gtu_full_hud_toggle() - # gtu_convert_joints_to_mesh() + logger.setLevel(logging.DEBUG) + # force_reload_file() + # open_resource_browser() + # unlock_default_channels() + # unhide_default_channels() + # references_import() + # references_remove() + # toggle_uniform_lra() + # toggle_uniform_jnt_label() + # select_non_unique_objects() + # + # generate_udim_previews() + # material_copy() + # material_paste() + # + # move_pivot_top() + # move_pivot_base() + # move_to_origin() + # + # reset_joint_display() + # reset_transforms() + # reset_persp_shape_attributes() + # + # delete_namespaces() + # delete_display_layers() + # delete_keyframes() + # delete_nucleus_nodes() + # delete_user_defined_attributes() + # delete_unused_nodes() + # delete_all_locators() + # + # # --- Outside Utilities --- + # curves_combine() + # curves_separate() + # convert_bif_to_mesh() + # convert_to_locators() + # + # build_gui_about_gt_tools() + # + # # --- Other Functions --- + # toggle_full_hud() + # convert_joints_to_mesh() # output_string_to_notepad('Test') diff --git a/python-scripts/gt_renamer.py b/python-scripts/gt_renamer.py index 257b34be..04f4b114 100644 --- a/python-scripts/gt_renamer.py +++ b/python-scripts/gt_renamer.py @@ -23,6 +23,16 @@ 1.5 - 2021-05-08 Made script compatible with Python 3 (Maya 2022+) + + 1.5.1 - 2022-07-29 + Added patch to version + PEP8 Cleanup + Removed unnecessary python version lines + + 1.5.2 - 2022-07-29 + Added logger + PEP8 Cleanup + Todo: Add persistent settings for the selection type (Selected, Hierarchy, All) @@ -36,10 +46,10 @@ """ import maya.cmds as cmds import traceback +import logging import random import copy -import sys -from maya import OpenMayaUI as omui +from maya import OpenMayaUI as OpenMayaUI try: from shiboken2 import wrapInstance @@ -52,20 +62,21 @@ except ImportError: from PySide.QtGui import QIcon, QWidget +# Logging Setup +logging.basicConfig() +logger = logging.getLogger("gt_renamer") +logger.setLevel(logging.INFO) # Script Name: script_name = "GT Renamer" # Version: -script_version = "1.5.0" - -# Python Version -python_version = sys.version_info.major +script_version = "1.5.2" # Auto Suffix/Prefix Strings and other settings: gt_renamer_settings = {'transform_suffix': '_grp', 'mesh_suffix': '_geo', - 'nurbs_curv_suffix': '_crv', + 'nurbs_crv_suffix': '_crv', 'joint_suffix': '_jnt', 'locator_suffix': '_loc', 'surface_suffix': '_sur', @@ -106,7 +117,7 @@ def get_persistent_settings_renamer(): stored_transform_suffix_exists = cmds.optionVar(exists="gt_renamer_transform_suffix") stored_mesh_suffix_exists = cmds.optionVar(exists="gt_renamer_mesh_suffix") - stored_nurbs_curv_suffix_exists = cmds.optionVar(exists="gt_renamer_nurbs_curve_suffix") + stored_nurbs_crv_suffix_exists = cmds.optionVar(exists="gt_renamer_nurbs_curve_suffix") stored_joint_suffix_exists = cmds.optionVar(exists="gt_renamer_joint_suffix") stored_locator_suffix_exists = cmds.optionVar(exists="gt_renamer_locator_suffix") stored_surface_suffix_exists = cmds.optionVar(exists="gt_renamer_surface_suffix") @@ -116,58 +127,58 @@ def get_persistent_settings_renamer(): stored_def_starting_number_exists = cmds.optionVar(exists="gt_renamer_def_starting_number") stored_def_padding_number_exists = cmds.optionVar(exists="gt_renamer_def_padding_number") stored_selection_type_exists = cmds.optionVar(exists="gt_renamer_selection_type") - + if stored_transform_suffix_exists: gt_renamer_settings['transform_suffix'] = str(cmds.optionVar(q="gt_renamer_transform_suffix")) - + if stored_mesh_suffix_exists: gt_renamer_settings['mesh_suffix'] = str(cmds.optionVar(q="gt_renamer_mesh_suffix")) - - if stored_nurbs_curv_suffix_exists: - gt_renamer_settings['nurbs_curv_suffix'] = str(cmds.optionVar(q="gt_renamer_nurbs_curve_suffix")) - + + if stored_nurbs_crv_suffix_exists: + gt_renamer_settings['nurbs_crv_suffix'] = str(cmds.optionVar(q="gt_renamer_nurbs_curve_suffix")) + if stored_joint_suffix_exists: gt_renamer_settings['joint_suffix'] = str(cmds.optionVar(q="gt_renamer_joint_suffix")) - + if stored_locator_suffix_exists: gt_renamer_settings['locator_suffix'] = str(cmds.optionVar(q="gt_renamer_locator_suffix")) - + if stored_surface_suffix_exists: gt_renamer_settings['surface_suffix'] = str(cmds.optionVar(q="gt_renamer_surface_suffix")) - + if stored_left_prefix_exists: gt_renamer_settings['left_prefix'] = str(cmds.optionVar(q="gt_renamer_left_prefix")) - + if stored_right_prefix_exists: gt_renamer_settings['right_prefix'] = str(cmds.optionVar(q="gt_renamer_right_prefix")) - + if stored_center_prefix_exists: gt_renamer_settings['center_prefix'] = str(cmds.optionVar(q="gt_renamer_center_prefix")) - + if stored_def_starting_number_exists: gt_renamer_settings['def_starting_number'] = str(cmds.optionVar(q="gt_renamer_def_starting_number")) - + if stored_def_padding_number_exists: gt_renamer_settings['def_padding_number'] = str(cmds.optionVar(q="gt_renamer_def_padding_number")) - + if stored_selection_type_exists: gt_renamer_settings['selection_type'] = str(cmds.optionVar(q="gt_renamer_selection_type")) - + def set_persistent_settings_renamer(option_var_name, option_var_string): """ Stores persistent settings for GT Renamer. It assumes that persistent settings were stored using the cmds.optionVar function. - Parameters: - option_var_name (string): name of the optionVar string. Must start with script name + name of the variable - option_var_string (string): string to be stored under the option_var_name + Args: + option_var_name (string): name of the optionVar string. Must start with script name + name of the variable + option_var_string (string): string to be stored under the option_var_name """ - + if option_var_string != '' and option_var_name != '': - cmds.optionVar( sv=(str(option_var_name), str(option_var_string))) - + cmds.optionVar(sv=(str(option_var_name), str(option_var_string))) + def reset_persistent_settings_renamer(): """ Resets persistent settings for GT Renamer """ @@ -183,7 +194,7 @@ def reset_persistent_settings_renamer(): cmds.optionVar(remove='gt_renamer_def_starting_number') cmds.optionVar(remove='gt_renamer_def_padding_number') cmds.optionVar(remove='gt_renamer_selection_type') - + for def_value in gt_renamer_settings_default_values: for value in gt_renamer_settings: if def_value == value: @@ -192,22 +203,22 @@ def reset_persistent_settings_renamer(): get_persistent_settings_renamer() build_gui_renamer() cmds.warning('Persistent settings for ' + script_name + ' were cleared.') - + # Renamer UI ============================================================================ def build_gui_renamer(): """ Builds the UI for GT Renamer """ window_name = "build_gui_renamer" - if cmds.window(window_name, exists =True): - cmds.deleteUI(window_name) + if cmds.window(window_name, exists=True): + cmds.deleteUI(window_name) + + # =================================================================================== + + window_gui_renamer = cmds.window(window_name, title=script_name + ' (v' + script_version + ')', + titleBar=True, mnb=False, mxb=False, sizeable=True) + + cmds.window(window_name, e=True, s=True, wh=[1, 1]) - # =================================================================================== - - build_gui_renamer = cmds.window(window_name, title=script_name + ' (v' + script_version+ ')', - titleBar=True, mnb=False, mxb=False, sizeable =True) - - cmds.window(window_name, e=True, s=True, wh=[1,1]) - content_main = cmds.columnLayout() # Title Text @@ -216,22 +227,26 @@ def build_gui_renamer(): cmds.rowColumnLayout(nc=1, cw=[(1, 270)], cs=[(1, 10)], p=content_main) # Window Size Adjustment cmds.rowColumnLayout(nc=3, cw=[(1, 10), (2, 200), (3, 50)], cs=[(1, 10), (2, 0), (3, 0)], p=content_main) cmds.text(" ", bgc=title_bgc_color) # Tiny Empty Green Space - cmds.text(script_name, bgc=title_bgc_color, fn="boldLabelFont", align="left") - cmds.button( l ="Help", bgc=title_bgc_color, c=lambda x:build_gui_help_renamer()) + cmds.text(script_name, bgc=title_bgc_color, fn="boldLabelFont", align="left") + cmds.button(l="Help", bgc=title_bgc_color, c=lambda x: build_gui_help_renamer()) cmds.separator(h=10, style='none', p=content_main) # Empty Space # Body ==================== - body_column = cmds.rowColumnLayout(nc=1, cw=[(1, 260)], cs=[(1,10)], p=content_main) - cmds.rowColumnLayout(nc=3, cw=[(1, 90),(2, 95),(3, 95)], cs=[(1,15)]) + body_column = cmds.rowColumnLayout(nc=1, cw=[(1, 260)], cs=[(1, 10)], p=content_main) + cmds.rowColumnLayout(nc=3, cw=[(1, 90), (2, 95), (3, 95)], cs=[(1, 15)]) selection_type_rc = cmds.radioCollection() - selection_type_selected = cmds.radioButton( label='Selected', select=True, cc=lambda x:store_selection_type_persistent_settings()) - selection_type_hierarchy = cmds.radioButton( label='Hierarchy', cc=lambda x:store_selection_type_persistent_settings()) - selection_type_all = cmds.radioButton( label='All', cc=lambda x:store_selection_type_persistent_settings()) - + selection_type_selected = cmds.radioButton(label='Selected', select=True, + cc=lambda x: store_selection_type_persistent_settings()) + selection_type_hierarchy = cmds.radioButton(label='Hierarchy', + cc=lambda x: store_selection_type_persistent_settings()) + selection_type_all = cmds.radioButton(label='All', cc=lambda x: store_selection_type_persistent_settings()) + def store_selection_type_persistent_settings(): - """ Stores current state of seletion type as persistent settings """ - set_persistent_settings_renamer('gt_renamer_selection_type', cmds.radioButton(cmds.radioCollection(selection_type_rc, q=True, select=True), q=True, label=True)) - + """ Stores current state of selection type as persistent settings """ + set_persistent_settings_renamer('gt_renamer_selection_type', + cmds.radioButton(cmds.radioCollection(selection_type_rc, q=True, select=True), + q=True, label=True)) + # Set Persistent Settings for Selection Type if gt_renamer_settings.get('selection_type') == 'Hierarchy': cmds.radioCollection(selection_type_rc, e=True, select=selection_type_hierarchy) @@ -239,52 +254,58 @@ def store_selection_type_persistent_settings(): cmds.radioCollection(selection_type_rc, e=True, select=selection_type_all) else: cmds.radioCollection(selection_type_rc, e=True, select=selection_type_selected) - - cmds.rowColumnLayout( nc=1, cw=[(1, 260)], cs=[(1, 0)], p=body_column) - cmds.separator(h=5, style='none') # Empty Space - + + cmds.rowColumnLayout(nc=1, cw=[(1, 260)], cs=[(1, 0)], p=body_column) + cmds.separator(h=5, style='none') # Empty Space + # Other Tools ================ cmds.separator(h=10) - cmds.separator(h=5, style='none') # Empty Space + cmds.separator(h=5, style='none') # Empty Space cmds.text('Other Tools') - cmds.separator(h=7, style='none') # Empty Space - cmds.rowColumnLayout(nc=2, cw=[(1, 120),(2, 120)], cs=[(1, 5),(2, 5)], p=body_column) - cmds.button(l ="Remove First Letter", c=lambda x:start_renaming('remove_first_letter')) - cmds.button(l ="Remove Last Letter", c=lambda x:start_renaming('remove_last_letter')) - cmds.separator(h=7, style='none') # Empty Space - cmds.separator(h=7, style='none') # Empty Space - cmds.rowColumnLayout(nc=3, cw=[(1, 78),(2, 79),(3, 78)], cs=[(1, 5),(2, 5), (3, 5)], p=body_column) - cmds.button(l ="U-Case", c=lambda x:start_renaming('uppercase_names')) - cmds.button(l ="Capitalize", c=lambda x:start_renaming('capitalize_names')) - cmds.button(l ="L-Case", c=lambda x:start_renaming('lowercase_names')) - cmds.separator(h=7, style='none') # Empty Space - cmds.rowColumnLayout( nc=1, cw=[(1, 260)], cs=[(1, 0)], p=body_column) - + cmds.separator(h=7, style='none') # Empty Space + cmds.rowColumnLayout(nc=2, cw=[(1, 120), (2, 120)], cs=[(1, 5), (2, 5)], p=body_column) + cmds.button(l="Remove First Letter", c=lambda x: start_renaming('remove_first_letter')) + cmds.button(l="Remove Last Letter", c=lambda x: start_renaming('remove_last_letter')) + cmds.separator(h=7, style='none') # Empty Space + cmds.separator(h=7, style='none') # Empty Space + cmds.rowColumnLayout(nc=3, cw=[(1, 78), (2, 79), (3, 78)], cs=[(1, 5), (2, 5), (3, 5)], p=body_column) + cmds.button(l="U-Case", c=lambda x: start_renaming('uppercase_names')) + cmds.button(l="Capitalize", c=lambda x: start_renaming('capitalize_names')) + cmds.button(l="L-Case", c=lambda x: start_renaming('lowercase_names')) + cmds.separator(h=7, style='none') # Empty Space + cmds.rowColumnLayout(nc=1, cw=[(1, 260)], cs=[(1, 0)], p=body_column) + # Rename and Number ================ cmds.separator(h=10) - cmds.separator(h=5, style='none') # Empty Space + cmds.separator(h=5, style='none') # Empty Space cmds.text('Rename and Number') - cmds.separator(h=7, style='none') # Empty Space - - cmds.rowColumnLayout( nc=2, cw=[(1, 80),(2, 150)], cs=[(1, 5),(2, 0)], p=body_column) + cmds.separator(h=7, style='none') # Empty Space + + cmds.rowColumnLayout(nc=2, cw=[(1, 80), (2, 150)], cs=[(1, 5), (2, 0)], p=body_column) cmds.text('Rename:') - rename_number_textfield = cmds.textField(placeholderText = 'new_name', enterCommand=lambda x: start_renaming('rename_and_number')) - - cmds.separator(h=7, style='none') # Empty Space - - cmds.rowColumnLayout( nc=4, cw=[(1, 50),(2, 40),(3, 60),(4, 40)], cs=[(1, 20),(2, 0),(3, 10),(4, 0)], p=body_column) + rename_number_textfield = cmds.textField(placeholderText='new_name', + enterCommand=lambda x: start_renaming('rename_and_number')) + + cmds.separator(h=7, style='none') # Empty Space + + cmds.rowColumnLayout(nc=4, cw=[(1, 50), (2, 40), (3, 60), (4, 40)], cs=[(1, 20), (2, 0), (3, 10), (4, 0)], + p=body_column) cmds.text('Start #:') - start_number_textfield = cmds.textField(text = gt_renamer_settings.get('def_starting_number'), - enterCommand=lambda x:start_renaming('rename_and_number'), - cc=lambda x: set_persistent_settings_renamer('gt_renamer_def_starting_number', cmds.textField(start_number_textfield, q=True, text=True))) + start_number_textfield = cmds.textField(text=gt_renamer_settings.get('def_starting_number'), + enterCommand=lambda x: start_renaming('rename_and_number'), + cc=lambda x: set_persistent_settings_renamer( + 'gt_renamer_def_starting_number', + cmds.textField(start_number_textfield, q=True, text=True))) cmds.text('Padding:') - padding_number_textfield = cmds.textField(text = gt_renamer_settings.get('def_padding_number'), \ - enterCommand=lambda x:start_renaming('rename_and_number'), \ - cc=lambda x: set_persistent_settings_renamer('gt_renamer_def_padding_number', cmds.textField(padding_number_textfield, q=True, text=True))) - - cmds.rowColumnLayout( nc=1, cw=[(1, 240)], cs=[(1, 10)], p=body_column) + padding_number_textfield = cmds.textField(text=gt_renamer_settings.get('def_padding_number'), + enterCommand=lambda x: start_renaming('rename_and_number'), + cc=lambda x: set_persistent_settings_renamer( + 'gt_renamer_def_padding_number', + cmds.textField(padding_number_textfield, q=True, text=True))) + + cmds.rowColumnLayout(nc=1, cw=[(1, 240)], cs=[(1, 10)], p=body_column) cmds.separator(h=10, style='none') # Empty Space - cmds.button(l ="Rename and Number", bgc=(.6, .6, .6), c=lambda x: start_renaming('rename_and_number')) + cmds.button(l="Rename and Number", bgc=(.6, .6, .6), c=lambda x: start_renaming('rename_and_number')) cmds.separator(h=10, style='none') # Empty Space # Prefix and Suffix ================ @@ -293,135 +314,160 @@ def store_selection_type_persistent_settings(): cmds.separator(h=5, style='none') # Empty Space cmds.text('Prefix and Suffix') cmds.separator(h=7, style='none') # Empty Space - - cmds.rowColumnLayout( nc=4, cw=[(1, 50),(2, 50),(3, 50),(4, 85)], cs=[(1, 0),(2, 0),(3, 0),(4, 10)], p=body_column) + + cmds.rowColumnLayout(nc=4, cw=[(1, 50), (2, 50), (3, 50), (4, 85)], cs=[(1, 0), (2, 0), (3, 0), (4, 10)], + p=body_column) cmds.text('Prefix:') cmds.radioCollection() - add_prefix_auto = cmds.radioButton( label='Auto', select=True, cc=lambda x:update_prefix_suffix_options()) - cmds.radioButton( label='Input', cc=lambda x:update_prefix_suffix_options()) + add_prefix_auto = cmds.radioButton(label='Auto', select=True, cc=lambda x: update_prefix_suffix_options()) + cmds.radioButton(label='Input', cc=lambda x: update_prefix_suffix_options()) prefix_textfield = cmds.textField(placeholderText='prefix_', enterCommand=lambda x: start_renaming('add_prefix'), en=False) - + cmds.text('Suffix:') cmds.radioCollection() - add_suffix_auto = cmds.radioButton( label='Auto', select=True, cc=lambda x:update_prefix_suffix_options()) - cmds.radioButton( label='Input', cc=lambda x:update_prefix_suffix_options()) + add_suffix_auto = cmds.radioButton(label='Auto', select=True, cc=lambda x: update_prefix_suffix_options()) + cmds.radioButton(label='Input', cc=lambda x: update_prefix_suffix_options()) suffix_textfield = cmds.textField(placeholderText='_suffix', enterCommand=lambda x: start_renaming('add_suffix'), en=False) - + cmds.separator(h=10, style='none') # Empty Space - - cmds.rowColumnLayout( nc=6, cw=[(1, 40), (2, 40),(3, 40),(4, 40),(5, 40), (6, 40)], - cs=[(1, 5),(2, 0),(3, 0),(4, 0),(5, 0),(6, 0)], p=body_column) + + cmds.rowColumnLayout(nc=6, cw=[(1, 40), (2, 40), (3, 40), (4, 40), (5, 40), (6, 40)], + cs=[(1, 5), (2, 0), (3, 0), (4, 0), (5, 0), (6, 0)], p=body_column) cmds.text('Group', font='smallObliqueLabelFont') cmds.text('Mesh', font='smallObliqueLabelFont') cmds.text('Nurbs', font='smallObliqueLabelFont') cmds.text('Joint', font='smallObliqueLabelFont') cmds.text('Locator', font='smallObliqueLabelFont') cmds.text('Surface', font='smallObliqueLabelFont') - transform_suffix_textfield = cmds.textField(text = gt_renamer_settings.get('transform_suffix'), - enterCommand=lambda x:start_renaming('add_suffix'), - cc=lambda x:set_persistent_settings_renamer('gt_renamer_transform_suffix', cmds.textField(transform_suffix_textfield, q=True, text=True))) - mesh_suffix_textfield = cmds.textField(text = gt_renamer_settings.get('mesh_suffix'), - enterCommand=lambda x:start_renaming('add_suffix'), - cc=lambda x:set_persistent_settings_renamer('gt_renamer_mesh_suffix', cmds.textField(mesh_suffix_textfield, q=True, text=True))) - nurbs_curve_suffix_textfield = cmds.textField(text = gt_renamer_settings.get('nurbs_curv_suffix'), - enterCommand=lambda x:start_renaming('add_suffix'), - cc=lambda x:set_persistent_settings_renamer('gt_renamer_nurbs_curve_suffix', cmds.textField(nurbs_curve_suffix_textfield, q=True, text=True))) - joint_suffix_textfield = cmds.textField(text = gt_renamer_settings.get('joint_suffix'), - enterCommand=lambda x:start_renaming('add_suffix'), - cc=lambda x:set_persistent_settings_renamer('gt_renamer_joint_suffix', cmds.textField(joint_suffix_textfield, q=True, text=True))) - locator_suffix_textfield = cmds.textField(text = gt_renamer_settings.get('locator_suffix'), - enterCommand=lambda x:start_renaming('add_suffix'), - cc=lambda x:set_persistent_settings_renamer('gt_renamer_locator_suffix', cmds.textField(locator_suffix_textfield, q=True, text=True))) - surface_suffix_textfield = cmds.textField(text = gt_renamer_settings.get('surface_suffix'), - enterCommand=lambda x:start_renaming('add_suffix'), - cc=lambda x:set_persistent_settings_renamer('gt_renamer_surface_suffix', cmds.textField(surface_suffix_textfield, q=True, text=True))) - - cmds.separator(h=5, style='none') # Empty Space - - cmds.rowColumnLayout( nc=3, cw=[(1, 80),(2, 80),(3, 80)], cs=[(1, 5),(2, 0),(3, 0)], p=body_column) + transform_suffix_textfield = cmds.textField(text=gt_renamer_settings.get('transform_suffix'), + enterCommand=lambda x: start_renaming('add_suffix'), + cc=lambda x: set_persistent_settings_renamer( + 'gt_renamer_transform_suffix', + cmds.textField(transform_suffix_textfield, q=True, text=True))) + mesh_suffix_textfield = cmds.textField(text=gt_renamer_settings.get('mesh_suffix'), + enterCommand=lambda x: start_renaming('add_suffix'), + cc=lambda x: set_persistent_settings_renamer('gt_renamer_mesh_suffix', + cmds.textField( + mesh_suffix_textfield, + q=True, text=True))) + nurbs_curve_suffix_textfield = cmds.textField(text=gt_renamer_settings.get('nurbs_crv_suffix'), + enterCommand=lambda x: start_renaming('add_suffix'), + cc=lambda x: set_persistent_settings_renamer( + 'gt_renamer_nurbs_curve_suffix', + cmds.textField(nurbs_curve_suffix_textfield, q=True, text=True))) + joint_suffix_textfield = cmds.textField(text=gt_renamer_settings.get('joint_suffix'), + enterCommand=lambda x: start_renaming('add_suffix'), + cc=lambda x: set_persistent_settings_renamer('gt_renamer_joint_suffix', + cmds.textField( + joint_suffix_textfield, + q=True, text=True))) + locator_suffix_textfield = cmds.textField(text=gt_renamer_settings.get('locator_suffix'), + enterCommand=lambda x: start_renaming('add_suffix'), + cc=lambda x: set_persistent_settings_renamer('gt_renamer_locator_suffix', + cmds.textField( + locator_suffix_textfield, + q=True, text=True))) + surface_suffix_textfield = cmds.textField(text=gt_renamer_settings.get('surface_suffix'), + enterCommand=lambda x: start_renaming('add_suffix'), + cc=lambda x: set_persistent_settings_renamer('gt_renamer_surface_suffix', + cmds.textField( + surface_suffix_textfield, + q=True, text=True))) + + cmds.separator(h=5, style='none') # Empty Space + + cmds.rowColumnLayout(nc=3, cw=[(1, 80), (2, 80), (3, 80)], cs=[(1, 5), (2, 0), (3, 0)], p=body_column) cmds.text('Left', font='smallObliqueLabelFont') cmds.text('Center', font='smallObliqueLabelFont') cmds.text('Right', font='smallObliqueLabelFont') - left_prefix_textfield = cmds.textField(text = gt_renamer_settings.get('left_prefix') , \ - enterCommand=lambda x:start_renaming('add_suffix'), \ - cc=lambda x:set_persistent_settings_renamer('gt_renamer_left_prefix', cmds.textField(left_prefix_textfield, q=True, text=True))) - center_prefix_textfield = cmds.textField(text = gt_renamer_settings.get('center_prefix'), \ - enterCommand=lambda x:start_renaming('add_suffix'), \ - cc=lambda x:set_persistent_settings_renamer('gt_renamer_center_prefix', cmds.textField(center_prefix_textfield, q=True, text=True))) - right_prefix_textfield = cmds.textField(text = gt_renamer_settings.get('right_prefix'), \ - enterCommand=lambda x:start_renaming('add_suffix'), \ - cc=lambda x:set_persistent_settings_renamer('gt_renamer_right_prefix', cmds.textField(right_prefix_textfield, q=True, text=True))) - - cmds.separator(h=10, style='none') # Empty Space - cmds.rowColumnLayout(nc=2, cw=[(1, 120),(2, 120)], cs=[(1, 5),(2, 5)], p=body_column) - cmds.button(l ="Add Prefix", bgc=(.6, .6, .6), c=lambda x:start_renaming('add_prefix')) - cmds.button(l ="Add Suffix", bgc=(.6, .6, .6), c=lambda x:start_renaming('add_suffix')) - cmds.separator(h=10, style='none') # Empty Space - - + left_prefix_textfield = cmds.textField(text=gt_renamer_settings.get('left_prefix'), + enterCommand=lambda x: start_renaming('add_suffix'), + cc=lambda x: set_persistent_settings_renamer('gt_renamer_left_prefix', + cmds.textField( + left_prefix_textfield, + q=True, text=True))) + center_prefix_textfield = cmds.textField(text=gt_renamer_settings.get('center_prefix'), + enterCommand=lambda x: start_renaming('add_suffix'), + cc=lambda x: set_persistent_settings_renamer('gt_renamer_center_prefix', + cmds.textField( + center_prefix_textfield, + q=True, text=True))) + right_prefix_textfield = cmds.textField(text=gt_renamer_settings.get('right_prefix'), + enterCommand=lambda x: start_renaming('add_suffix'), + cc=lambda x: set_persistent_settings_renamer('gt_renamer_right_prefix', + cmds.textField( + right_prefix_textfield, + q=True, text=True))) + + cmds.separator(h=10, style='none') # Empty Space + cmds.rowColumnLayout(nc=2, cw=[(1, 120), (2, 120)], cs=[(1, 5), (2, 5)], p=body_column) + cmds.button(l="Add Prefix", bgc=(.6, .6, .6), c=lambda x: start_renaming('add_prefix')) + cmds.button(l="Add Suffix", bgc=(.6, .6, .6), c=lambda x: start_renaming('add_suffix')) + cmds.separator(h=10, style='none') # Empty Space + # Search and Replace ================== - cmds.rowColumnLayout( nc=1, cw=[(1, 260)], cs=[(1, 0)], p=body_column) + cmds.rowColumnLayout(nc=1, cw=[(1, 260)], cs=[(1, 0)], p=body_column) cmds.separator(h=10) - cmds.separator(h=5, style='none') # Empty Space + cmds.separator(h=5, style='none') # Empty Space cmds.text('Search and Replace') - cmds.separator(h=7, style='none') # Empty Space - - cmds.rowColumnLayout( nc=2, cw=[(1, 70),(2, 150)], cs=[(1, 10),(2, 0)], p=body_column) + cmds.separator(h=7, style='none') # Empty Space + + cmds.rowColumnLayout(nc=2, cw=[(1, 70), (2, 150)], cs=[(1, 10), (2, 0)], p=body_column) cmds.text('Search:') - search_textfield = cmds.textField(placeholderText = 'search_text', enterCommand=lambda x:start_renaming('search_and_replace')) - + search_textfield = cmds.textField(placeholderText='search_text', + enterCommand=lambda x: start_renaming('search_and_replace')) + cmds.text('Replace:') - replace_textfield = cmds.textField(placeholderText = 'replace_text', enterCommand=lambda x:start_renaming('search_and_replace')) - - cmds.rowColumnLayout( nc=1, cw=[(1, 240)], cs=[(1, 10)], p=body_column) - cmds.separator(h=15, style='none') # Empty Space - cmds.button(l ="Search and Replace", bgc=(.6, .6, .6), c=lambda x:start_renaming('search_and_replace')) - cmds.separator(h=15, style='none') # Empty Space - - + replace_textfield = cmds.textField(placeholderText='replace_text', + enterCommand=lambda x: start_renaming('search_and_replace')) + + cmds.rowColumnLayout(nc=1, cw=[(1, 240)], cs=[(1, 10)], p=body_column) + cmds.separator(h=15, style='none') # Empty Space + cmds.button(l="Search and Replace", bgc=(.6, .6, .6), c=lambda x: start_renaming('search_and_replace')) + cmds.separator(h=15, style='none') # Empty Space + def update_prefix_suffix_options(): - """ Updates variables and UI when there is an user input (For the prefix and suffix options) """ + """ Updates variables and UI when there is user input (For the prefix and suffix options) """ if cmds.radioButton(add_prefix_auto, q=True, select=True): - prefix_auto_textfields = True - prefix_input_textfields = False + prefix_auto_text_fields = True + prefix_input_text_fields = False else: - prefix_auto_textfields = False - prefix_input_textfields = True - + prefix_auto_text_fields = False + prefix_input_text_fields = True + if cmds.radioButton(add_suffix_auto, q=True, select=True): - suffix_auto_textfields = True - suffix_input_textfields = False + suffix_auto_text_fields = True + suffix_input_text_fields = False else: - suffix_auto_textfields = False - suffix_input_textfields = True - - cmds.textField(transform_suffix_textfield, e=True, en=suffix_auto_textfields) - cmds.textField(mesh_suffix_textfield, e=True, en=suffix_auto_textfields) - cmds.textField(nurbs_curve_suffix_textfield, e=True, en=suffix_auto_textfields) - cmds.textField(joint_suffix_textfield, e=True, en=suffix_auto_textfields) - cmds.textField(locator_suffix_textfield, e=True, en=suffix_auto_textfields) - cmds.textField(surface_suffix_textfield, e=True, en=suffix_auto_textfields) - - cmds.textField(left_prefix_textfield, e=True, en=prefix_auto_textfields) - cmds.textField(center_prefix_textfield, e=True, en=prefix_auto_textfields) - cmds.textField(right_prefix_textfield, e=True, en=prefix_auto_textfields) - - cmds.textField(suffix_textfield, e=True, en=suffix_input_textfields) - cmds.textField(prefix_textfield, e=True, en=prefix_input_textfields) - - + suffix_auto_text_fields = False + suffix_input_text_fields = True + + cmds.textField(transform_suffix_textfield, e=True, en=suffix_auto_text_fields) + cmds.textField(mesh_suffix_textfield, e=True, en=suffix_auto_text_fields) + cmds.textField(nurbs_curve_suffix_textfield, e=True, en=suffix_auto_text_fields) + cmds.textField(joint_suffix_textfield, e=True, en=suffix_auto_text_fields) + cmds.textField(locator_suffix_textfield, e=True, en=suffix_auto_text_fields) + cmds.textField(surface_suffix_textfield, e=True, en=suffix_auto_text_fields) + + cmds.textField(left_prefix_textfield, e=True, en=prefix_auto_text_fields) + cmds.textField(center_prefix_textfield, e=True, en=prefix_auto_text_fields) + cmds.textField(right_prefix_textfield, e=True, en=prefix_auto_text_fields) + + cmds.textField(suffix_textfield, e=True, en=suffix_input_text_fields) + cmds.textField(prefix_textfield, e=True, en=prefix_input_text_fields) + def start_renaming(operation): """ Main function to rename elements, it uses a string to determine what operation to run. - Parameters: - operation (string): name of the operation to execute. (e.g. search_and_replace) + Args: + operation (string): name of the operation to execute. (e.g. search_and_replace) """ current_selection = cmds.ls(selection=True) is_operation_valid = True - + # Manage type of selection if cmds.radioButton(selection_type_selected, q=True, select=True): selection = cmds.ls(selection=True) @@ -433,14 +479,14 @@ def start_renaming(operation): selection = cmds.ls() for node in gt_renamer_settings.get('nodes_to_ignore'): if cmds.objExists(node): - selection.remove(node) + selection.remove(node) for node_type in gt_renamer_settings.get('node_types_to_ignore'): undesired_types = cmds.ls(type=node_type) for undesired_node in undesired_types: if cmds.objExists(undesired_node): if undesired_node in selection: selection.remove(undesired_node) - + # Check if something is selected if len(selection) == 0: cmds.warning('Nothing is selected!') @@ -448,19 +494,20 @@ def start_renaming(operation): # Start Renaming Operation if operation == 'search_and_replace': - search_string = cmds.textField(search_textfield, q=True, text=True) - replace_string = cmds.textField(replace_textfield, q=True, text=True) - rename_search_replace(selection, search_string, replace_string) + search_string = cmds.textField(search_textfield, q=True, text=True) + replace_string = cmds.textField(replace_textfield, q=True, text=True) + rename_search_replace(selection, search_string, replace_string) elif operation == 'rename_and_number': new_name = cmds.textField(rename_number_textfield, q=True, text=True) - - if cmds.textField(start_number_textfield, q=True, text=True).isdigit() and cmds.textField(padding_number_textfield, q=True, text=True).isdigit(): + + if cmds.textField(start_number_textfield, q=True, text=True).isdigit() and cmds.textField( + padding_number_textfield, q=True, text=True).isdigit(): start_number = int(cmds.textField(start_number_textfield, q=True, text=True)) padding_number = int(cmds.textField(padding_number_textfield, q=True, text=True)) rename_and_number(selection, new_name, start_number, padding_number) else: cmds.warning('Start Number and Padding Number must be digits (numbers)') - elif operation == 'add_prefix': + elif operation == 'add_prefix': prefix_list = [] if cmds.radioButton(add_prefix_auto, q=True, select=True): left_prefix_input = cmds.textField(left_prefix_textfield, q=True, text=True) @@ -472,29 +519,29 @@ def start_renaming(operation): else: new_prefix = cmds.textField(prefix_textfield, q=True, text=True) prefix_list.append(new_prefix) - + rename_add_prefix(selection, prefix_list) - + elif operation == 'add_suffix': - + suffix_list = [] if cmds.radioButton(add_suffix_auto, q=True, select=True): transform_suffix_input = cmds.textField(transform_suffix_textfield, q=True, text=True) mesh_suffix_input = cmds.textField(mesh_suffix_textfield, q=True, text=True) - nurbsCurv_suffix_input = cmds.textField(nurbs_curve_suffix_textfield, q=True, text=True) + nurbs_crv_suffix_input = cmds.textField(nurbs_curve_suffix_textfield, q=True, text=True) joint_suffix_input = cmds.textField(joint_suffix_textfield, q=True, text=True) locator_suffix_input = cmds.textField(locator_suffix_textfield, q=True, text=True) surface_suffix_input = cmds.textField(surface_suffix_textfield, q=True, text=True) suffix_list.append(transform_suffix_input) suffix_list.append(mesh_suffix_input) - suffix_list.append(nurbsCurv_suffix_input) + suffix_list.append(nurbs_crv_suffix_input) suffix_list.append(joint_suffix_input) suffix_list.append(locator_suffix_input) suffix_list.append(surface_suffix_input) else: new_suffix = cmds.textField(suffix_textfield, q=True, text=True) suffix_list.append(new_suffix) - + rename_add_suffix(selection, suffix_list) elif operation == 'remove_first_letter': remove_first_letter(selection) @@ -506,10 +553,10 @@ def start_renaming(operation): rename_capitalize(selection) elif operation == 'lowercase_names': rename_lowercase(selection) - + # Undo function if is_operation_valid: - cmds.undoInfo(openChunk=True, chunkName=script_name) + cmds.undoInfo(openChunk=True, chunkName=script_name) try: pass except Exception as e: @@ -517,21 +564,16 @@ def start_renaming(operation): cmds.error("## Error, see script editor: %s" % e) finally: cmds.undoInfo(closeChunk=True, chunkName=script_name) - - + # Show and Lock Window - cmds.showWindow(build_gui_renamer) + cmds.showWindow(window_gui_renamer) cmds.window(window_name, e=True, s=False) - + # Set Window Icon - qw = omui.MQtUtil.findWindow(window_name) - if python_version == 3: - widget = wrapInstance(int(qw), QWidget) - else: - widget = wrapInstance(long(qw), QWidget) + qw = OpenMayaUI.MQtUtil.findWindow(window_name) + widget = wrapInstance(int(qw), QWidget) icon = QIcon(':/renamePreset.png') widget.setWindowIcon(icon) - def build_gui_help_renamer(): @@ -540,30 +582,30 @@ def build_gui_help_renamer(): if cmds.window(window_name, exists=True): cmds.deleteUI(window_name, window=True) - cmds.window(window_name, title= script_name + " Help", mnb=False, mxb=False, s=True) - cmds.window(window_name, e=True, s=True, wh=[1,1]) + cmds.window(window_name, title=script_name + " Help", mnb=False, mxb=False, s=True) + cmds.window(window_name, e=True, s=True, wh=[1, 1]) + + main_column = cmds.columnLayout(p=window_name) - main_column = cmds.columnLayout(p= window_name) - # Title Text - cmds.separator(h=12, style='none') # Empty Space - cmds.rowColumnLayout(nc=1, cw=[(1, 310)], cs=[(1, 10)], p=main_column) # Window Size Adjustment - cmds.rowColumnLayout(nc=1, cw=[(1, 300)], cs=[(1, 10)], p=main_column) # Title Column - cmds.text(script_name + " Help", bgc=[.4,.4,.4], fn="boldLabelFont", align="center") - cmds.separator(h=10, style='none', p=main_column) # Empty Space + cmds.separator(h=12, style='none') # Empty Space + cmds.rowColumnLayout(nc=1, cw=[(1, 310)], cs=[(1, 10)], p=main_column) # Window Size Adjustment + cmds.rowColumnLayout(nc=1, cw=[(1, 300)], cs=[(1, 10)], p=main_column) # Title Column + cmds.text(script_name + " Help", bgc=[.4, .4, .4], fn="boldLabelFont", align="center") + cmds.separator(h=10, style='none', p=main_column) # Empty Space # Body ==================== - cmds.rowColumnLayout(nc=1, cw=[(1, 300)], cs=[(1,10)], p=main_column) + cmds.rowColumnLayout(nc=1, cw=[(1, 300)], cs=[(1, 10)], p=main_column) cmds.text(l='Script for renaming multiple objects.', align="center") - cmds.separator(h=15, style='none') # Empty Space - + cmds.separator(h=15, style='none') # Empty Space + cmds.text(l='Modes:', align="center", fn="tinyBoldLabelFont") cmds.text(l='- Selected: uses selected objects when renaming.', align="left", font='smallPlainLabelFont') cmds.text(l='- Hierarchy: uses hierarchy when renaming.', align="left", font='smallPlainLabelFont') cmds.text(l='- All: uses everything in the scene (even hidden nodes)', align="left", font='smallPlainLabelFont') - - cmds.separator(h=10, style='none') # Empty Space - + + cmds.separator(h=10, style='none') # Empty Space + cmds.text(l='Other Tools:', align="center", fn="tinyBoldLabelFont") cmds.text(l='- Remove First Letter: removes the first letter of a name.', align="left", font='smallPlainLabelFont') cmds.text(l='If the next character is a number, it will be deleted.', align="left", font='smallPlainLabelFont') @@ -571,97 +613,92 @@ def build_gui_help_renamer(): cmds.text(l='- U-Case: makes all letters uppercase.', align="left", font='smallPlainLabelFont') cmds.text(l='- Capitalize: makes the 1st letter of every word uppercase.', align="left", font='smallPlainLabelFont') cmds.text(l='- L-Case: makes all letters lowercase.', align="left", font='smallPlainLabelFont') - - cmds.separator(h=10, style='none') # Empty Space - + + cmds.separator(h=10, style='none') # Empty Space + cmds.text(l='Rename and Number:', align="center", fn="tinyBoldLabelFont") cmds.text(l='Renames selected objects and number them.', align="left", font='smallPlainLabelFont') - cmds.text(l='- Start # : first number when countaing the new names.', align="left", font='smallPlainLabelFont') + cmds.text(l='- Start # : first number when counting the new names.', align="left", font='smallPlainLabelFont') cmds.text(l='- Padding : how many zeros before the number. e.g. "001"', align="left", font='smallPlainLabelFont') - cmds.separator(h=10, style='none') # Empty Space - + cmds.separator(h=10, style='none') # Empty Space + cmds.text(l='Prefix and Suffix:', align="center", fn="tinyBoldLabelFont") cmds.text(l='Prefix: adds a string in front of a name.', align="left", font='smallPlainLabelFont') cmds.text(l='Suffix: adds a string at the end of a name.', align="left", font='smallPlainLabelFont') - cmds.separator(h=5, style='none') # Empty Space + cmds.separator(h=5, style='none') # Empty Space cmds.text(l=' - Auto: Uses the provided strings to automatically name', align="left", font='smallPlainLabelFont') cmds.text(l='objects according to their type or position.', align="left", font='smallPlainLabelFont') cmds.text(l='1st example: a mesh would automatically receive "_geo"', align="left", font='smallPlainLabelFont') cmds.text(l='2nd example: an object in positive side of X, would', align="left", font='smallPlainLabelFont') cmds.text(l='automatically receive "left_"', align="left", font='smallPlainLabelFont') - cmds.separator(h=5, style='none') # Empty Space + cmds.separator(h=5, style='none') # Empty Space cmds.text(l=' - Input: uses the provided text as a prefix or suffix.', align="left", font='smallPlainLabelFont') - cmds.separator(h=10, style='none') # Empty Space - + cmds.separator(h=10, style='none') # Empty Space + cmds.text(l='Search and Replace:', align="center", fn="tinyBoldLabelFont") cmds.text(l='Uses the well-known method of search and replace', align="left", font='smallPlainLabelFont') cmds.text(l='to rename objects.', align="left", font='smallPlainLabelFont') - cmds.separator(h=10, style='none') # Empty Space - - cmds.rowColumnLayout(nc=2, cw=[(1, 140),(2, 140)], cs=[(1,10),(2, 0)], p=main_column) + cmds.separator(h=10, style='none') # Empty Space + + cmds.rowColumnLayout(nc=2, cw=[(1, 140), (2, 140)], cs=[(1, 10), (2, 0)], p=main_column) cmds.text('Guilherme Trevisan ') - cmds.text(l='TrevisanGMW@gmail.com', hl=True, highlightColor=[1,1,1]) - cmds.rowColumnLayout(nc=2, cw=[(1, 140),(2, 140)], cs=[(1,10),(2, 0)], p=main_column) - cmds.separator(h=10, style='none') # Empty Space - cmds.text(l='Github', hl=True, highlightColor=[1,1,1]) - cmds.separator(h=7, style='none') # Empty Space - + cmds.text(l='TrevisanGMW@gmail.com', hl=True, highlightColor=[1, 1, 1]) + cmds.rowColumnLayout(nc=2, cw=[(1, 140), (2, 140)], cs=[(1, 10), (2, 0)], p=main_column) + cmds.separator(h=10, style='none') # Empty Space + cmds.text(l='Github', hl=True, highlightColor=[1, 1, 1]) + cmds.separator(h=7, style='none') # Empty Space + # Close Button - cmds.rowColumnLayout(nc=1, cw=[(1, 300)], cs=[(1,10)], p=main_column) - + cmds.rowColumnLayout(nc=1, cw=[(1, 300)], cs=[(1, 10)], p=main_column) + cmds.separator(h=10, style='none') cmds.button(l='Reset Persistent Settings', h=30, c=lambda args: reset_persistent_settings_renamer()) cmds.separator(h=5, style='none') cmds.button(l='OK', h=30, c=lambda args: close_help_gui()) cmds.separator(h=8, style='none') - + # Show and Lock Window cmds.showWindow(window_name) cmds.window(window_name, e=True, s=False) - + # Set Window Icon - qw = omui.MQtUtil.findWindow(window_name) - if python_version == 3: - widget = wrapInstance(int(qw), QWidget) - else: - widget = wrapInstance(long(qw), QWidget) + qw = OpenMayaUI.MQtUtil.findWindow(window_name) + widget = wrapInstance(int(qw), QWidget) icon = QIcon(':/question.png') widget.setWindowIcon(icon) - + def close_help_gui(): if cmds.window(window_name, exists=True): cmds.deleteUI(window_name, window=True) - def string_replace(string, search, replace): """ Search and Replace Function for a String - Parameters: - string (string): string to be processed - search (string): what to search for - replace (string): what to replace it with + Args: + string (string): string to be processed + search (string): what to search for + replace (string): what to replace it with """ if string == '': return '' - replace_string = string.replace(search, replace) + replace_string = string.replace(search, replace) return replace_string - def get_short_name(obj): """ Get the name of the objects without its path (Maya returns full path if name is not unique) - Parameters: - obj (string) - object to extract short name + Args: + obj (string) - object to extract short name """ if obj == '': return '' split_path = obj.split('|') if len(split_path) >= 1: - short_name = split_path[len(split_path)-1] + short_name = split_path[len(split_path) - 1] return short_name @@ -669,18 +706,18 @@ def rename_uppercase(obj_list): """ Rename objects to be uppercase - Parameters: - obj_list (list) - a list of objects (strings) to be renamed + Args: + obj_list (list) - a list of objects (strings) to be renamed """ to_rename = [] errors = '' - + for obj in obj_list: object_short_name = get_short_name(obj) new_name = object_short_name.upper() if cmds.objExists(obj) and 'shape' not in cmds.nodeType(obj, inherited=True) and obj != new_name: - to_rename.append([obj,new_name]) - + to_rename.append([obj, new_name]) + for pair in reversed(to_rename): if cmds.objExists(pair[0]): try: @@ -688,29 +725,30 @@ def rename_uppercase(obj_list): except Exception as exception: errors = errors + '"' + str(pair[0]) + '" : "' + exception[0].rstrip("\n") + '".\n' if errors != '': - print('#' * 80 + '\n') - print(errors) - print('#' * 80) - cmds.warning(gt_renamer_settings.get('error_message')) - + print('#' * 80 + '\n') + print(errors) + print('#' * 80) + cmds.warning(gt_renamer_settings.get('error_message')) + renaming_inview_feedback(len(to_rename)) + def rename_lowercase(obj_list): """ Rename objects to be lowercase - Parameters: - obj_list (list) - a list of objects (strings) to be renamed + Args: + obj_list (list) - a list of objects (strings) to be renamed """ to_rename = [] errors = '' - + for obj in obj_list: object_short_name = get_short_name(obj) new_name = object_short_name.lower() if cmds.objExists(obj) and 'shape' not in cmds.nodeType(obj, inherited=True) and obj != new_name: - to_rename.append([obj,new_name]) - + to_rename.append([obj, new_name]) + for pair in reversed(to_rename): if cmds.objExists(pair[0]): try: @@ -718,11 +756,11 @@ def rename_lowercase(obj_list): except Exception as exception: errors = errors + '"' + str(pair[0]) + '" : "' + exception[0].rstrip("\n") + '".\n' if errors != '': - print('#' * 80 + '\n') - print(errors) - print('#' * 80) - cmds.warning(gt_renamer_settings.get('error_message')) - + print('#' * 80 + '\n') + print(errors) + print('#' * 80) + cmds.warning(gt_renamer_settings.get('error_message')) + renaming_inview_feedback(len(to_rename)) @@ -730,27 +768,27 @@ def rename_capitalize(obj_list): """ Rename objects to be capitalized - Parameters: - obj_list (list) - a list of objects (strings) to be renamed + Args: + obj_list (list) - a list of objects (strings) to be renamed """ to_rename = [] errors = '' - + for obj in obj_list: object_short_name = get_short_name(obj) object_short_name_split = object_short_name.split('_') - + if len(object_short_name_split) > 1: new_name = '' for name in object_short_name_split: new_name = new_name + name.capitalize() + '_' new_name = new_name[:-1] else: - new_name = object_short_name.capitalize() - + new_name = object_short_name.capitalize() + if cmds.objExists(obj) and 'shape' not in cmds.nodeType(obj, inherited=True) and obj != new_name: - to_rename.append([obj,new_name]) - + to_rename.append([obj, new_name]) + for pair in reversed(to_rename): if cmds.objExists(pair[0]): try: @@ -758,11 +796,11 @@ def rename_capitalize(obj_list): except Exception as exception: errors = errors + '"' + str(pair[0]) + '" : "' + exception[0].rstrip("\n") + '".\n' if errors != '': - print('#' * 80 + '\n') - print(errors) - print('#' * 80) - cmds.warning(gt_renamer_settings.get('error_message')) - + print('#' * 80 + '\n') + print(errors) + print('#' * 80) + cmds.warning(gt_renamer_settings.get('error_message')) + renaming_inview_feedback(len(to_rename)) @@ -770,26 +808,26 @@ def remove_first_letter(obj_list): """ Rename objects removing the first letter - Parameters: - obj_list (list) - a list of objects (strings) to be renamed + Args: + obj_list (list) - a list of objects (strings) to be renamed """ to_rename = [] errors = '' - + for obj in obj_list: object_short_name = get_short_name(obj) is_char = False - + if len(object_short_name) > 1: new_name = object_short_name[1:] else: is_char = True new_name = object_short_name cmds.warning('"' + object_short_name + '" is just one letter. You can\'t remove it.') - - if cmds.objExists(obj) and 'shape' not in cmds.nodeType(obj, inherited=True) and is_char == False: - to_rename.append([obj,new_name]) - + + if cmds.objExists(obj) and 'shape' not in cmds.nodeType(obj, inherited=True) and is_char is False: + to_rename.append([obj, new_name]) + for pair in reversed(to_rename): if cmds.objExists(pair[0]): try: @@ -797,11 +835,11 @@ def remove_first_letter(obj_list): except Exception as exception: errors = errors + '"' + str(pair[0]) + '" : "' + exception[0].rstrip("\n") + '".\n' if errors != '': - print('#' * 80 + '\n') - print(errors) - print('#' * 80) - cmds.warning(gt_renamer_settings.get('error_message')) - + print('#' * 80 + '\n') + print(errors) + print('#' * 80) + cmds.warning(gt_renamer_settings.get('error_message')) + renaming_inview_feedback(len(to_rename)) @@ -809,26 +847,26 @@ def remove_last_letter(obj_list): """ Rename objects removing the last letter - Parameters: - obj_list (list) - a list of objects (strings) to be renamed + Args: + obj_list (list) - a list of objects (strings) to be renamed """ to_rename = [] errors = '' - + for obj in obj_list: object_short_name = get_short_name(obj) is_char = False - + if len(object_short_name) > 1: new_name = object_short_name[:-1] else: is_char = True new_name = object_short_name cmds.warning('"' + object_short_name + '" is just one letter. You can\'t remove it.') - - if cmds.objExists(obj) and 'shape' not in cmds.nodeType(obj, inherited=True) and is_char == False: - to_rename.append([obj,new_name]) - + + if cmds.objExists(obj) and 'shape' not in cmds.nodeType(obj, inherited=True) and is_char is False: + to_rename.append([obj, new_name]) + for pair in reversed(to_rename): if cmds.objExists(pair[0]): try: @@ -836,11 +874,11 @@ def remove_last_letter(obj_list): except Exception as exception: errors = errors + '"' + str(pair[0]) + '" : "' + exception[0].rstrip("\n") + '".\n' if errors != '': - print('#' * 80 + '\n') - print(errors) - print('#' * 80) - cmds.warning(gt_renamer_settings.get('error_message')) - + print('#' * 80 + '\n') + print(errors) + print('#' * 80) + cmds.warning(gt_renamer_settings.get('error_message')) + renaming_inview_feedback(len(to_rename)) @@ -848,66 +886,66 @@ def rename_search_replace(obj_list, search, replace): """ Rename Using Search and Replace - Parameters: - obj_list (list): a list of objects (strings) to be renamed - search (string): what to search for - replace (string): what to replace it with + Args: + obj_list (list): a list of objects (strings) to be renamed + search (string): what to search for + replace (string): what to replace it with """ if search == '': cmds.warning('The search string must not be empty.') - else: + else: to_rename = [] - + for obj in obj_list: object_short_name = get_short_name(obj) new_name = string_replace(str(object_short_name), search, replace) if cmds.objExists(obj) and 'shape' not in cmds.nodeType(obj, inherited=True) and obj != new_name: - to_rename.append([obj,new_name]) - + to_rename.append([obj, new_name]) + for pair in reversed(to_rename): if cmds.objExists(pair[0]): cmds.rename(pair[0], pair[1]) - + renaming_inview_feedback(len(to_rename)) - + def rename_and_number(obj_list, new_name, start_number, padding_number): """ Rename Objects and Add Number (With Padding) - Parameters: - obj_list (list): a list of objects (strings) to be renamed - new_name (string): a new name to rename the objects - start_number (int): what number to start counting from - padding_number (int): how many zeroes it will add before numbers + Args: + obj_list (list): a list of objects (strings) to be renamed + new_name (string): a new name to rename the objects + start_number (int): what number to start counting from + padding_number (int): how many zeroes it will add before numbers """ if new_name == '': cmds.warning('The provided string must not be empty.') - else: + else: to_rename = [] count = start_number errors = '' - + for obj in obj_list: - object_short_name = get_short_name(obj) + # object_short_name = get_short_name(obj) new_name_and_number = new_name + str(count).zfill(padding_number) if cmds.objExists(obj) and 'shape' not in cmds.nodeType(obj, inherited=True): - to_rename.append([obj,new_name_and_number]) + to_rename.append([obj, new_name_and_number]) count += 1 - + for pair in reversed(to_rename): if cmds.objExists(pair[0]): try: cmds.rename(pair[0], pair[1]) except Exception as exception: errors = errors + '"' + str(pair[0]) + '" : "' + exception[0].rstrip("\n") + '".\n' - + if errors != '': print('#' * 80 + '\n') print(errors) print('#' * 80) cmds.warning(gt_renamer_settings.get('error_message')) - + renaming_inview_feedback(len(to_rename)) @@ -915,31 +953,33 @@ def rename_add_prefix(obj_list, new_prefix_list): """ Add Prefix - Parameters: - obj_list (list): a list of objects (strings) to be renamed - new_prefix_list (list) - a list of prefix strings, if just one it assumes that it's a manual input, if more (3) it automates (usually left, center, right) + Args: + obj_list (list): a list of objects (strings) to be renamed + new_prefix_list (list): a list of prefix strings, if just one it assumes that it's a manual input, + if more (3) it automates (usually left, center, right) """ - + auto_prefix = True if len(new_prefix_list) == 1: auto_prefix = False new_prefix = new_prefix_list[0] - - if auto_prefix == False and new_prefix == '': + + if auto_prefix is False and new_prefix == '': cmds.warning('Prefix Input must not be empty.') - else: + else: to_rename = [] errors = '' for obj in obj_list: if auto_prefix and 'shape' not in cmds.nodeType(obj, inherited=True): try: - obj_x_pos = cmds.xform(obj, piv=True , q=True , ws=True)[0] - except: + obj_x_pos = cmds.xform(obj, piv=True, q=True, ws=True)[0] + except Exception as e: + logger.debug(str(e)) obj_x_pos = 'Unknown' if obj_x_pos == 'Unknown': new_prefix = '' elif obj_x_pos > 0.0001: - new_prefix= new_prefix_list[0] + new_prefix = new_prefix_list[0] elif obj_x_pos < -0.0001: new_prefix = new_prefix_list[2] else: @@ -948,63 +988,62 @@ def rename_add_prefix(obj_list, new_prefix_list): new_prefix = '' if not auto_prefix: new_prefix = new_prefix_list[0] - + object_short_name = get_short_name(obj) - + if object_short_name.startswith(new_prefix): new_name_and_prefix = object_short_name else: new_name_and_prefix = new_prefix + object_short_name - + if cmds.objExists(obj) and 'shape' not in cmds.nodeType(obj, inherited=True) and obj != new_name_and_prefix: - to_rename.append([obj,new_name_and_prefix]) - + to_rename.append([obj, new_name_and_prefix]) + for pair in reversed(to_rename): if cmds.objExists(pair[0]): try: cmds.rename(pair[0], pair[1]) except Exception as exception: errors = errors + '"' + str(pair[0]) + '" : "' + exception[0].rstrip("\n") + '".\n' - - + if errors != '': print('#' * 80 + '\n') print(errors) print('#' * 80) cmds.warning(gt_renamer_settings.get('error_message')) - + renaming_inview_feedback(len(to_rename)) - + def rename_add_suffix(obj_list, new_suffix_list): """ Add Suffix - Parameters: - obj_list (list): a list of objects (strings) to be renamed - new_suffix_list (list): - a list of suffix strings, if just one it assumes that it's a manual input, if more (6) it automates (usually _geo,_jnt, etc...) + Args: + obj_list (list): a list of objects (strings) to be renamed + new_suffix_list (list): a list of suffix strings, if just one it assumes that it's a manual input, + if more (6) it automates (usually _geo,_jnt, etc...) """ auto_suffix = True - + if len(new_suffix_list) == 1: auto_suffix = False new_suffix = new_suffix_list[0] - - if auto_suffix == False and new_suffix == '': + + if auto_suffix is False and new_suffix == '': cmds.warning('Suffix Input must not be empty.') - else: + else: to_rename = [] errors = '' for obj in obj_list: if auto_suffix and 'shape' not in cmds.nodeType(obj, inherited=True): - object_type = '' object_shape = cmds.listRelatives(obj, shapes=True, fullPath=True) or [] if len(object_shape) > 0: object_type = cmds.objectType(object_shape[0]) else: object_type = cmds.objectType(obj) - + if object_type == 'transform': new_suffix = new_suffix_list[0] elif object_type == 'mesh': @@ -1018,53 +1057,54 @@ def rename_add_suffix(obj_list, new_suffix_list): elif object_type == 'nurbsSurface': new_suffix = new_suffix_list[5] else: - new_suffix ='' + new_suffix = '' else: new_suffix = '' if not auto_suffix: new_suffix = new_suffix_list[0] - + object_short_name = get_short_name(obj) - + if object_short_name.endswith(new_suffix): new_name_and_suffix = object_short_name else: new_name_and_suffix = object_short_name + new_suffix - + if cmds.objExists(obj) and 'shape' not in cmds.nodeType(obj, inherited=True) and obj != new_name_and_suffix: - to_rename.append([obj,new_name_and_suffix]) - + to_rename.append([obj, new_name_and_suffix]) + for pair in reversed(to_rename): if cmds.objExists(pair[0]): try: cmds.rename(pair[0], pair[1]) except Exception as exception: errors = errors + '"' + str(pair[0]) + '" : "' + exception[0].rstrip("\n") + '".\n' - + if errors != '': print('#' * 80 + '\n') print(errors) print('#' * 80) cmds.warning(gt_renamer_settings.get('error_message')) - + renaming_inview_feedback(len(to_rename)) - - + + def rename_and_alphabetize(obj_list, new_name): """ WIP - Rename Objects and Add Letter (Alphabetical Order) - Work in Progress - Parameters: - obj_list (list): a list of objects (strings) to be renamed - new_name - WIP + Args: + obj_list (list): a list of objects (strings) to be renamed + new_name (string) : Work in Progress """ - alphabet_array = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"] + alphabet_array = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", + "T", "U", "V", "W", "X", "Y", "Z"] print([len(alphabet_array)]) current_letter_index = 0 multiple_letter_patch = '' multiple_letter_index = 0 for obj in obj_list: - object_short_name = get_short_name(obj) + # object_short_name = get_short_name(obj) new_name_and_letter = new_name + multiple_letter_patch + alphabet_array[current_letter_index] current_letter_index += 1 if current_letter_index == 25: @@ -1077,19 +1117,21 @@ def renaming_inview_feedback(number_of_renames): Prints an inViewMessage to give feedback to the user about how many objects were renamed. Uses the module "random" to force identical messages to appear at the same time. - Parameters: - number_of_renames (int): how many objects were renamed. + Args: + number_of_renames (int): how many objects were renamed. """ if number_of_renames != 0: - message = '<' + str(random.random()) + '>' + str(number_of_renames) - - if number_of_renames == 1: - message += ' object was renamed.' - else: - message += ' objects were renamed.' - cmds.inViewMessage(amg=message, pos='botLeft', fade=True, alpha=.9) + message = '<' + str(random.random()) + '>' + str( + number_of_renames) + + if number_of_renames == 1: + message += ' object was renamed.' + else: + message += ' objects were renamed.' + cmds.inViewMessage(amg=message, pos='botLeft', fade=True, alpha=.9) + # Run Script get_persistent_settings_renamer() if __name__ == '__main__': - build_gui_renamer() \ No newline at end of file + build_gui_renamer() diff --git a/python-scripts/gt_rigger_corrective_logic.py b/python-scripts/gt_rigger_corrective_logic.py index f1bf14c2..1688afd0 100644 --- a/python-scripts/gt_rigger_corrective_logic.py +++ b/python-scripts/gt_rigger_corrective_logic.py @@ -2024,7 +2024,7 @@ def merge_corrective_elements(): persp_pos = cmds.getAttr('persp.translate')[0] persp_rot = cmds.getAttr('persp.rotate')[0] import gt_maya_utilities - gt_maya_utilities.gtu_reload_file() + gt_maya_utilities.force_reload_file() cmds.viewFit(all=True) cmds.setAttr('persp.tx', persp_pos[0]) cmds.setAttr('persp.ty', persp_pos[1]) diff --git a/python-scripts/gt_rigger_facial_logic.py b/python-scripts/gt_rigger_facial_logic.py index 892c554a..c8486b3b 100644 --- a/python-scripts/gt_rigger_facial_logic.py +++ b/python-scripts/gt_rigger_facial_logic.py @@ -3649,7 +3649,7 @@ def merge_facial_elements(): persp_rot = cmds.getAttr('persp.rotate')[0] import gt_maya_utilities - gt_maya_utilities.gtu_reload_file() + gt_maya_utilities.force_reload_file() cmds.viewFit(all=True) cmds.setAttr('persp.tx', persp_pos[0]) cmds.setAttr('persp.ty', persp_pos[1]) diff --git a/python-scripts/gt_rigger_retarget_assistant.py b/python-scripts/gt_rigger_retarget_assistant.py index 071a5af0..29026223 100644 --- a/python-scripts/gt_rigger_retarget_assistant.py +++ b/python-scripts/gt_rigger_retarget_assistant.py @@ -1556,7 +1556,7 @@ def get_joint_orientation(obj, expected_up=(0, 1, 0)): persp_pos = cmds.getAttr('persp.translate')[0] persp_rot = cmds.getAttr('persp.rotate')[0] import gt_maya_utilities - gt_maya_utilities.gtu_reload_file() + gt_maya_utilities.force_reload_file() cmds.viewFit(all=True) cmds.setAttr('persp.tx', persp_pos[0]) cmds.setAttr('persp.ty', persp_pos[1])