So i did it this way and it worked (for those who do not know how to run script in maya press ctrl + enter) :
import maya.cmds as cmds
def edges_to_curves():
# Get the selected edges
selection = cmds.ls(selection=True, fl=True)
if not selection:
cmds.warning("Please select at least one edge.")
return
print("Selected components:", selection) # Debugging
# Ensure only edges are selected
edges = cmds.filterExpand(selection, selectionMask=32) # 32 is the mask for edges
if not edges:
cmds.warning("No valid polygon edges selected.")
return
print("Filtered edges:", edges) # Debugging
# Create a list to store the curves
curves = []
# Loop through the selected edges
for edge in edges:
print(f"Processing edge: {edge}") # Debugging
# Get the vertices of the edge
vertices = cmds.polyListComponentConversion(edge, toVertex=True)
vertices = cmds.ls(vertices, fl=True)
print(f"Vertices for edge {edge}:", vertices) # Debugging
if len(vertices) != 2:
cmds.warning(f"Skipping edge {edge}: Expected 2 vertices, found {len(vertices)}")
continue # Skip problematic edges
# Get the positions of the vertices
points = [cmds.xform(vtx, q=True, t=True, ws=True) for vtx in vertices]
print(f"Points for edge {edge}:", points) # Debugging
# Create a linear curve from the points
curve = cmds.curve(d=1, p=points) # d=1 for straight-line curves
curves.append(curve)
if curves:
cmds.select(curves)
cmds.confirmDialog(title="Success", message=f"Created {len(curves)} curves from edges.")
else:
cmds.warning("No curves were created.")
# Run the function
edges_to_curves()