keqiquan Posted February 16, 2017 Share Posted February 16, 2017 I am a rookie for python . so I have a lot of questions about python. Hope someone can help me because I really want to learn python. i have a simple code : sel = hou.selectedNodes() if len(sel) >== 1: sel[0].parm("px").setExpression("$CEX") sel[0].parm("py").setExpression("$CEY") sel[0].parm("pz").setExpression("$CEZ") is ablout set centroid pivot in transformation.I hope that this script can be used on many transformation node at once. not just single node so i try write this: sel = hou.selectedNodes() if len(sel)>=1: for i in sel: i[0].parm("px").setExpression("$CEX") i[0].parm("py").setExpression("$CEY") i[0].parm("pz").setExpression("$CEZ") I got a Error : 'ObjNode' object does not support indexing. how i can fix this.and how can find simple houdini python simple tutor? Thank you for your help! Quote Link to comment Share on other sites More sharing options...
anim Posted February 16, 2017 Share Posted February 16, 2017 since for i in sel will not be run if sel is empty, you don't need the first if then i already contains single object per iteration, so lose the [] sel = hou.selectedNodes() for i in sel: i.parm("px").setExpression("$CEX") i.parm("py").setExpression("$CEY") i.parm("pz").setExpression("$CEZ") 1 Quote Link to comment Share on other sites More sharing options...
MrScienceOfficer Posted February 16, 2017 Share Posted February 16, 2017 # Get the selected nodes in a list nodes = hou.selectedNodes() # Loop over the selected nodes list for node in nodes : node.parm("px").setExpression("$CEX") node.parm("py").setExpression("$CEY") node.parm("pz").setExpression("$CEZ") In the second sample you were trying to index ( i[0] ) a node. Whereas, in the first code example, you were indexing the node list ( sel[0] ). A good way to learn python is printing things out for example, print type(i) would have told you that 'i' was an ObjNode and not a Parm like in the first example. 1 Quote Link to comment Share on other sites More sharing options...
anim Posted February 16, 2017 Share Posted February 16, 2017 you can as well safeguard it for certain node type like Transform SOP sel = hou.selectedNodes() for i in sel: if i.type().nameWithCategory() == 'Sop/xform': i.parm("px").setExpression("$CEX") i.parm("py").setExpression("$CEY") i.parm("pz").setExpression("$CEZ") 1 Quote Link to comment Share on other sites More sharing options...
keqiquan Posted February 16, 2017 Author Share Posted February 16, 2017 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.