Created
May 2, 2025 20:14
-
-
Save Pakmanv/afcf09ce40e4508e9adeb04bdb6f5a60 to your computer and use it in GitHub Desktop.
Multi Corrective VV 1.1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import maya.cmds as cmds | |
| def create_blendshape_tool_ui(): | |
| """Create a UI for connecting blendshapes with correctional and source shapes.""" | |
| window_name = "MultiCorrectiveVV11Window" | |
| if cmds.window(window_name, exists=True): | |
| cmds.deleteUI(window_name) | |
| window = cmds.window(window_name, title="Multi Corrective VV 1.1", widthHeight=(400, 600)) | |
| main_layout = cmds.columnLayout(adjustableColumn=True, rowSpacing=5) | |
| global corrective_shape, source_shapes, target_shapes | |
| corrective_shape = [] | |
| source_shapes = [] | |
| target_shapes = [] | |
| # Corrective Shape Section | |
| cmds.text(label="Corrective Shape") | |
| corrective_field = cmds.textScrollList(allowMultiSelection=False) | |
| cmds.button(label="Load Corrective Shape", command=lambda *args: load_corrective_shape()) | |
| def load_corrective_shape(*args): | |
| global corrective_shape | |
| selected = cmds.ls(selection=True, type="transform") | |
| if len(selected) != 1: | |
| cmds.warning("Please select exactly one corrective shape.") | |
| return | |
| if cmds.listRelatives(selected[0], shapes=True) is None: | |
| cmds.warning("Selected object is a group. Please select a mesh.") | |
| return | |
| corrective_shape = selected | |
| cmds.textScrollList(corrective_field, edit=True, removeAll=True) | |
| cmds.textScrollList(corrective_field, edit=True, append=selected[0]) | |
| cmds.select(clear=True) | |
| print(f"Loaded corrective shape: {selected[0]}") | |
| # Source Blendshapes Section | |
| cmds.text(label="Source Blendshapes") | |
| source_field = cmds.textScrollList(allowMultiSelection=True, height=200) | |
| source_count_label = cmds.text(label="Source Blendshapes (0 objects)") | |
| cmds.button(label="Load Source Blendshapes", command=lambda *args: load_source_shapes()) | |
| def load_source_shapes(*args): | |
| global source_shapes | |
| selected = cmds.ls(selection=True, type="transform") | |
| if not selected: | |
| cmds.warning("Please select at least one source blendshape.") | |
| return | |
| valid_shapes = [obj for obj in selected if cmds.listRelatives(obj, shapes=True)] | |
| if not valid_shapes: | |
| cmds.warning("No valid mesh objects selected for source blendshapes.") | |
| return | |
| source_shapes = valid_shapes | |
| cmds.textScrollList(source_field, edit=True, removeAll=True) | |
| for shape in valid_shapes: | |
| cmds.textScrollList(source_field, edit=True, append=shape) | |
| cmds.text(source_count_label, edit=True, label=f"Source Blendshapes ({len(valid_shapes)} objects)") | |
| cmds.select(clear=True) | |
| print(f"Loaded {len(valid_shapes)} source blendshapes: {valid_shapes}") | |
| # Target Shapes Section | |
| cmds.text(label="Target Shapes") | |
| target_field = cmds.textScrollList(allowMultiSelection=True, height=200) | |
| target_count_label = cmds.text(label="Target Shapes (0 objects)") | |
| cmds.button(label="Load Target Shapes", command=lambda *args: load_target_shapes()) | |
| def load_target_shapes(*args): | |
| global target_shapes | |
| selected = cmds.ls(selection=True, type="transform") | |
| if not selected: | |
| cmds.warning("Please select at least one target shape.") | |
| return | |
| valid_shapes = [obj for obj in selected if cmds.listRelatives(obj, shapes=True)] | |
| if not valid_shapes: | |
| cmds.warning("No valid mesh objects selected for target shapes.") | |
| return | |
| target_shapes = valid_shapes | |
| cmds.textScrollList(target_field, edit=True, removeAll=True) | |
| for shape in valid_shapes: | |
| cmds.textScrollList(target_field, edit=True, append=shape) | |
| cmds.text(target_count_label, edit=True, label=f"Target Shapes ({len(valid_shapes)} objects)") | |
| cmds.select(clear=True) | |
| print(f"Loaded {len(valid_shapes)} target shapes: {valid_shapes}") | |
| def connect_shapes(*args): | |
| try: | |
| if not corrective_shape: | |
| cmds.warning("No corrective shape loaded.") | |
| return | |
| if not source_shapes: | |
| cmds.warning("No source blendshapes loaded.") | |
| return | |
| if not target_shapes: | |
| cmds.warning("No target shapes loaded.") | |
| return | |
| if len(source_shapes) != len(target_shapes): | |
| cmds.warning("Source and target shapes must have the same number of objects.") | |
| return | |
| corrective = corrective_shape[0] | |
| for i, (source, target) in enumerate(zip(source_shapes, target_shapes)): | |
| print(f"Processing pair {i+1}: corrective={corrective}, source={source}, target={target}") | |
| blendshape_node = cmds.blendShape(corrective, source, target, name=f"transfer_{target}", frontOfChain=True)[0] | |
| corrective_attr = f"{blendshape_node}.{corrective}" | |
| if not cmds.getAttr(corrective_attr, lock=True) and not cmds.listConnections(corrective_attr, source=True): | |
| cmds.setAttr(corrective_attr, 1) | |
| else: | |
| print(f"Skipped setting {corrective_attr}: Attribute is locked or connected.") | |
| source_attr = f"{blendshape_node}.{source}" | |
| if not cmds.getAttr(source_attr, lock=True) and not cmds.listConnections(source_attr, source=True): | |
| cmds.setAttr(source_attr, 1) | |
| else: | |
| print(f"Skipped setting {source_attr}: Attribute is locked or connected.") | |
| inputs = cmds.blendShape(blendshape_node, query=True, target=True) | |
| print(f"Blendshape node {blendshape_node} inputs: {inputs}") | |
| print(f"Created blendshape node: {blendshape_node} on target: {target}") | |
| cmds.select(clear=True) | |
| cmds.confirmDialog(title="Success", message="Shapes connected successfully!", button=["OK"]) | |
| print("All shapes connected successfully.") | |
| except Exception as e: | |
| cmds.warning(f"Error connecting shapes: {str(e)}") | |
| cmds.button(label="Connect All Shapes", command=lambda *args: connect_shapes()) | |
| cmds.showWindow(window) | |
| create_blendshape_tool_ui() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment