chrsmith Posted November 8, 2016 Share Posted November 8, 2016 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? Quote Link to comment Share on other sites More sharing options...
Atom Posted November 9, 2016 Share Posted November 9, 2016 (edited) 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 November 9, 2016 by Atom Quote Link to comment Share on other sites More sharing options...
galagast Posted November 9, 2016 Share Posted November 9, 2016 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 :) 1 Quote Link to comment Share on other sites More sharing options...
chrsmith Posted November 9, 2016 Author Share Posted November 9, 2016 Neat, thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.