multiple polygon edges to curves

multiple polygon edges to curves

V4nDl0
Enthusiast Enthusiast
3,773 Views
11 Replies
Message 1 of 12

multiple polygon edges to curves

V4nDl0
Enthusiast
Enthusiast

When using "modify>convert>polygon edges to curves", Maya can only do one single edge loop at a time. Is there any way to select multiple edge loops and convert them all at once, rather than selecting them all one by one? This would be really useful for me generating hair curves for Xgen. I want to sculpt the hair as geometry and then select the relevant polygon edge loops and make them all into nurbs curves.

 

Thanks

3,774 Views
11 Replies
Replies (11)
Message 2 of 12

hamsterHamster
Advisor
Advisor

Maybe some scripting to avoid manual selecting.

Alternatively, more dirty way, you can convert all the selected edges to the same number of disconnected curves. Modeling > Curves > DuplicateSurfaceCurves.


,,,_°(O__O)°_,,,
Maya2019.1 @ Windows10 & GeForce GTX1080Ti

If the post was helpful, click the
 ACCEPT SOLUTION  button, so others might find it much more easily.

Message 3 of 12

V4nDl0
Enthusiast
Enthusiast

Thanks for responding. Unfortunately I don't know how to do much with scripting. If anyone does know how to do this script, I would be very grateful for the help.

0 Likes
Message 4 of 12

anatoliiCD3WB
Observer
Observer

nice question.

Autdesk?
Where is this tool in maya?
Make it finally!

0 Likes
Message 5 of 12

BoDiddley
Participant
Participant

Hey this script will allow you to select edges and convert them into curves:

  • The script retrieves the selected edges and converts them into their corresponding vertex positions.
  • It then creates a curve for each edge based on those vertices.
  • The newly created curves are selected at the end of the operation.



 

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 edges.")
return

# Create a list to store the curves
curves = []

# Loop through the selected edges
for edge in selection:
# Get the vertices of the edge
vertices = cmds.polyListComponentConversion(edge, toVertex=True)
vertices = cmds.ls(vertices, fl=True)

# Get the positions of the vertices
points = [cmds.xform(vtx, q=True, t=True, ws=True) for vtx in vertices]

# Create a curve from the points
curve = cmds.curve(d=3, p=points)
curves.append(curve)

# Select the created curves
cmds.select(curves)

# Run the function
edges_to_curves()

0 Likes
Message 6 of 12

mabioca
Contributor
Contributor

Just select edges and then run the below MEL script.

 

 

// Convert selected edges to a single curve in Maya
string $selectedEdges[] = `ls -sl -fl`;
string $object[] = `listRelatives -p $selectedEdges[0]`;

string $curveNodes[];
for ($edge in $selectedEdges) {
    string $edgeCurve[] = `polyToCurve -form 2 -degree 1 -conformToSmoothMeshPreview false $edge`;
    $curveNodes[size($curveNodes)] = $edgeCurve[0];
}

string $finalCurve[] = `attachCurve -ch 0 -rpo 0 -kmk 0 -m 0 $curveNodes`;

delete $curveNodes;
select $finalCurve[0];

 

 

Screenshot 2024-11-04 012020.png

0 Likes
Message 7 of 12

nickylasb
Community Visitor
Community Visitor

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()

0 Likes
Message 8 of 12

mabioca
Contributor
Contributor

Thanks! However, the result of running this script is the creation of separate curves from the selected edges, which can be achieved using Curves > Offset > Offset Curve

Message 9 of 12

V4nDl0
Enthusiast
Enthusiast

Thanks everyone for trying to help, but so far I haven't had success with any of the scripts posted, they either give syntax errors or create the wrong kind of curves.
In case my original question was unclear -
I want to select MULTIPLE EDGE LOOPS and convert them into separate individual curves, 1 for each edge loop selected. Just like using "modify > convert polygon edges to curve" but doing many edge loops in a single action.
LIKE THIS:

HAIR.JPG

Using Chat GPT, I was sort of able to come up with this attempt at a script:

 

string $edge;
string $curves[];
string $edges[] = `ls -sl -flatten`;
for ($edge in $edges) {
select -r $edge;
polySelectSp -loop; // or performSelContiguousEdges 0;

// change -degree to 1 for a linear (instead of smooth) curve
string $result[] = `polyToCurve -form 2 -degree 3 -conformToSmoothMeshPreview 1`;
$curves[size($curves)] = $result[0];
}
select -r $curves;

 

 

 

