Jump to content
AntoineSfx

Non procedurally flatten a curve

Recommended Posts

I have created a curve, but I didn't realize some points were created outside of the XZ plane.

How can I fix the curve so that I don't have for example, a transform node with scaleY=0 after the curve. I just want to non procedurally alter the points.

Share this post


Link to post
Share on other sites

Hi, try out this code if it works for you.

# flattens a curve without using a transform SOP
sel = hou.selectedNodes()
for s in sel:
    if s.type().name() == 'curve':
        p = s.parm('coords')
        old = p.eval().split()
        new = ''
        for i in old:
            vec = i.split(',')
            new += vec[0] + ',0,' + vec[2] + ' '
        p.set(new)

Just select the your Curve SOPs and run the script on a Shelf Tool.

Share this post


Link to post
Share on other sites

As @konstantin magnus said, you need to manually process coordinate string, where points delimited by spaces and coordinates delimited by commas. It's usually easy to do by hand, but for the big curves, as one-time solution, open "Python Source Editor" from "Windows" menu on menu-bar and paste:

import re
coords = '-0.74726,0.925304,-0.00824785 -0.673029,0.290926,0.435489 0.377754,0.610135,-0.875927 0.689525,-0.412144,-0.35301 '
print(re.sub(r'(.*?),(.*?),(.*?)', r'\1,0.0,\3', coords))

Press Apply. Resulting string should be printed into console. Modify this for your case.

1. If Curve node outputs error, make sure you didn't copy empty newline from the end of console.

2. Clear and apply editor's contents before closing, otherwise it will print every time you open hip.

3. re.sub's second argument for zeroing x, y and z axes:

r'0.0,\2,\3'
r'\1,0.0,\3'
r'\1,\2,0.0'

 

Edited by f1480187
  • Like 1

Share this post


Link to post
Share on other sites

That is cool f1! I hope you don't mind me creating a variant of the script with your method :lol:

# flatten variant using regular expressions
import re
sel = hou.selectedNodes()
for s in sel:
    if s.type().name() == 'curve':
        p = s.parm('coords')
        coords = p.eval()
        p.set(re.sub(r'(.*?),(.*?),(.*?)', r'\1,0.0,\3', coords))

 

Edited by galagast
  • Like 2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×