AE ENHANCERS

Expressions/Scripts/Presets
It is currently Wed Jun 19, 2013 6:53 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: sort to individual folder 1.0b
PostPosted: Mon May 14, 2012 10:03 am 
Offline

Joined: Sun May 06, 2012 2:11 pm
Posts: 12
hey all,
I have written a new (simple) script. The purpose of this script is to take selected items in your project window and place them in their own folder named after themselves.
It available on http://vidjuheffex.com/scripts/

I had an issue with the first uploaded version of the script:
Code:
app.beginUndoGroup("Sort To Individual Folders");
var mySelectedItems = [];

for (var i = 1; i <= app.project.numItems; i++){
    if (app.project.item(i).selected){
    mySelectedItems[mySelectedItems.length] = app.project.item(i);
    }
    else{
        alert("Please select an item(s) in the project bin!");
        break;
        };
   
}

for (var i = 0; i < mySelectedItems.length; i++){
    var mySelection = mySelectedItems[i];
    var compFolder = app.project.items.addFolder(mySelection.name);
    mySelection.parentFolder = compFolder;
}
app.endUndoGroup;


this seemed to be working in CS5.5 (windows 7 64bit) but when I came to work (CS5 boxes) selecting layers and clicking the script would always launch the alert box, the user would have to click it like 20 times and then the script would work?

The current solution is:

Code:
app.beginUndoGroup("Sort To Individual Folders");
var mySelectedItems = [];

for (var i = 1; i <= app.project.numItems; i++){
    if (app.project.item(i).selected === true){
    mySelectedItems[mySelectedItems.length] = app.project.item(i);
    };

  }

for (var i = 0; i < mySelectedItems.length; i++){
    var mySelection = mySelectedItems[i];
    var compFolder = app.project.items.addFolder(mySelection.name);
    mySelection.parentFolder = compFolder;

}

app.endUndoGroup;


The obvious difference is that there are no alerts anymore, I also added an '==' comparison to the first 'for' loop (this was what I thought would fix the bug but when I had this and the else{} it was still bugging out.) I left it in since otherwise no comparison was being made.

How can I get the alerts back, I think I've pin pointed where the problem is, just not the solution. Any help would be greatly appreciated thanks!


Top
 Profile  
 
 Post subject: Re: sort to individual folder 1.0b
PostPosted: Mon May 14, 2012 4:41 pm 
Offline

Joined: Sat Jun 26, 2004 10:01 am
Posts: 299
Location: Folsom, CA
I'd do it like this:

Code:
{
   var mySelectedItems = app.project.selection;

   if (mySelectedItems.length > 0){
      app.beginUndoGroup("Sort To Individual Folders");
      for (var i = 0; i < mySelectedItems.length; i++){
             var mySelection = mySelectedItems[i];
             var compFolder = app.project.items.addFolder(mySelection.name);
             mySelection.parentFolder = compFolder;
      }
      app.endUndoGroup;
   }else{
           alert("Please select an item(s) in the project bin!");
   }
}


Dan

_________________
http://www.motionscript.com


Top
 Profile  
 
 Post subject: Re: sort to individual folder 1.0b
PostPosted: Mon May 14, 2012 9:58 pm 
Offline

Joined: Sun May 06, 2012 2:11 pm
Posts: 12
Thanks Dan! If you don't mind, I have a few questions in regards to that solution.

The first variable:
Code:
var mySelectedItems = app.project.selection;


Does this mean I do not have to loop through to find the selected items, but can merely summon them and their value?


Also:
Code:
var mySelection = mySelectedItems[i];
             var compFolder = app.project.items.addFolder(mySelection.name);


This bit. In my previous code, I passed the selected items into an array so that the number of layers wouldn't change while i is counting. Why does this not matter here?

I see what you did with the undo groups, and that makes sense.

I have updated my code and I will re-upload it to my site, but really for me the most important things is understanding the "why" of my early bugs.

Thanks again!


Top
 Profile  
 
 Post subject: Re: sort to individual folder 1.0b
PostPosted: Tue May 15, 2012 10:52 pm 
Offline

Joined: Sat Jun 26, 2004 10:01 am
Posts: 299
Location: Folsom, CA
>Does this mean I do not have to loop through to find the selected items, but can merely summon them and their value?

That's correct.

>Why does this not matter here?

It's pretty much equivalent to your loop. mySelectedItems is an array of items selected at the time the script launched.

Dan

_________________
http://www.motionscript.com


Top
 Profile  
 
 Post subject: Re: sort to individual folder 1.0b
PostPosted: Tue May 15, 2012 11:00 pm 
Offline

Joined: Sun May 06, 2012 2:11 pm
Posts: 12
Thanks, makes sense!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group