Code Block- Function

I’m trying to use blocks of code to solve the problem instead of using the buttons on the dynamo. This is what I am seeking to do.

I’m trying to understand how the code block works through the example above. I’d love to find answers to problems. Thank you for reading. :slight_smile:

try using While instead of For, dont know why but in some cases it helps.

Could you paste the block of code, drop the file or something? Thanks.

hi Organon. Thanks for answering. This is my file
BT Cau tao.dyn (36.3 KB)

I think the problem is here

The problem is that you decalre the arguments for sl, x, and bk1 as lists when they are scalars. DesignScript therefore expects list. As you are using an imperative block the entire ‘list’ is used to calculate t1 and the radius of the circle. Since you havent provided a list the calculations fails which is why you get nulls. Even if you gave it lists for all the arguments it would still fail as you would need to index.

Here’s the fix:

def dt(sl:int,x:int,bk1:int,npoint:var[])
	return =[Imperative]
		t1 = x/sl;

		t2 = {};
		for ( i in GetKeys(npoint) )
			t2[i] = Circle.ByCenterPointRadius(npoint[i], bk1 + i* t1);
		return = t2;

dt(sl, x, bk1, npoint);

You are always solved my problems. :nụ cười:
Thank you very much