Troubles with Python and file SOP

   1751   2   1
User Avatar
Member
479 posts
Joined: 8月 2014
Offline
Hello.

I've been racking my brain for about an hour now trying to figure out why this script doesn't work, when theoretically it should.

For the sake of simplicity, let's say I have an OBJ node containing a sphere SOP with a file node piped to it downstream. The sphere holds the display flag.
I want to export the sphere with a file SOP, but I want the sphere to retain its display flag after the operation.
I've noticed that file node will export geometry when minimum of two conditions are met:
1. Its filemode is set to write (3).
2. Its display flag is set to true (it will begin exporting right after it receives the display flag).
It can also write the file when both requirements are already satisfied AND the reload button is pressed (pressButton()), OR when both requirements are met AND upstream geometry is changed.

The thing is, that immediately after the file gets written to disk, I need to return the display flag to sphere node. I also want to set the filemode back to 0 (No Operation). And here's where troubles begin, because if I add those two instructions, the file is never exported. It looks almost like fileNode.setDisplayFlag(True) was completely ignored, filemode immediately set back to “No Operation” and display flag returned to sphere SOP.

The script:
import hou

def export(objNode):
geoNode = hou.node(objNode.path()+'/sphere1')
fileNode = hou.node(objNode.path()+'/file1')

fileNode.parm('filemode').set(2)
fileNode.setDisplayFlag(True)
fileNode.parm('filemode').set(3) # If I comment out those two last lines,
geoNode.setDisplayFlag(True) # the geometry exports without problems.

export(hou.node('/obj/sphere'))
What is wrong with it? :?
User Avatar
Member
8630 posts
Joined: 7月 2007
Offline
your file node was probably not cooked since Viewport may have never realised it was displayed
moving display flag to cook a node is not a good idea, especially if you are calling scripts in nongraphical interface or the viewport is not active

- you can simply do fileNode.cook() to force it to cook

- as well for getting the child node you don't have to use path, simply use
objNode.node('sphere1')

def export(objNode):
fileNode = objNode.node('file1')

fileNode.parm('filemode').set(2)
fileNode.cook()
fileNode.parm('filemode').set(3)


- alternatively you can use saveToFile() function from hou.Geometry and avoid file node altogether if you want to just export display geo
def exportDisplayedSop(objNode):
geoNode = objNode.displayNode()
geoNode.geometry().saveToFile(“/tmp/geo.bgeo”)
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
479 posts
Joined: 8月 2014
Offline
Thank you very much Tamte! I didn't realise that I had to cook it first. It would probably take me a lot of time to figure this out.

Moving display flag felt very awkward and tedious, but I just assumed that's what had to be done. :roll:
So much to learn.
  • Quick Links