cybernetix
May 15, 2023 10:08:51
Is there any way to do this - before i run the render TOP?
cybernetix
May 15, 2023 11:35:35
ChatGPT recommends using a python processor with this: but it doesn't work.
# Create a dictionary to store the data of each work item and its index in upstream_items
data_dict = {}
for i, item in enumerate(upstream_items):
data_dict = i
# Loop through the upstream_items list again to check for duplicates
for item in upstream_items:
# Check if the current item's data already exists in the dictionary
if data_dict != item.index:
# If it does, it's a duplicate, so remove it
item_holder.removeWorkItem(item)
cybernetix
May 17, 2023 00:32:27
anyone?
alexandru_p
May 17, 2023 14:25:50
added_items = set()
for item in upstream_items:
value = item.intAttribValue("attrib_to_check")
if not value in added_items:
new_item = item_holder.addWorkItem(parent=item)
added_items.add(value)
Depending on what "duplicate work item" means to you, you'd have to change the "attrib_to_check", but also the intAttribValue (if the attribute is not an int, but something else, like a float or string)
cybernetix
May 17, 2023 14:49:53
Thanks so much for the reply, i had reverted to manually deleting from my csv printout!
I want to delete any items that have ALL the exact same values on all the attributes set by my wedges, if just one attribute is different, then I want to keep it. (pdg_index, wedgeindex not included)
Not sure if I'm able to replace "attrib_to_check" with a "*" then?
alexandru_p
May 17, 2023 16:03:56
Depends on how many attributes there are. Instead of holding a set, you could hold a tuple containing each attribute.
added_items = []
for item in upstream_items:
value = (item.stringAttribValue("stringA"), item.floatAttribValue("floatB"), item.intAttribValue("intC"), item.intAttribValue("intD"))
if not value in added_items:
new_item = item_holder.addWorkItem(parent=item)
added_items = added_items + [value]
cybernetix
May 18, 2023 01:14:00
thanks that makes sense, i have 15 attibs, so gonna be a bit of a pain, I better learn python!