Dear Experts,
Is it possible to do task explained at photo below (by python or dynamo):
I have one mechanical task. That is why trying to do this task. However, no achieved by your recommendation.
Dear Christian, thanks for recomendation. But what you did is not same as we requested:
AAA AND BBB AND CCC
We need:
AAA, BBB AND CCC
Thanks anyways.
Try looking at the total number of objects being combined into a string. If it’s more than 3 include “AND”. You can do this by replacing the final substring or just including an extra condition in a python node.
Voici une version Python (peut être améliorer tres certainement)
Python Script:
# Charger les bibliothèques DesignScript et Standard Python
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# Les entrées effectuées dans ce noeud sont stockées sous forme de liste dans les variables IN.
_list=IN[0]
# Placer votre code au-dessous de cette ligne
cont=[]
for i in (IN[0]):
if len(i)==1:
cont.append([i[0]])
if len(i)==2:
cont.append([i[0]+" AND "+i[1]])
if len(i)==3:
cont.append([i[0]+", "+i[1]+" AND "+i[2]])
# Affectez la sortie Ă la variable OUT.
OUT = cont
cordialement
christian.stan
If you want something scalable you can add conditional checks for the specific conditions you need met.
An alternative
import sys
out = []
first_sep = ", "
second_sep = " and "
for lst in IN[0]:
s = first_sep.join(lst)
s = s[::-1].replace(first_sep[::-1], second_sep[::-1] , 1)[::-1]
out.append(s)
OUT = out
Thank you gentlemen for the scalable and elegant codes
cordially
christian.stan
nag mode in python