// Warning: string $edge;
// Warning: Line 1.13 : Redeclaration of variable "$edge" shadows previous declaration at line 6. Previous value will be retained.

 

- but this script creates way too many curves. For example, if I select just four edge loops and run the script, I get 136 curves - the curves are good and usable, but I have to delete 132 of them. So for a full haircut I have to delete thousands of unwanted curves.
If anyone who knows scripting can help fix this script, I'm still looking. Thanks! 

0 Likes
Message 10 of 12

BoDiddley
Participant
Participant

Hey I think I've got a bit of a work around for you to try to achieve this.

Under the Modify menu convert your mesh to SubD then convert the SubD mesh to a Nurbs mesh now select your Isoparms highlighted in yellow in the image bellow. Now use Duplicate Surface Curves under the Curves menu (might find it useful to go into the options for this tool first and tick Group with Original) now you should have your curves. 

If you run SubD to Nurbs on a more complicated mesh your final Nurbs object will probably produce multiple Nurbs shapes. Here's a way to combine all the shapes to make it easier to select your Isoparms (This will only make its easier for you to select your Isoparms but the edges will still cut at the shape end so you'll still need to use curve attach to connect them)

Firstly Freeze transforms on all your Nurbs shapes
now create a Null group ctrl+G
Under Display in your outliner check on Shapes
now copy the shape name, for example "subdToNurbsShape1_Shape1" 
now in the input line menu at the top of your toolbar select "select by name" then paste subdToNurbsShape1_Shape1 but remove the number at the end and replace with a * so it should look like this "subdToNurbsShape1_Shape*" this will now select all shapes.
Now ctrl select your Null grp then in the MEL script write "parent -r-s" this will now combine all your shapes 
You should now be able to select multiple Isoparms across all your Nurbs shapes


Its a bit of a janky work around but let me know if this works for you.
Your script does a good job, maybe someone can tweak it so that it doesn't generate so many and only the selected ones

Curve_workflow.PNG

0 Likes
Message 11 of 12

BoDiddley
Participant
Participant

Hey @V4nDl0 try this Python script. It does the same as your MEL script but it shouldn't create all the duplicates its working by edge looping the selection currently, Ideally it would be better to have it create the curves based on a selection, but currently looking into it.

import maya.cmds as cmds

def create_curves_from_non_continuous_selection():
    # Get the selected edges
    edges = cmds.ls(selection=True, flatten=True)

    if edges:
        # List to store the created curve names
        curves = []
        
        # Set to keep track of processed edges to avoid duplication
        processed_edges = set()

        # Process each edge
        for edge in edges:
            if edge not in processed_edges:
                # Select the current edge and try to select the whole connected loop
                cmds.select(edge)
                cmds.polySelectSp(loop=True)
                
                # Get the selected edges after selecting the loop
                selected_edges = cmds.ls(selection=True, flatten=True)
                
                # Create the curve from the selected edge loop
                result = cmds.polyToCurve(form=2, degree=3, conformToSmoothMeshPreview=True)
                
                # Store the created curve
                curves.append(result[0])
                
                # Mark the selected edges as processed
                for e in selected_edges:
                    processed_edges.add(e)

        # Select all the created curves
        if curves:
            cmds.select(curves)
        else:
            cmds.warning("No curves created.")
    else:
        cmds.warning("No edges selected.")

# Run the function
create_curves_from_non_continuous_selection()
Message 12 of 12

robszczerba
Participant
Participant

Many thanks! This Python script from Chat GPT, making a slight adjustment, will produce straight curves:

 

import maya.cmds as cmds

def create_straight_curves_from_edges():
# Get the selected edges
edges = cmds.ls(selection=True, flatten=True)

if edges:
# List to store the created curve names
curves = []

# Set to keep track of processed edges to avoid duplication
processed_edges = set()

# Process each edge
for edge in edges:
if edge not in processed_edges:
# Select the current edge and try to select the whole connected loop
cmds.select(edge)
cmds.polySelectSp(loop=True)

# Get the selected edges after selecting the loop
selected_edges = cmds.ls(selection=True, flatten=True)

# Create a curve from the selected edge loop with straight segments (degree 1)
result = cmds.polyToCurve(form=2, degree=1, conformToSmoothMeshPreview=False)

# Store the created curve
curves.append(result[0])

# Mark the selected edges as processed
for e in selected_edges:
processed_edges.add(e)

# Select all the created curves
if curves:
cmds.select(curves)
else:
cmds.warning("No curves created.")
else:
cmds.warning("No edges selected.")

# Run the function
create_straight_curves_from_edges()

0 Likes