How to create geometry in standalone hython script?
1900
4
3
Aug. 18, 2020 3:04 p.m.
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
jsmack
Member
8038 posts
Joined: Sept. 2011
Offline
Aug. 18, 2020 7:08 p.m.
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.
drew
Member
120 posts
Joined: July 2005
Offline
Aug. 18, 2020 7:12 p.m.
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 ])
monomon
Member
40 posts
Joined: May 2019
Offline
July 2, 2024 7:46 a.m.
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
Aug. 24, 2024 8:18 a.m.
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 nodeYes, this works thanks a lot! this is a very nice way to create geometry through python!