demand
The parameters of a node affect the behavior of the node. Therefore, for node users, comparing the differences of parameters between nodes can understand the differences of their behavior.
However, there are too many parameters in some nodes, so it will be troublesome to compare the differences between their parameters. Without tools, you can only jump back and forth between nodes to compare the differences of parameters.
I think it can actually be used Python module of Houdini It's not troublesome to write code to automatically compare and output differences. Finally, if you can output a more readable format (such as csv table or Markdown table syntax), it will make the comparison more efficient.
In addition, I also assume that the types of the nodes being compared are the same, so this makes the code simpler -- just access the parameters in order, because the order of the parameters must be the same.
Compare the difference of two node parameters
The code that compares only two nodes is very simple.
For example, I put two box nodes and adjusted the scaling parameters differently.
#Two contrasting nodes: node1 = hou.node("../box1"); node2 = hou.node("../box2"); #Number of parameters of node parmCount = len(node1.parms()); #Traverse all parameters to find different values for i in range(parmCount) : if(node1.parms()[i].eval() != node2.parms()[i].eval()): message = ""; message += node1.parms()[i].description() message += " " + str(node1.parms()[i].eval()) + " " + str(node2.parms()[i].eval()) print(message)
Output:
Uniform Scale 1.0 3.11
Multi node comparison
When considering multiple nodes, take the 0 as the reference, and compare other nodes with it. As long as one node is different, the values of all nodes of this parameter will be output.
For example, I put three box nodes. The second and third have one parameter respectively, which is different from the first.
#Nodes to compare: (take the 0 as the reference) nodes = []; nodes.append(hou.node("../box1")); nodes.append(hou.node("../box2")); nodes.append(hou.node("../box3")); #Number of parameters of node parmCount = len(nodes[0].parms()); #Traverse all parameters to find different values for i in range(parmCount) : allsame = True; #Are the parameters the same message = ""; #Information is displayed only when there are different parameters message += nodes[0].parms()[i].description() #Parameter name message += " " + str(nodes[0].parms()[i].eval()) #Parameter value of reference node for j in range(len(nodes)-1): #If the parameters are different, write the value if(nodes[j+1].parms()[i].eval() != nodes[0].parms()[i].eval()): allsame = False; message += " " + str(nodes[j+1].parms()[i].eval()) #Same parameter: omit value else: message += " -" if not allsame : #Output information only when there are different parameters print(message)
Output:
Size 1.0 - 1.9 Uniform Scale 1.0 3.11 -
Output MarkDown table syntax
MarkDown table syntax It can also be used in CSDN blog.
such as
| Syntax | Description | | - | - | | Header | Title | | Paragraph | Text |
In the blog, it will become:
Syntax | Description |
---|---|
Header | Title |
Paragraph | Text |
Therefore, the code is modified to:
#Nodes to compare: (take the 0 as the reference) nodes = []; nodes.append(hou.node("../box1")); nodes.append(hou.node("../box2")); nodes.append(hou.node("../box3")); #The first two rows of the MarkDown table: line1 = "| - | " line2 = "| - | " for n in range(len(nodes)): line1 += nodes[n].name() +" |" line2 += "- |" print(line1) print(line2) #Number of parameters of node parmCount = len(nodes[0].parms()); #Traverse all parameters to find different values for i in range(parmCount) : allsame = True; #Are the parameters the same message = "| "; #Information is displayed only when there are different parameters message += nodes[0].parms()[i].description() #Parameter name message += " | " + str(nodes[0].parms()[i].eval()) + " |" #Parameter value of reference node for j in range(len(nodes)-1): #If the parameters are different, write the value if(nodes[j+1].parms()[i].eval() != nodes[0].parms()[i].eval()): allsame = False; message += " " + str(nodes[j+1].parms()[i].eval())+ " |" #Same parameter: omit value else: message += " - |" if not allsame : #Output information only when there are different parameters print(message)
Output:
| - | box1 |box2 |box3 | | - | - |- |- | | Size | 1.0 | - | 1.9 | | Uniform Scale | 1.0 | 3.11 | - |
If you copy this paragraph directly to your blog, it will become:
- | box1 | box2 | box3 |
---|---|---|---|
Size | 1.0 | - | 1.9 |
Uniform Scale | 1.0 | 3.11 | - |
Try in a complex example
Downloadable fabrics It's some display effects of Houdini's official Vellum cloth simulation
Engineering documents can be found in here Download.
I created a default Vellum cloth configuration and then tried to compare it with the current eight cloth configurations
#Nodes to compare: (take the 0 as the reference) nodes = []; nodes.append(hou.node("../default")); nodes.append(hou.node("../vellumcloth10")); nodes.append(hou.node("../vellumcloth11")); nodes.append(hou.node("../vellumcloth15")); nodes.append(hou.node("../vellumcloth3")); nodes.append(hou.node("../vellumcloth6")); nodes.append(hou.node("../vellumcloth8")); nodes.append(hou.node("../vellumcloth9")); nodes.append(hou.node("../vellumcloth_wool")); ...
The results are as follows:
- | default | vellumcloth10 | vellumcloth11 | vellumcloth15 | vellumcloth3 | vellumcloth6 | vellumcloth8 | vellumcloth9 | vellumcloth_wool |
---|---|---|---|---|---|---|---|---|---|
Density | 0.1 | 0.4 | 0.04 | 0.4 | 0.25 | 0.04 | 0.04 | 0.02 | 0.04 |
Thickness | 2 | - | 3 | - | 3 | 3 | 3 | 3 | 3 |
Edge Length Scale | 0.25 | - | - | - | - | - | 0.2 | - | - |
Normal Drag | 10.0 | - | 80.0 | - | - | 40.0 | 80.0 | 40.0 | 80.0 |
Tangent Drag | 0.1 | 2.0 | 0.4 | 5.0 | 1.0 | 0.4 | 0.8 | 40.0 | 0.4 |
Stiffness | 1.0 | 100000000.0 | - | 100000000.0 | - | - | - | - | - |
Damping Ratio | 0.001 | 0.0001 | - | 0.0001 | - | - | - | - | - |
Stiffness | 1.0 | 2000.0 | - | - | - | 0.15 | - | 2.0 | - |
× | -4 | 10 | 10 | 6 | 10 | -6 | -7 | -7 | - |
bendstiffnessscalemode | 0 | - | 1 | - | - | - | - | - | - |
Damping Ratio | 0.01 | - | - | - | 0.0075 | - | 0.1 | - | - |
Rest Angle Scale | 1.0 | - | 2.0 | - | 2.0 | - | - | - | - |
dobendstiffnessfalloff | 0 | - | - | - | 1 | - | - | - | - |
Stiffness Dropoff | 0.0 | 55.0 | 85.0 | 55.0 | 48.0 | 85.0 | 70.0 | 85.0 | 85.0 |
bendstiffnessfalloffdir | 0 | - | 1 | - | 1 | 1 | 1 | 1 | 1 |
dobendstiffnessdropoffmin | 0 | - | - | 1 | 1 | - | - | - | - |
Min Stiffness | 0.0 | - | - | 0.0001 | 5e-06 | - | - | - | - |
Enable Plasticity | 0 | 1 | - | 1 | 1 | 1 | - | 1 | 1 |
Threshold | 10.0 | 3.0 | - | 35.0 | 15.0 | 0.1 | - | 1.0 | 0.005 |
Rate | 1.0 | 6.0 | - | 5.0 | 0.3 | 0.25 | - | 2.0 | - |
Hardening | 1.0 | 0.5 | - | 5.0 | - | 0.3 | - | 2.0 | - |
Promotion Method | 2 | 5 | - | 5 | - | - | - | - | - |
Tag | default | vellumcloth10 | vellumcloth11 | vellumcloth15 | vellumcloth3 | vellumcloth6 | vellumcloth8 | vellumcloth9 | vellumcloth_wool |
Through this list, you can know which parameters have changed, that is, which parameters I need to pay attention to.
Problem record:
Errors will be reported when running python scripts:
I'm on this question Python troubleshooting Unicode encodeerror 'ascii' codec can't encode character error resolution - guest granting - blog Garden The solution is found, that is, run this code first:
import sys reload(sys) sys.setdefaultencoding('utf8')
After that, there was no error