# Inserting a list between a fixed index interval

Hi guys!!
image|690x280

I am trying to create a list of 0s and after a fixed amount of lets say 23. after the 23rd “0” it will increase to 800 and so on…

Is there a code that can do this?

What i am trying to accomplish is to insert detail groups in a snake like pattern with a 500 distance between each other.

the values would probably be like this
(i will just have 7 items per row with 4 rows for an example)

x = 0,500,1000,1500,2000,2500,3000,
3000,2500,2000,1500,1000,0,
0,500,1000,1500,2000,2500,3000,
3000,2500,2000,1500,1000,0,
y = 0,0,0,0,0,0,0,
800,800,800,800,800,800,800
1600,1600,1600,1600,1600,1600,1600,
2400,2400,2400,2400,2400,2400,2400
3200,3200,3200,3200,3200,3200,3200
z = 0

I am having a hard time understanding what you want to accomplish. Can you show your attempt in Dynamo or explain with pictures/plan?

If you just want to do this part:

something like this would work:

1 Like

Hi Kenny,

This is what i would like to accomplish. The location of every icon(item) in the diagram below.

I have attached what i have done so far. So i was able to only make out a straight line. although i can manually type the coordinates one by one and.make the list myself but it is time consuming.
Fire Alarm Schematic Diagram.dyn (110.5 KB)

So far what i can only do is these items on a straight line. not on a “S-like” pattern.

That solved part of my problem hahaha at least i got the Y coordinates sorted out.
Thanks!
I Hope you there is a solution for my X coordinates.

CHeers!!

Can you draw a line on that picture for how you want the items to snake around?

Hi Kenny.
Picture below.

Francis

So I gave up trying to do this in node form because it is much easier to do with python:

``````# Enable Python support and load DesignScript library
import clr
from Autodesk.DesignScript.Geometry import *

# The inputs to this node will be stored as a list in the IN variables.
xDist = IN[0]
xInRow = IN[1]
yDist = IN[2]
yInRow = IN[3]
zValue = IN[4]

xList = range(0,xDist * xInRow,xDist)
yList = range(0,yDist * yInRow,yDist)

listX = []
listY = []
# X list
for i in range(yInRow):
if i % 2 == 0:
listX.append(xList)
else:
listX.append(xList[::-1])
#Flatten the X list:
flatX = [item for sublist in listX for item in sublist]

# Y list
for j in range(yInRow*xInRow):
listY.append(yList[j//xInRow])

pointList = []
for x,y in zip(flatX,listY):
pointList.append(Point.ByCoordinates(x,y,zValue))
OUT = pointList
``````

It outputs a list of points that snake around like you asked. It can be modified to output just the X and Y values if you want it to be. Maybe someone like @mellouze can do it better in node form.

1 Like

Hi Kenny,

Amazing!! I was still trying to solve this using some kind of loop node but this is way better!
Thank you so much!!
Cheers

1 Like

Hi @kennyb6

Here it is. I’m not 100% convinced of the Imperative block, I believe we can do better, but I honestly have still some issues with the If statements in CodeBlock (you know, the `a?b:c;` syntax).

``````xList = 0..xDist*(xInRow-1)..xDist;
yList = 0..yDist*(yInRow-1)..yDist;
points = Point.ByCoordinates(xList&lt;2&gt;, yList&lt;1&gt;, zValue);
rev_points = List.Reverse(points@L2&lt;1&gt;);
boole = (0..yInRow-1)%2 == 1;
c = [Imperative]{
result=[];
for(i in 0..List.Count(boole)-1){
if(boole[i]){
result[i] = rev_points[i];
}else{
result[i] = points[i];
}
}
return = result;
};
List.Flatten(c);
``````

1 Like

I always feel like using imperative code blocks are worse than using python because the syntax is so weird and it doesnt produce warnings half the time, just red errors. Any chance this could be done with only nodes?

1 Like

Feel that way too. I’ll give it a try without Imperative blocks.

1 Like

Hi again,

The solution without any Imperative block (there is an If node though …)

``````xList = 0..xDist*(xInRow-1)..xDist;
yList = 0..yDist*(yInRow-1)..yDist;
points = Point.ByCoordinates(xList<2>, yList<1>, zValue);
boole = (0..yInRow-1)%2 == 1;
rev_points = List.Reverse(points@L2<1>);
``````

3 Likes

Thank you @kennyb6 and @mellouze Everything is working now!

Cheers.