Nesting cs in atom referencing?

All topics on coding 4Dscript in Enterprise Dynamics.
Post Reply
MarvinH
Posts: 93
Joined: Tuesday 25 January, 2011 - 11:07
Contact:

Re: Nesting cs in atom referencing?

Post by MarvinH »

Hello Joost,

The setcs/cs function is a built-in engine function to store and retrieve local atom references. Although I cannot immediately see what is going wrong in your code, the use of self-defined local variables may benefit your code. For example, alter your code in the following manner.

Code: Select all

    do(
       Var([atmLoop1], vbAtom),
       Var([atmLoop2], vbAtom),
       
       ForAtomLayerUnder(p(1),
          do(
             atmLoop1 := a,
             ... { do some things with atmLoop1 }
             ForAtomLayerUnder(atmLoop1,
                do(
                   atmLoop2 := a,
                   ... { do some things with atmLoop2 }
                )
             )
          )
       )
    )
This way your code is more clear (i.e. you can name your loop variable in a explanatory way, like atmLoopContainer for the first variable and atmLoopContent for the second variable so you now what the variable is referencing to). Note that setting of the loop variables should be done as the first thing after the "ForAtomLayerUnder" call, because the global atom reference "a" always returns the last activated atom during the execution of the code.

I hope that in this way your code performs as expected.

Regards,

Marvin
Post Reply