martinkrol Posted March 18, 2021 Share Posted March 18, 2021 ( I posted this on the sidefx forum as well, posting here as well to hopefully get more eyes on this . ) Hey there guys. So in my journey to learn some scripting/python... I am having some issues ( code below ) So I am trying to create a shelf script that goes through all geo objects in the scene, creates a new specific geo node, and within it make a pointcloud that would be made from the values collected. I am hoping to build the pointAttrib dict, and as it's looping through the objects, append to the list. at the end of the script, I want to print/use the list of values but only one set of values prints. I am expecting at least 10 object names and their respective values. Anyone have the time to point me in the right direction? I'd love to know what I am doing wrong. pointAttrib ={} def selectSubChildrenOfType(node, node_type): for child in node.allSubChildren(): if child.type() == node_type: #print child.name() #print child.worldTransform() trX = str(child.worldTransform().at(3,0)) trY = str(child.worldTransform().at(3,1)) trZ = str(child.worldTransform().at(3,2)) #create dictionary from info above. keys = {'name': child.name(), 'tx': trX, 'ty': trY, 'tz': trZ} pointAttrib.update(keys) # print "obj "+ (pointAttrib["name"]) + " transX " + (pointAttrib["tx"]) # print a readable version of the values we generated. # print "translate X: " + trX # print "translate Y: " + trY # print "translate Z: " + trZ # executes the defined function above. selectSubChildrenOfType(hou.node("/obj"), hou.objNodeTypeCategory().nodeTypes()['geo']) #create a point per transform matrix that was found in the selctSUbChildrenOfType function. for key in pointAttrib: print key print pointAttrib[key] Question number 2: How would the code look for creating a node only if it doesn't exist. ( if I point to the specific node directly ). It's a bit of a chicken or an egg problem and I'm not sure how I would solve it. So far I have tried.. but yeah it's not right, but at least thats where my head is at. Any ideas? hints? tips? def createNodeIF(node, name) for child in node.allSubChildren(): if child.name() != name: hou.node("/obj").createNode("geo", "pointcloud" ) Any help would be appreciated. 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.