Jump to content

Python error on working code


csp

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?

 

Link to comment
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.

Link to comment
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
Link to comment
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.

Link to comment
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
Link to comment
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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...