Nested Loop and If Function

https://www.google.com/url?sa=i&rct=j&q=&esrc=s&source=images&cd=&ved=0ahUKEwiIt-ywzY7SAhWJ5yYKHYhVAIwQjRwIBw&url=https%3A%2F%2Fwww.pinterest.com%2Fbeekeeperlinda%2Fapiary-thoughts%2F&bvm=bv.146786187,d.cGc&psig=AFQjCNF2knxXnGXT5FGgrErCjf1HRFP4SQ&ust=1487127920047390

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
radius = 20;
columns = 1;
rows = 1;
offset = Math.Cos(30)*radius;

//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)
{

circle1=Circle.ByCenterPointRadius(Autodesk.Point.ByCoordinates(i1.5radius, j2offset+offset, 0), 5);
return = Polygon.RegularPolygon(circle1, radius);

		}
		else
		{
			circle2=Circle.ByCenterPointRadius(Autodesk.Point.ByCoordinates(i*1.5*radius, j*2*offset, 0), 5);
			return = Polygon.RegularPolygon(circle2, radius);
		}
	}
}

}
}
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]
	{
		radius = 20;
		columns = 1;
		rows = 1;
		offset = Math.Cos(30)*radius;

		while (i < 15)
		{
			i = i+1;
			while (j <15)
			{
				j = j+1;
				if (i % 2 == 0)
				{
					pt = Point.ByCoordinates(i*1.5*radius, j*2*offset+offset, 0);
					circle1 = Circle.ByCenterPointRadius(pt, 5);
					return = Polygon.RegularPolygon(circle1, radius);
				}
				else
				{
					pt = Autodesk.Point.ByCoordinates(i*1.5*radius, j*2*offset, 0);
					circle2=Circle.ByCenterPointRadius(pt, 5);
					return = Polygon.RegularPolygon(circle2, radius);
				}
			}
		}
	}
}

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
See also Resources & Curricula on this page:
http://dynamobim.org/learn/

Take a look at this document too:
Redirect Notice

@Thomas_Mahon, @Yna_Db

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)

Thanks in advance. @Thomas_Mahon