Find and delete any duplicate work items

   1935   6   1
User Avatar
Member
22 posts
Joined: 9月 2015
Offline
Is there any way to do this - before i run the render TOP?
Edited by cybernetix - 2023年5月15日 10:11:49
User Avatar
Member
22 posts
Joined: 9月 2015
Offline
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)
User Avatar
Member
22 posts
Joined: 9月 2015
Offline
anyone?
User Avatar
Member
27 posts
Joined: 6月 2013
Offline
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)
User Avatar
Member
22 posts
Joined: 9月 2015
Offline
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?
Edited by cybernetix - 2023年5月17日 15:09:13
User Avatar
Member
27 posts
Joined: 6月 2013
Offline
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]
User Avatar
Member
22 posts
Joined: 9月 2015
Offline
thanks that makes sense, i have 15 attibs, so gonna be a bit of a pain, I better learn python!
Edited by cybernetix - 2023年5月18日 02:53:57
  • Quick Links