Jump to content

Getting list of all point positions from a SOP


Recommended Posts

Hi all,

   I need to make a script that can get all of the point positions from a sop. I.e. I have a curve sop, I put a transform after that curve sop, and need to make a brand new curve sop with the point positions from the transform sop. Then I can delete the original curve and transform and be left with the new curve only. But I don't see how I can get those points' positions into a string to put in the new curve sop. The plan is to use hscript and probably the tcl plug-in. However I do it, I'd probably generate an "opadd" for the new curve and make an "opparm" line for the curve coordinates, I just don't know how to get the coordinates. It's probably easy. Any advice?

Link to comment
Share on other sites

Here is some python code that looks at the geometry of it's input and creates a light at each point. Maybe this can help you construct a new curve to match your requirements? It at least shows how to get the points from a source input. In this example script the source geometry comes from an ObjectMerge so input could be any valid sop.

node = hou.pwd()
geo = node.geometry()

def fetchIfObject (passedName):
    # Return a named item if it exists.
    try:
        result = hou.node(passedName)
        if result == 0:
            result = None
    except:
        result = None
    return result
    
parent_name = "light_container"   # Name of master object that will hold all the generated lights.
subnet_name = "/obj/%s" % parent_name
        
parent = fetchIfObject(subnet_name)
if parent == None:
    # Create a SubNet for all lights to reside under.
    parent = hou.node('/obj').createNode('subnet', parent_name)
    
for (i,point) in enumerate(geo.points()):
    light_name = "ilight_%s" % i
    ob = fetchIfObject('/obj/%s/%s' % (parent_name, light_name))
    if ob == None:
        # Light does not exist, time to create it.
        ob = parent.createNode('hlight', light_name, run_init_scripts=False)
        ob.parm("light_type").set(0)        # Set the type of light.
        ob.parm("coneenable").set(1)        # Turn on the spotlight cone to convert this point light to a spotlight.
        ob.parm("light_colorr").set(1)      # Set light color.
        ob.parm("light_colorg").set(0.75)
        ob.parm("light_colorb").set(0.8)
        ob.parm("light_intensity").set(1.0) # Set light intensity.
        
    # Set the position for this light.
    p = point.position()
    ob.parm('tx').set(p[0])         # Position the item.
    ob.parm('ty').set(p[1])         # Position the item.
    ob.parm('tz').set(p[2])         # Position the item.
    
    # Rotate the spotlight so it is facing down.
    ob.parm("rx").set(-90)

 

ap_scatter_lights.hipnc

Edited by Atom
Link to comment
Share on other sites

Hi, here's a slightly different alternative. Also using python.

Use this as a shelf tool. Select a single SOP node, then run this tool. It will copy the point positions to the clipboard.

node = hou.selectedNodes()
if len(node) == 1:
    sop = node[0]
    if type(sop) == hou.SopNode:
        geo = sop.geometry()
        pnts = geo.points()
        plist = ""
        for p in pnts:
            pos = p.attribValue("P")
            plist += str(pos[0]) + "," + str(pos[1]) + "," + str(pos[2]) + " "
        print plist
        
        # copy to clipboard by asnowcappedromance
        listcount = len(plist)
        if listcount > 0:
            import PySide.QtGui as qtg
            app = qtg.QApplication.instance()
            clipboard = app.clipboard()
            string = hou.selectedNodes()[0].path()
            clipboard.setText(plist)

* Got the clipboard functionality from asnowcappedromance's thread :)

  • Like 1
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...