XaiJu
Ricardo Rioja
Ricardo Rioja

gumroad


Hard Edge Selector v2

Hard Edge Selector v2 script

Thanks to the suggestions I’ve received, here are the changes I’ve implemented so far:

  1. Better threshold.
  2. Dynamic edge tracking: The script now stores and compares vertex positions in world space, making it resilient to topology changes.
  3. Improved edge validation: If you select multiple objects, the script will only process valid meshes and skip non-polygonal elements.
  4. Optimized selection: The script can recall previous edge selections and keep them intact, even after modifying geometry.
  5. Cylinder compatibility.


How to Use the Hard Edge Selector Script in Maya

1. Running the Script from the Script Editor

  1. Open Maya and go to Windows > General Editors > Script Editor.
  2. Paste the full script into the Python tab.
  3. Select all the code and press Ctrl + Enter (Windows) or Cmd + Enter (Mac) to execute it.
  4. To call the function anytime, type the following into the Python tab:select_outer_edges()

2. Saving the Script in Maya’s Scripts Folder

  1. Copy the full script and save it as a .py file (e.g., hard_edge_selector.py).
  2. Place the file in your Maya scripts folder.
    • On Windows: Documents\maya\<version>\scripts
    • On Mac: ~/Library/Preferences/Autodesk/maya/<version>/scripts
    • On Linux: ~/maya/<version>/scripts
  3. In Maya, load the script by typing the following into the Script Editor (or any Python-enabled window):import hard_edge_selector hard_edge_selector.select_outer_edges()
  4. To make it even easier, you can create a shelf button or hotkey using the import and function call lines above.

3. Assigning the Script to a Shelf Button

  1. Right-click on any shelf (or create a new one) and select Add Script.
  2. Paste the following code into the Python section:import hard_edge_selector hard_edge_selector.select_outer_edges()
  3. Assign a name and optional icon, then click Save.

4. Assigning the Script to a Hotkey

  1. Go to Windows > Settings/Preferences > Hotkey Editor.
  2. Click Custom Scripts and create a new command.
  3. Paste the following code into the Python section:import hard_edge_selector hard_edge_selector.select_outer_edges()
  4. Assign a hotkey (e.g., Alt + E) and click Save and Close.

With these options, you can integrate the script seamlessly into your Maya workflow and run it however you prefer. If you have any questions, feel free to reach out. Happy modeling!

hardEdgeSelectorV2.py


import maya.api.OpenMaya as om, math def calculate_angle(v1, v2): return math.degrees(math.acos(min(max(sum(a * b for a, b in zip(v1, v2)) / (math.sqrt(sum(a ** 2 for a in v1)) * math.sqrt(sum(b ** 2 for b in v2))), -1.0), 1.0))) def store_edge_positions(obj, edges): positions = [[list(obj.getPoint(v1, om.MSpace.kWorld)), list(obj.getPoint(v2, om.MSpace.kWorld))] for v1, v2 in edges] if not cmds.attributeQuery("edgePositions", node=obj.fullPathName(), exists=True): cmds.addAttr(obj.fullPathName(), longName="edgePositions", dataType="string") cmds.setAttr(f"{obj.fullPathName()}.edgePositions", str(positions), type="string") def retrieve_edge_positions(obj): if not cmds.attributeQuery("edgePositions", node=obj.fullPathName(), exists=True): return [] return eval(cmds.getAttr(f"{obj.fullPathName()}.edgePositions") or "[]") def match_edges_by_position(mesh, stored_positions): matched_edges = [] for edge_index in range(mesh.numEdges): v1, v2 = mesh.getEdgeVertices(edge_index) pos1, pos2 = list(mesh.getPoint(v1, om.MSpace.kWorld)), list(mesh.getPoint(v2, om.MSpace.kWorld)) if [pos1, pos2] in stored_positions or [pos2, pos1] in stored_positions: matched_edges.append(edge_index) return matched_edges def select_outer_edges(threshold=35): selection = om.MGlobal.getActiveSelectionList() if selection.length() == 0: return om.MGlobal.displayWarning("No objects selected.") for i in range(selection.length()): try: obj = selection.getDagPath(i) if not obj.hasFn(om.MFn.kMesh): om.MGlobal.displayWarning(f"{obj.fullPathName()} is not a polygonal mesh. Skipping."); continue mesh = om.MFnMesh(obj) stored_positions = retrieve_edge_positions(obj) if stored_positions: matched_edges = match_edges_by_position(mesh, stored_positions) if matched_edges: [om.MGlobal.selectByName(f"{obj.fullPathName()}.e[{edge}]", om.MGlobal.kAddToList) for edge in matched_edges] continue edge_itr, selected_edges = om.MItMeshEdge(obj), [] while not edge_itr.isDone(): faces = edge_itr.getConnectedFaces() if len(faces) == 2 and calculate_angle(mesh.getPolygonNormal(faces[0], om.MSpace.kWorld), mesh.getPolygonNormal(faces[1], om.MSpace.kWorld)) >= threshold: selected_edges.append((edge_itr.vertexId(0), edge_itr.vertexId(1))) om.MGlobal.selectByName(f"{obj.fullPathName()}.e[{edge_itr.index()}]", om.MGlobal.kAddToList) edge_itr.next() if selected_edges: store_edge_positions(mesh, selected_edges) except Exception as e: om.MGlobal.displayError(f"Error processing {obj.fullPathName()}: {e}") select_outer_edges()

Hard Edge Selector v2

More Creators