Jump to content
davidyannick

Spliting Kitbash pack

Recommended Posts

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

Share this post


Link to post
Share on other sites
Posted (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 by Alain2131

Share this post


Link to post
Share on other sites
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 :)

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

×