Find and delete any duplicate work items
1880 6 1- cybernetix
- Member
- 22 posts
- Joined: 9月 2015
- Offline
- cybernetix
- 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)
# 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
- Member
- 22 posts
- Joined: 9月 2015
- Offline
- alexandru_p
- 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)
- cybernetix
- 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?
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
- alexandru_p
- 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]
- cybernetix
- Member
- 22 posts
- Joined: 9月 2015
- Offline
-
- Quick Links