stevegh Posted July 24, 2014 Share Posted July 24, 2014 Forgive the naivety of this question: In the attached file I am trying to simply set up a grid cloth object where-in I can change the number of points in the grid, having a constraint update correctly. To achieve this, I have a Python SOP toss the points from a group into a detail attribute. Then in DOPs, I am trying to update the target constraint points parameter using this attribute. I am unsure of the correct way to do this however, as currently the points are returned but the constraint doesn't work. I have tried adding a spare parameter, and setting the constrainedpoints parameter directly using the expression, but this requires that I select the node manually for it to update after I've changed the number of points on the grid. This is the only method I've managed to get working. What is the preferred method for doing this? Thank you for your patience -Steve python_constrainedPoints_sh.hip Quote Link to comment Share on other sites More sharing options...
stevegh Posted July 30, 2014 Author Share Posted July 30, 2014 Perhaps I can rephrase the question. How would one use a multi-line python expression in a parameter field to set that parameter field's value? Does this have to be done through callbacks in the python hdamodule? Quote Link to comment Share on other sites More sharing options...
edward Posted July 31, 2014 Share Posted July 31, 2014 You don't (and can't). Just have your python expression return the value that you want to be used. Quote Link to comment Share on other sites More sharing options...
stevegh Posted July 31, 2014 Author Share Posted July 31, 2014 Hey Edward, So I have this as my parameter field expression: node = hou.pwd() for i in node.processedObjects(): if i.name() == node.parm('constrainedobject').eval(): return i.geometry().attribValue('target') It returns the correct value to field, but the constraint doesn't work. It only works if I explicitly set the parameter value TO that value, overwriting the expression itself. What is the correct method for doing this? Thanks! python_constrainedPoints_sh2.hip Quote Link to comment Share on other sites More sharing options...
edward Posted August 1, 2014 Share Posted August 1, 2014 Some problems come to mind: - What if there's no match? You still need to return something - I'm not too sure in DOPs, but doesn't processedObjects() give the objects that *get processed* on this node? But to this, the node needs to do the processing first, and to do that, it needs the value of your parameter. So this leads into an infinite loop. Perhaps you want to get the input's processedObjects() or perhaps objectsToProcess() ? Quote Link to comment Share on other sites More sharing options...
anim Posted August 1, 2014 Share Posted August 1, 2014 (edited) aren't you overcomplicating things a bit? forget both Python SOP and python expression in the target constraint just put your group name (seam) in the Constrained Points parm it will be procedural and work when you change grid resolution as the seam group is always procedurally generated from border points Edited August 1, 2014 by anim Quote Link to comment Share on other sites More sharing options...
stevegh Posted August 1, 2014 Author Share Posted August 1, 2014 Hey guys, @Edward: I had checks in before to make sure I was grabbing the right thing or I'd return an empty string, but it didn't make a difference when I had another parameter field set the expression, it just worked but I would have to select the constraint node for it to update. I've attached a file that does this. Also the objectstoProcess method has to be implemented inside a python DOP. @Tomas: Derp. Learn 26 new things every day. Just out of curiosity do you know how to get this to work via python? I haven't tried it yet but I feel it would be quite easy via HScript and if it is to be deprecated in favor of python I'd sure like to know how! Thanks! python_constrainedPoints_sh3.hip 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.