Search - User list
Full Version: Filter by Expression/Range to delete wedge nodes at Random
Root » PDG/TOPs » Filter by Expression/Range to delete wedge nodes at Random
Can you filter random values within a range using an expression?

"Please look at image attached"

i.e I have 495 Wedge Index's generated.

I would like to randomly delete 200 index's at random and not in a sequential order that is set in the range. So a total of 200 index's will be deleted but selected at random.

Would this be done in using a filter by range or filter by expression.

If so. what expression is best to do this.

I have tried this python script but it doesn't seem to work:

("`@pdg_frame`" if "`@pdg_frame`" in random.choices(range(0,10), k=10) else None)
You can't mix HScript expression functions/variables like @pdg_frame and Python in the same expression. If you're using a Python expression, you'll need to use pdg.workItem() to access the work item that the parameter is being evaluated against. For example, pdg.workItem().frame in a Python expression is the same as @pdg_frame in an HScript expression.

pdg.workItem() will return a pdg.WorkItem instance that you can use to access attributes and intrinsic data: []
Thanks for that, so but changing my @pdg_frame to pdg.workItem().frame. Will that solve my main problem or are there other definitive issues wrong in my code, because it is still not working.

Even after changing the Language to python in my expression settings.
It's pretty hard to say what the issue is without actually seeing the .hip file.

If you want to delete exactly 200 work items, then that approach probably won't work. The filter expression is evaluated independently for each work item, which means there's no shared state and no way for you to ensure that an exact number are deleted. You're better of using a Python Processor TOP, which has access to the full list of input work items. Something like:

import random

choices = random.sample(range(0, len(upstream_items)), k=200)

for index, upstream_item in enumerate(upstream_items):
    if index not in choices:
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB