Jump to content

Getting maximum value of attribute


simonj

Recommended Posts

Hi!

I'm a little bit stuck.

I have a RBD fractured object which contains 4 diffent groups of geometry. Before I send in the data to be processed in a custom Force VOP I'd like to find the piece with the maximum mass in the groups, and return this mass.

So it looks like this:

obj1 - mass: 32

obj2 - mass: 210

obj3 - mass: 150

obj4 - mass: 80

In a custom parameter in my Force VOP I want to have an expression that would loop through/search the different groups and return the mass of the group with the highest mass: 210.

Come to think of it, I have no good way of doing this in SOPs either..

Can anyone help me out? :)

Cheers,

Simon J

Link to comment
Share on other sites

Hi!

I'm a little bit stuck.

I have a RBD fractured object which contains 4 diffent groups of geometry. Before I send in the data to be processed in a custom Force VOP I'd like to find the piece with the maximum mass in the groups, and return this mass.

So it looks like this:

obj1 - mass: 32

obj2 - mass: 210

obj3 - mass: 150

obj4 - mass: 80

In a custom parameter in my Force VOP I want to have an expression that would loop through/search the different groups and return the mass of the group with the highest mass: 210.

This is the sort of thing that's much easier in Python. So put a Python expression into the parameter of the Force VOP and put something like this in it:

max(p.findSubData("Position").options().field("mass") for p in pwd().simulation().objects())

The only problem is that HOM doesn't yet support DOP Object groups, so at the moment you have to get trickier if you want to limit this expression to only a certain group of objects.

Come to think of it, I have no good way of doing this in SOPs either..

Some version AttributePromote with "Promotion Method" set to "Maximum" will often do the trick.

  • Like 1
Link to comment
Share on other sites

Thanks man, it worked great. :)

Sure thing. One more quick thought: you can actually get around the no groups in HOM problem a bit if all the objects you care about were created by the same DOP node (say, a RBD Fractured Object). If the name of the node that creates the pieces is named "obj" for example, you could write:

max(p.findSubData("Position").options().field("mass") for p in node("../obj").createdObjects())

and that would restrict the expression to only those objects created by that node. Groups are still the better way to go once HOM support them, but this might be a good workaround. Also, if for some reason you need the mass to show up on the first frame, checking "Solve on Creation Frame" will tell DOPs to do the volume/mass calculations as soon as the objects are created.

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...