Combine nested list items into one multiline string

#1

Hi everyone,
i would like to ask for help with creating multiline string from nested list. In the image below i manage to create list with layers of compound elements. The list contains material and its thickness. I want to create from those items multiline parameter and write it into shared type parameter.
After a lot of searching and experiments i could manage to do it so.
Any idea how to continue? My idea is to manage to create one dimensional list with combined strings with newline element between those values and than use it to set parameter by value.
Thank you for any help.

0 Likes

#2

You could try to implement it by using a python script.

text = IN[0]
newText = []

#add newline to the string
for t in text[:-1]:
	newText.append(t+'\n')

#add last line without newline
newText.append(text[-1])

OUT = ''.join(map(str, newText))
0 Likes

Python Nodes Basics
#3

@Adam_Huleja, use the special character “\n” as a separater, like this:


This way you’ll break down the string to be used in multiline text parameter. There’s a bug with multiline text though, when writing it with API - if you try to edit this text afterwards, you’ll get the single string without breaks.

0 Likes

Nested list to multiline text parameter
#4

Hi and thank you for your response.
Right now iam trying to dive more into python. I am still beginner.
But the problem is still the same. I can manage to join items in one list with builtin nodes. The problem i have is, that i want to combine items in those nested list, but still keeping the upper level list structure. And there is also one condition, that every element can have different count of layers. I cant figure out how to “disassemble” that 2d list into those 1d lists, do the combining of items and store it into final 1d list.

0 Likes

#5

Yeah, i thought about that character. Didn’t managed to get the list items combining to try, if Revit will take it correctly, yet:slight_smile:
Still, thank you for your response.

0 Likes

#6

if you have a 2D list then implement this code

text2D = IN[0]
newText = []

#add newline to the string
for text1D in text2D[:-1]:
	for text in text1D:
		newText.append(text + '\n')

#add last line without newline
for text1D in text2D[-1:]:
	for idx, text in enumerate(text1D):
		if len(text1D)-1 > idx:
			newText.append(text + '\n')
		else:
			newText.append(text)

OUT = ''.join(map(str, newText))

Home2.dyn (3.1 KB)

0 Likes

#7

Once again thank you:) but this still gives me result of one string with all of the layers from all of the element types. And what i need is to get a list of strings with same number of items as number of elements (i want to combine only 2nd level of items together, while keeping the 1st level hierarchy of the original list). This is exactly the circle, in which i am whole day :slight_smile: Every approach leads me to only one string with all the layers or some errors :confused:

0 Likes

#8

Home3.dyn (3.2 KB)

text2D = IN[0]
newText = []

for text1D in text2D:
	t = []
	for idx, text in enumerate(text1D):		
		if len(text1D)-1 > idx:
			#add newline to the string
			t.append(text + '\n')
		else:
			#add last line without newline
			t.append(text)
	newText.append(''.join(map(str, t)))

OUT = newText
0 Likes

#9

@Adam_Huleja Would this work for you?

3 Likes

#10

@Vikram_Subbaiah
so simple and so clean… that is absolutely the best solution :slight_smile:

1 Like

#11

Really?? I swear, that i have tried the String.Join node. Maybe i didnt have brain capacity to solve such a trivial problem.
Thank you and sorry for such a lame problem.
Thank you all:)

0 Likes

#12

Oooh, i see, i didnt use the List.First node before and that was the missing part, which i overlooked.

0 Likes

#13

I am also a bit embarrassed. Whenever I run into problems, I know that I can solve it by using Python by 99% certainty. But I have to give @Vikram_Subbaiah he have more than once shown that solutions can be made using OOTB nodes. I am grateful to learn from him :slight_smile:

3 Likes