Jump to content

Non procedurally flatten a curve


AntoineSfx

Recommended Posts

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.

Link to comment
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
Link to comment
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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...