Hi guys!
I am trying to develop a python script that allows me to add a number to the Revision Clouds Mark parameter according to its Comments (same string Comments). The strings will be then formatted so it can be exported to Excel, generate a txt. file that can easily be pasted on a sheet.
I was able to do this through a 100% Dynamo script, but I would like to mimic the same behavior in Python, as I am learning the language. In Python the output is correct according to my needs, but as soon as I paste it to the Python Dynamo node, my output turns out to be different (see pic).
Is this due to the fact that I am using some extra Python modules to make my life easier?
This is my Python code which I copy/paste to Dynamo Python node. Just changed the input and output in the Python node.
import itertools
from collections import Counter
comments = [
"wand aangepast", "plafond verlaagd", "kozijn", "kozijn",
"kozijn", "plafond verlaagd", "morgen", "kozijn",
"sloop", "sloop", "niks", "sloop"
]
items_repeated = []
items_repeated_amount_total = []
unique_mark = []
# Making that list a unique element list
for item in comments:
if item not in items_repeated:
items_repeated.append(item)
print("Items repeated are :",items_repeated)
items_repeated_amount_total = len(items_repeated)
# Making a list representing the numbering base
# So it can be used when looping according to the amount
# Of same comments
for mark in range(1, items_repeated_amount_total + 1):
unique_mark.append(mark)
#print(mark)
print("Unique mark is: ", unique_mark)
# Using Counter class from collections module to check
# The ammount of comment repetitions in the list
dic_comments = Counter(comments)
print(dic_comments)
# Convert dictionary values to list
dic_values = []
for key, value in dic_comments.items():
dic_values.append(value)
print("Number of repetitions of mark values: ", dic_values)
# Cycle the unique mark values according to the (converted) dictionary values
# That represent the amount of same comments
mark_sequence = list(itertools.chain(*(itertools.repeat(elem, n)
for elem, n in zip(unique_mark, dic_values))))
print("Items to be inserted in the revClouds: ", mark_sequence)
Any tip in the right way would be wonderful. Thank you in advance