Loop in Code Block / Designscript

I want to create 2 points (1,0,0) and (2,0,0) by using for loop in Code Block / Designscript, but it doesn’t do anything, and there is no error message.

I know how to do it in regular way, but I want to do it by "Loop"

Loop.dyn (2.8 KB)

Need to define the results - Return =

Hi Jacobs,

Like this?


Nothing shows up and there is no error.

Looks as if you still need to append the results onto the list before you return it. Check out this documentation from @solamour’s BiLT class last year.

Also, you don’t need to go imperative in this case - just process the list as you normally would.

5 Likes

Thanks for the link, just got down to here…


Edit: Just for the record I did finish it, thanks @solamour great resource!

1 Like

@ JacobSmall
If I don’t use Imperative, DY shows error, say it’s can only be used in imperative mode.

@ Mark.Ackerley
I tried to mimic the code in the document, but it doesn’t create any point.


  1. your assign statement doesn’t make sense - you are assigning a point to a list.
  2. you might be hitting a bug with fully qualified functions in imperative blocks.
  3. when possible - avoid imperative. It’s simply not as robust as the rest of the language, as very few nodes compile to it.
  4. hook up a watch node to see what the output is.

do this:
point1[i] = Point.ByCoordinates(i,0,0)

4 Likes

Michael_Kirschner2
Thank you for the tips.

" 3. when possible - avoid imperative. It’s simply not as robust as the rest of the language, as very few nodes compile to it."
——Designscript manual says:

“do this: point1[i] = Point.ByCoordinates(i,0,0)”
2
No error, no point created.

The code that @Michael_Kirschner2 posted doesn’t need to be in an imperative code block.

i=1..2;
point1=Autodesk.Point.ByCoordinates(i,0,0);

Notice that using the code there for every value in i you are getting a point. No imperative code required. Design script manages replication internally in most ‘for loop’ cases using list lacing and levels.

Here are a few more samples to get you started:

http://designscript.io/DesignScript_user_manual_0.1.pdf

@Xiaofei_Ying In your case i starts with 1
Ensuring the first index is 0 should sort things out
for

2 Likes

I found the culprit: “Autodesk.Point.ByCoordinates(i, 0, 0)”, sholuld be “Point.ByCoordinates(i, 0, 0)”

this is the bug I suspected - it’s fixed in 2.1 -
you can do
func = Autodesk.Point.ByCoordinates() outside the imperative block
and then func(1,1,1)

1 Like

Michael_Kirschner2

I learn from other post that package Rhynamo cause this issue.