iLogic Advanced tools – “For” loops

Marketing
Marketing
  • Updated

by Chris Smith

Introduction

Sometimes when creating automation in iLogic, we may find the need to loop through several objects, like parameters, parts, property values etc. One of the tools available is the FOR loop.

Breakdown

A FOR loop allows the user to simplify their code by cycling through the same code block until specific criteria has been met. This can help in several ways, but mainly by keeping the code as simple as possible while being easier to understand when shared with other users.

Example.

Imagine we have several parts in an assembly, and we would like to change the appearance colour based on user selection. In the model below we would like to change the appearance for different wood types.

ilogic loops 1.png

We could write the code like the below example, referencing each part for each appearance option.

ilogic loops 2.png

The above code will update the appearances as expected, however editing the code, adding more appearances or additional components would require over a dozen edits per appearance.

With a ‘For’ loop, we can streamline the code. The below code will cycle through each component in the assembly and change the material/appearance.

ilogic loops 3.png

The code is much simpler than the previous code example and allows for much faster updates.

Another example below will cycle through numbers 1 to 10 and display a message box to display the current value.

ilogic loops 4.png

As below.

ilogic loops 5.gif

In summary, the For loop can be a very powerful tool not only to streamline your code, but to also make future editing simpler as well.

 

By Chris Smith

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.