Translate for each point using for loop

Dear dynamo experts!!
I am now learning how design script works, and I am trying to translate each points in a list using for loop,
see pic below


I have a list of points O_T_P, and a list of points to translate to LO_P_X = [-6.5,-6.5,-5,5,5,6.5,6.5] and LO_P_Y = [0,2,2,5,5,2,2,0], I want to use for loop to translate each point in list O_T_P.
my code is below

I’ve looked how for loop works, and tried it, but it didn’t work, it gives me undefined O_T_P
many thanks!!!

The error you are getting is probably either the line new_O_T_P = Geometry.Translate() doesn’t take lists or because your lists are different sizes.

When using a for loop, keep in mind that the syntax for (a in O_T_P) is saying that it will go through the entire O_T_P list and at each loop, a will be the current item in the loop. This means that a is the variable you want to use some how. It represents the item in O_T_P.

You do not use the variable a in the Translate, so you are not translating a single point, but the list O_T_P

So you want to translate a with what? You have two other lists of different sizes, neither match the size of the list of points. If you just want to use the first 3 X and first 3 Y, you are better off not using imperative and for loops. Just type this in the codeblock:

Geometry.Translate(O_T_P, LO_P_X, 0, LO_P_Y);

I did this before using code block and I ignored lacing since you can’t see lacing in code blocks, thanks to your comment that I found out it was the lacing that is causing the problem, I need to change it to cross product, the question is should my code be Geometry.Translate(O_T_P, LO_P_X<3>, 0, LO_P_Y<3>); ?

due to the ignorance of lacing , so I gave up that method, then I saw for loop, the for loop is to execute function each items in a list(correct me if I am wrong),even though my problem is solved, can you give me an example of for loop in my case? thanks!

For cross product, the code block version would just be:

Geometry.Translate(O_T_P<1>,LO_P_X<2>,0,LO_P_Y<3>);
no need for an Imperative statement. Otherwise you would need 3 for loops to make a 3-way cross product.

Also Dynamo has a nifty function where you can click a couple nodes that are connected to each other and then right click the empty graph space and an option called “Node to Code” will turn everything to a single codeblock where possible.

1 Like

thanks for helping me out!!!

1 Like

Hi, kenny, I still want to try using for loop, and I did try something out, I did some changes, and found out my LO_P_X and LO_P_Y doesn’t match then I corrected it, tried it again, but it grabbed the last point of O_T_P, but not the other, why is that?

Sorry I left the office for the night. But the reason why is because the line newlist = Geometry… The = means you are overwriting whatever was in newlist from the other iterations of the for loop. So you get only the final iteration (last point). You have it as = when you should have it added onto a single list. I don’t know designscript’s syntax off the top of my head, sorry.

1 Like

I took your advise and did some research and then it worked, turns out I need to insert an index, and this will take all the index from the list, Thanks for your patience and help!!