# Nested Loop and If Function

## I am trying to make a honeycomb pattern with nested “for” statement and “if” statement. It is an example from book “parametric design for architecture” using MAXScript. I wish to use dynamo to achieve the same outcome. The logic should work, but I am not sure where I get wrong. Attached my code in dynamo and also pasted below.

def make_geometry(i,j)
{
return = [Imperative]
{
//define variables
columns = 1;
rows = 1;

//create polygon
//circle1 = Circle.ByCenterPointRadius(Autodesk.Point.ByCoordinates(0, 0, 0), 5);
//polygon1 = Polygon.RegularPolygon(circle1, 6);

//loop and copy
while (i<15)
{
i = i+1;
while (j <15)
{
j = j+1;
if (i % 2 == 0)
{

``````		}
else
{
}
}
}
``````

}
}
g = make_geometry(1,1);

Any one can give me a hint? Any suggestion for me to get more understanding about dynamo script?

Don’t use static constructors for your circle centre points. This is/was a bug in DS reported here (although it is fixed in newer versions). I’ve updated your code to show what you need to do:

``````def make_geometry(i,j)
{
return = [Imperative]
{
columns = 1;
rows = 1;

while (i < 15)
{
i = i+1;
while (j <15)
{
j = j+1;
if (i % 2 == 0)
{
}
else
{
}
}
}
}
}

g = make_geometry(1,1);
``````

Hi, @Thomas_Mahon, Thank you for your reply. I am using Version 1.2 to test the code again. I just copy your code and past in a code block. It still returns null. I am new to design script and don’t know why. It seems it is not returning a honeycomb. Could you please give me more hint on it? Is it because the bug is still not fixed? Do you mind sending me a .dyn file so I can read closely from it?

Second question is where can I know more about the script design for Dynamo? Can Dynamo read Python directly?

Thanks again.
Xiaoxuan

@Xiaoxuan_Peng
Hello, the Dynamo Primer could be what you are looking for:
http://dynamoprimer.com/en/07_Code-Block/7-2_Design-Script-syntax.html
http://dynamobim.org/learn/

Hi, I finally get a real project to use dynamo scripting. However, it comes to a moment I cannot master the loop/while statement. Here are a list of my questions:

1. Can I use a regular code block to compose the code or do I need to use Python script to run the code?

2. My task is to compare two sheet lists from two files. One with previous template the other is from new template. I want to compare if a sheet existing in both file, if so I want to change the sheet category to match what shown in old file. For example, if A100 exists in new file (in inactive sheet category) and old file (in active sheet category), I want to change the sheet category of A 100 from inactive to active. If A500 does not exist in old file, I want to skip this file. I have shared some image and my dynamo file in the following link. [https://www.dropbox.com/sh/kn6w4owcdheq3wi/AACTIXtV4iwnka5Lu_Dr_nY8a?dl=0](https://www.dropbox.com/sh/kn6w4owcdheq3wi/AACTIXtV4iwnka5Lu_Dr_nY8a?dl=

Any suggestions are welcome! Thank you all in advance.

Xiaoxuan

Hi, I didn’t look at your files precisely but I have a simple suggestion for comparing your sheet lists:

The principle here is to first write one of the list in Excel in order to compare the both lists afterwards.
Remove List from List by Item not Value and Compare Two Lists by Item and Return Item Differences come from Bakery.
Once this is done, you would still need to delete and create the sheets accordingly. I assume that just copy-pasting the sheets from one file to another doesn’t work in your case…

@Yna_Db Thank you for your suggestion. On top of it, I am trying to let dynamo to update the sheet type. I feel that I get close to it, but when I pass a list of sheet purpose in the code, the string change to letters. Below is my code, could you please take a look?

I was assuming that I will get a list of string like “SUBMISSION - ACTIVE” and “SUBMISSION - INACTIVE”. However, it breaks the string into letters.

Do you have any clue? I have also uploaded my dynamo file here. New ReWrite Sheet PurposeType_Post to Forum.dyn (9.1 KB)