How to create geometry in standalone hython script?
1969
4
3
2020年8月18日 15:04
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
8042 posts
Joined: 9月 2011
Offline
2020年8月18日 19:08
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: 7月 2005
Offline
2020年8月18日 19:12
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: 5月 2019
Offline
2024年7月2日 7:46
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 - 2024年7月2日 07:57:31
2024年8月24日 8:18
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!