Jump to content
Sign in to follow this  
csp

Python error on working code

Recommended Posts

Hi, the following code which is included in an ordered menu script, code does what supposed to do.

menu = []

list = len(hou.pwd().node("OUT").geometry().prims())

for i in range(0,list):
    menu.append(i)
    menu.append(i)

return menu

But when even I copy paste the node or open the saved hip will give me an error:

AttributeError: 'NoneType' object has no attribute 'geometry'

I have not compiled an OTL, this parameter is on a subnet node and getting info from the SOP nodes inside.

Why is there an error and at the same time the code is working?

 

Share this post


Link to post
Share on other sites

I suspect that it's just an order of operations type thing.  Houdini may be creating the main node, then attempting to display the menu parameter before it's actually created any of the child nodes.  In this case the call to get the child node would fail (give you None).  Just a guess anyway.  Easiest thing to do would be to just do a check against the child node existing, and of not, return the empty menu.  Chances are when the node goes to actually cook properly, things should be all good.

Share this post


Link to post
Share on other sites

I suspect that it's just an order of operations type thing.  Houdini may be creating the main node, then attempting to display the menu parameter before it's actually created any of the child nodes.  In this case the call to get the child node would fail (give you None).  Just a guess anyway.  Easiest thing to do would be to just do a check against the child node existing, and of not, return the empty menu.  Chances are when the node goes to actually cook properly, things should be all good.

 

Thanks graham, that worked!

 

for future reference:

menu = []

geo = hou.pwd().node("OUT")

if geo:
    list = len(geo.geometry().prims())
    for i in range(0,list):
        menu.append(i)
        menu.append(i)

return menu

Share this post


Link to post
Share on other sites

Hey Graham,

 

somehting weird is happing with this code. I have an OTL out of this tool now.

I get an error when I copy paste the OTL and also when I submit the hip to the farm.

AttributeError: 'NoneType' object has no attribute 'prims'

But I will NOT get any error when a new instance of the OTL is down.

I will NOT get any error when I copy paste and there is.

I will NOT get any error when I copy paste when the OTL is in "Allow Editing Contents" mode, with is input or not.

 

So I get the error only when is compiled, there is an input and I copy paste it.

 

 

I suspect that it's just an order of operations type thing.  Houdini may be creating the main node, then attempting to display the menu parameter before it's actually created any of the child nodes.  In this case the call to get the child node would fail (give you None).  Just a guess anyway.  Easiest thing to do would be to just do a check against the child node existing, and of not, return the empty menu.  Chances are when the node goes to actually cook properly, things should be all good.

Share this post


Link to post
Share on other sites

fixed by replaced two lines of the code from:

menu = []

geo = hou.pwd().node("OUT")

if geo:
    list = len(geo.geometry().prims())
    for i in range(0,list):
        menu.append(i)
        menu.append(i)

return menu

to:

menu = []

geo = hou.pwd().node("OUT").geometry()

if geo is not None:
    list = len(geo.prims())
    for i in range(0,list):
        menu.append(i)
        menu.append(i)

return menu

Share this post


Link to post
Share on other sites

If you change this:

list = len(geo.prims())

to this:

list = len(geo.iterPrims())

You will get x100 speed boost on heavy models, since getting the length of generator is ultra fast.

Share this post


Link to post
Share on other sites

If you change this:

list = len(geo.prims())

to this:

list = len(geo.iterPrims())

You will get x100 speed boost on heavy models, since getting the length of generator is ultra fast.

 

thanks Alex for the tip.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×