How to create geometry in standalone hython script?

   1900   4   3
User Avatar
Member
301 posts
Joined: July 2005
Offline
import hou
import sys

def main(output_hip):
    geo_node = hou.node('/obj').createNode('geo')
    nurb_surface = hou.Geometry().createNURBSSurface(10,10)
    hou.hipFile.save(file_name=output_hip)

if __name__ == "__main__":
    if len(sys.argv) == 2:
        main(output_hip=sys.argv[1])

How do I associate the newly create nurb_surface with the ‘geo’ node ? My created hip file only has ‘geo1’ but not the NURBS surface geometry.

Cheers
Nicholas Yue
User Avatar
Member
8038 posts
Joined: Sept. 2011
Offline
A hip file typically doesn't contain any geometry, but the instructions for creating it. Put the code creating hou.geometry in a python sop's code snippet.
User Avatar
Member
120 posts
Joined: July 2005
Offline
Something like this maybe.

import hou
import sys

def main(output_hip):
    geo_node = hou.node('/obj').createNode('geo')
    pysop = geo_node.createNode('python')
    code = \
'''
node = hou.pwd()
geo = node.geometry()
geo.createNURBSSurface(10,10)
'''
    pysop.parm('python').set(code)
    hou.hipFile.save(file_name=output_hip)

if __name__ == "__main__":
    if len(sys.argv) == 2:
        main(output_hip=sys.argv[1])
User Avatar
Member
40 posts
Joined: May 2019
Offline
In case anyone else comes across this thread, I found a way to create static geometry outside of sop, and pass it on via a stash node
# stash node
node = hou.node('/obj/clips/stash1')

# detached geometry
new_geo = hou.Geometry()
new_geo.addAttrib(hou.attribType.Point, "path", "")

for motion in motions:
  p = new_geo.createPoint()
  p.setAttribValue("path", motion["filepath"])
  
print(node.parm("stash").set(new_geo))

The parameter "stash" of the stash node can contain straight geometry, which then joins the SOP context.
Edited by monomon - July 2, 2024 07:57:31
User Avatar
Member
16 posts
Joined: April 2021
Offline
monomon
In case anyone else comes across this thread, I found a way to create static geometry outside of sop, and pass it on via a stash node

Yes, this works thanks a lot! this is a very nice way to create geometry through python!
  • Quick Links