davidyannick Posted June 12, 2021 Share Posted June 12, 2021 A few months ago I wrote a little script to change the name of pieces from kitbash3D node = hou.pwd() geo = node.geometry() # Add code to modify contents of geo. # Use drop down menu to select examples. for prim in geo.prims: path=prim.attribValues("name") newpath=path[:20] prim.setAttribValue("path",newpath) It worked, but now with H 18.5.596 and 606 Python 2 and 3 I always have this error : Python error: Traceback (most recent call last): File "<stdin>", line 7, in <module> TypeError: 'method' object is not iterable Any idea? Thanks for your help split-kitbash.hiplc Quote Link to comment Share on other sites More sharing options...
Alain2131 Posted June 12, 2021 Share Posted June 12, 2021 (edited) Salut Davidt, Let's break down the error. "'method' object is not iterable" at line 7. What is line 7, and what do you do there ? for prim in geo.prims: You iterate on geo.prims But it says that geo.prims is not iterable. So geo.prims is the culprit. If you go see in the Geometry Help page and search for prims, you'll see that it has parenthesis after it. Simply put, you need to write geo.prims() and that should fix your issue. That is because geo.prims is the equivalent to hou.Geometry.prims, which is the method (a quick Google search will explain what is a method to you) that is used to return the data you want. But it's not the same as calling it. You need the parenthesis to do that. EDIT : A good way to test and poke around a bit is to print out the result of the stuff you try to do. node = hou.pwd() geo = node.geometry() print(geo.prims) Returns : <bound method Geometry.prims of <hou.Geometry frozen at 00000000E4000800>> But, with the parenthesis.. node = hou.pwd() geo = node.geometry() print(geo.prims()) Returns : (<hou.Polygon prim #0 of geometry frozen at 00000000E4003200>, <hou.Polygon prim #1 of geometry frozen at 00000000E4003200>, <hou.Polygon prim #2 of geometry frozen at 00000000E4003200>, <hou.Polygon prim #3 of geometry frozen at 00000000E4003200>, <hou.Polygon prim #4 of geometry frozen at 00000000E4003200>, <hou.Polygon prim #5 of geometry frozen at 00000000E4003200>) This is for a cube. Be aware that printing to the console is very slow, and can take a very long time depending on the amount of stuff to print. The Python Shell (Windows - Python Shell) is much faster to print to. Edited June 12, 2021 by Alain2131 Quote Link to comment Share on other sites More sharing options...
davidyannick Posted June 13, 2021 Author Share Posted June 13, 2021 13 hours ago, Alain2131 said: Salut Davidt, Let's break down the error. "'method' object is not iterable" at line 7. What is line 7, and what do you do there ? for prim in geo.prims: You iterate on geo.prims But it says that geo.prims is not iterable. So geo.prims is the culprit. If you go see in the Geometry Help page and search for prims, you'll see that it has parenthesis after it. Simply put, you need to write geo.prims() and that should fix your issue. That is because geo.prims is the equivalent to hou.Geometry.prims, which is the method (a quick Google search will explain what is a method to you) that is used to return the data you want. But it's not the same as calling it. You need the parenthesis to do that. EDIT : A good way to test and poke around a bit is to print out the result of the stuff you try to do. node = hou.pwd() geo = node.geometry() print(geo.prims) Returns : <bound method Geometry.prims of <hou.Geometry frozen at 00000000E4000800>> But, with the parenthesis.. node = hou.pwd() geo = node.geometry() print(geo.prims()) Returns : (<hou.Polygon prim #0 of geometry frozen at 00000000E4003200>, <hou.Polygon prim #1 of geometry frozen at 00000000E4003200>, <hou.Polygon prim #2 of geometry frozen at 00000000E4003200>, <hou.Polygon prim #3 of geometry frozen at 00000000E4003200>, <hou.Polygon prim #4 of geometry frozen at 00000000E4003200>, <hou.Polygon prim #5 of geometry frozen at 00000000E4003200>) This is for a cube. Be aware that printing to the console is very slow, and can take a very long time depending on the amount of stuff to print. The Python Shell (Windows - Python Shell) is much faster to print to. ok thanks for your help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.