Jump to content

Cloth constraint; updating with Python


stevegh

Recommended Posts

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  :o

-Steve

python_constrainedPoints_sh.hip

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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() ?

Link to comment
Share on other sites

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 by anim
Link to comment
Share on other sites

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: :blush: 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

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...