Python script to create list of layers depending on the input layer names

Hi
I have 2D objects that are added to a specific layer and then I create 3D solids but they need to be put in a different layer for example
2D object is on layer T-------EZT------ and I want to put the 3Dsolids on layer T-------EJT------

But I can’t make the python script to work for me.

Someone of you might have an answer what I can do?

Best regards,
Patrick

solids on 3D-layer.dyn (8.3 KB)

Use lay_out.append instead.

Although lay_out is a list you’re using = which isn’t adding, it’s overwriting.

Also you don’t need to write, “in range” because if you write - for i in xxx: it will enumerate over each item in the list regardless of length.

2 Likes

Hi @patrick.ericson ,

You could also do this with DesignScript:

"x" ? "y" :
"y" ? "z" :
"x" ;

Or using dictionaries, which would probably be the easiest one to read, change & understand.

(Or apply the changes which @Alien suggested)

2 Likes

I tried to write Python code to online IDE from my mobile phone. I know it is not exactly what you are looking for but I hope it can help you Rename string - Replit

layers = [“EZT”, “EZF”, “AAA”]
out =
old_char = “Z”
new_char = “J”
for i in layers:
if old_char in i:
new = i.replace(old_char, new_char)
out.append(new)
else:
out.append(“EJE”)

OUT=out

1 Like

Thank you guys!
Really appreciate you effort!

I asked a colleague and got this suggestion

# Load the Python Standard and DesignScript Libraries
import sys
import clr

# The inputs to this node will be stored as a list in the IN variables.
Lay_in = IN[0]

#**This was the interesting part!!**
Lay_out=["None"]*len(Lay_in)



for i in range(0, len(Lay_in)):
	if Lay_in[i] == "T-------EJT------":
		Lay_out[i] = "T-------EZT------"
			
	elif Lay_in[i] == "T-------EJF------":
		Lay_out[i]  = "T-------EZF------"
		
	elif Lay_in[i] == "T-------EJO------":
		Lay_out[i] = "T-------EZO------"

	elif Lay_in[i] == "T-------EJR------":
		Lay_out[i]  = "T-------EZR------"

	else:
		Lay_out[i] = "T-------EZE------"

# Assign your output to the OUT variable.
OUT = Lay_out

That will give you a multiple of the same item.

I thought you wanted a different item for each one?

As I said before, you need Lay_out.append

Sorry @Alien
My bad, i switched layer codes in my script and missed that when I uploaded the pictures and the code, that’s the reason they differ.
In my script they work just fine but I will try to use the example from @Drbohlav to make the script less project specific

1 Like

FYI: You could also use the node List.ReplaceMultiple from the Clockwork package.