Python Error while dividing: TypeError: unsupported operand type(s) for /: 'int' and 'NoneType'

   6319   3   2
User Avatar
Member
2 posts
Joined: Jan. 2015
Offline
So I'm working on a tool that requires me to do some divisions of variables. I ran a test version in the Python Shell window and it worked just as I expected but when I run it in my Python node I get an error when I apply it. Here is the code and error

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

hairs = list(geo.prims())
hair_count = len(hairs) - 1

node_percent = hou.node("/obj/geo1/Percent")

percent = node_percent.parm("Percent")

threshold = int((hair_count / percent) / hair_count)

Error:       Python error: Traceback (most recent call last):
File "<stdin>", line 11, in <module>
TypeError: unsupported operand type(s) for /: 'int' and 'NoneType'

Does anyone have an idea why this would happen?

Thank you in advance
User Avatar
Member
1743 posts
Joined: March 2012
Offline
Justin Rhoades
Does anyone have an idea why this would happen?
If the node with path /obj/geo1/Percentdoesn't have a parameter whose token is Percent, node_percent.parm("Percent")would probably return NoneType. Make sure you're not mixing up the parameter's token and label. You can hover over a parameter's label to see it's token in the help tooltip. Hopefully that's what you're looking for.
Writing code for fun and profit since... 2005? Wow, I'm getting old.
https://www.youtube.com/channel/UC_HFmdvpe9U2G3OMNViKMEQ [www.youtube.com]
User Avatar
Member
7759 posts
Joined: Sept. 2011
Offline
You didn't evaluate the parm either. If you evaluated it first, you would have caught the exception earlier as “NoneType has no attribute ‘eval’”
User Avatar
Member
2 posts
Joined: Jan. 2015
Offline
Thank you both. You were absolutely correct on these issues. Thank you for the quick reply sorry I was slow to respond
  • Quick Links