Skip to main content
Participant
February 20, 2014
Answered

Moving Solids

  • February 20, 2014
  • 1 reply
  • 443 views

Hello,

I cannot figure out, to save my life, why this piece of code doesn't move all my solids into my "solids' folder.

I am testing using 4 solids in my project source, and it moves all but 1. They aren't the bottom files in my source and so the script def. loops through them. It also looks like the script skip every second file per the screenshot at the bottom of this post.

There is nothing corrupt with the loop. Alert tells me that X equals 4.

Does anyone have any ideas?

var i = 1;

var x= 0;

var solidos = app.project.items.addFolder("Solids");

while (i <= app.project.numItems) {

    if(app.project.item(i).mainSource instanceof SolidSource){

   

        app.project.item(i).parentFolder = solidos;

          

        x++;

       

    }

    ++i;

}

alert(x);

https://www.dropbox.com/s/dcd1hb4qmixtf1f/screen2.jpg

This topic has been closed for replies.
Correct answer françois leroy

Hi!

I'm not sure the loop is correct. When you change your solid's parentFolder, you also change its index value... the value of X could be a "fake positive" (I don't get why, though...)

You could try storing your solids in an array instead of moving them.

Then you can loop into the array and move them...

This way you're sure you don't mess with indices.

var i = 1;

var mySolids = new Array();

var solidos = app.project.items.addFolder("Solids");

while (i <= app.project.numItems) {

    if(app.project.item(i).mainSource instanceof SolidSource){

  

        mySolids.push(app.project.item(i));

      

    }

    ++i;

}

for (s = 0; s < mySolids.length; s++) {

     mySolids.parentFolder = solidos;

}

Cheers,

François

1 reply

françois leroy
françois leroyCorrect answer
Inspiring
February 20, 2014

Hi!

I'm not sure the loop is correct. When you change your solid's parentFolder, you also change its index value... the value of X could be a "fake positive" (I don't get why, though...)

You could try storing your solids in an array instead of moving them.

Then you can loop into the array and move them...

This way you're sure you don't mess with indices.

var i = 1;

var mySolids = new Array();

var solidos = app.project.items.addFolder("Solids");

while (i <= app.project.numItems) {

    if(app.project.item(i).mainSource instanceof SolidSource){

  

        mySolids.push(app.project.item(i));

      

    }

    ++i;

}

for (s = 0; s < mySolids.length; s++) {

     mySolids.parentFolder = solidos;

}

Cheers,

François