[PYTHON] How many nodes are there?

Houdini Advent Calendar 2016 Day 19 article.

The content is as the title ... At this point, those who say "Ah, high" may be asked to close it. If you know any other better way, I would be grateful if you could tell me secretly.

Guessing Node Type

Let's take a look inside the hou module. Of the list returned by dir, if "NodeType" is included, it seems like that, so I will investigate it like that.

for i in dir(hou):
    if 'NodeType' in i:
        print( i )

Then

NodeType

It has returned quite a bit. It seems that the first half and _swigregister are different. It's interesting that there are "Node Type" and "Node Type Category". I feel that the latter is more like that.

inspect.getmembers

Now let's take a look using the inspect module getmembers.

import inspect
for i in inspect.getmembers(hou):
    if 'NodeType' in i[0]:
        print i
getmembers

The NodeTypeCategory system seems to be ** built-in function ** across the board. These functions return a "NodeTypeCategory" type.

type( hou.sopNodeTypeCategory() )
<class 'hou.NodeTypeCategory'>

NodeTypeCategory

It's a NodeTypeCategory type, and I typed n to see if I could see it by name, and then "nodeTypes" was also suggested. name_nodeTypes

sopCategory.name()
'Sop'

sopCategory.nodeTypes()

The name is as expected, but The nodeTypes I found by the way looks like this! nodeTypes

I was a little scared, but now I can check the nodes in each node category.

Count the contents of nodeTypes

import inspect
for i in inspect.getmembers(hou):
    if 'NodeType' in i[0]:
        if inspect.isbuiltin(i[1]):
            try:
                nodetypecategory= i[1]()
            except:
                continue
            nts = nodetypecategory.nodeTypes()
            print( nodetypecategory.name(),len( nts ) )

The try-except in the middle is provided by the swigregister people to cause an error. The second line from the bottom received the dictionary that was the result of nodeTypes, and printed the length of the dictionary along with the category name.

count

result…… ~ ~ I understand that each Net system has only one node, Is there so much SOP, DOP, VOP, etc.? ?? ?? Is that so.

I will post the result for the time being. It is H15.5.632.

('ChopNet', 1)
('Chop', 103)
('CopNet', 1)
('Cop2', 145)
('Dop', 435)
('Object', 146)
('Particle', 1)
('Pop', 68)
('Driver', 42)
('Shop', 205)
('Sop', 430)
('VopNet', 18)
('Vop', 816)

Count the contents of nodeTypes (especially CHOP)

I decided to compare ** CHOP **, which seems to be relatively easy to count. The result of the script is "103" as above.

chopNodes = hou.chopNodeTypeCategory().nodeTypes()
sorted( chopNodes.keys() )
スクリーンショット 2016-12-19 23.22.11.png

On the Houdini UI ...

CHOP

4 columns, 25 rows. ** You can even multiply ** I can't find 3 nodes " for "," popnet" and " vop phop type "on the UI.

However, if you look at the online document as of H12, there is forCHOP, so http://sidefx.jp/doc/nodes/chop/for.html It can be inferred that these are left behind to maintain compatibility with past scene data. Is it so that the amount of VOP is so great?

So how to filter only that node in a script? It seems that this will be my next homework.

Summary

I was helped by the suggestion. Convenient! !!

Next is Yone80 @ github's "Transform to fit a square polygon".

Recommended Posts

How many nodes are there?
Since there are many earthquakes, get the history of earthquakes
[Harlem] There are too many to choose! 13 ways to calculate pi in Python
How to write a string when there are multiple lines in python