ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

How to edit this script and make it link layers?

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Don Jobs
How to edit this script and make it link layers?
on Jun 5, 2019 at 6:09:40 pm

Hi,

I have this working script but I would like to change it. I guess that it would take 2 minutes to change it, but I don't know how... I did manage to change the text on the buttons 😉 hehe

The script has 2 buttons.

1. First, you select all the layers in the project and click the "First Button" to "grab it"
2. Then you select all the compositions in the project and click the "Second Button" to place all the layers from the first seletion to all the selected compositions.

It's working fine, but I need something else... ☺

I need this:

1. First, you select some layers in the active composition and click the "First Button" to "grab it"
2. Then you select another layers in the same composition and click the "Second Button" to link all the layers from "selection one" to "selection two"

Is this a problem? I would change it but I don't know how... I've been trying for hours... but it's not working...

Please help me, if it's not too much work... ☺ Thank you all!

var w = new Window ("palette", "Link");
w.add("button", undefined,"Selection 1",{name:"ok"}).onClick = function(){ SelFootage(); }
w.add("button", undefined,"Link To Selection 2",{name:"ok"}).onClick = function(){ SelComps(); }
w.show();
FootageList = new Array();
function SelFootage()
{
var mySelectedItems = [];
for (var i = 1; i &lt;= app.project.numItems; i++)
{
if (app.project.item(i).selected)
mySelectedItems[mySelectedItems.length] = app.project.item(i);
}
for (var b = 0; b &lt; mySelectedItems.length; b++)
{
var mySelection = mySelectedItems[b];
var myComp = app.project.items;
FootageList[FootageList.length] = mySelection;
}
}
function SelComps()
{
app.beginUndoGroup("Add To Comps");
var mySelectedItems = [];
for (var i = 1; i &lt;= app.project.numItems; i++)
{
if (app.project.item(i).selected)
mySelectedItems[mySelectedItems.length] = app.project.item(i);
}
for (var b = 0; b &lt; mySelectedItems.length; b++)
{
mySelectedItems[b].layers.add(FootageList[b]);
}
FootageList = []
app.endUndoGroup();
}


Return to posts index

Tomas Bumbulevičius
Re: How to edit this script and make it link layers?
on Jun 7, 2019 at 5:09:28 am

Hello Don, heres what needed here:

1. Please properly specify behaviour, by naming 'layers' and 'comps' where its applicable. Now there is a clash of definitions, where you say 'layers in the project' even though layers can be in compositions only, etc.
2. I tested the code and what it actually does - based on initial selection, add those comps into selected project items.
3. Your 'new requirements' are not clear - here is what you are saying. You want to select layers in the composition, and then, by selecting 'other layers' inside the same composition, link them with previously selected layers. What it would do is make copies of selected layers in the first place. Reason for that is ?

Cheers!

Find out more:
After Effects Tutorials: motion design, expressions, scripting.
Boxer - Dynamic Text Boxes Template with a Live Preview


Return to posts index

Don Jobs
Re: How to edit this script and make it link layers?
on Jun 7, 2019 at 11:41:02 am

Hi Tomas,

thank you very much for your reply! ☺

I'm sorry if I wasn't clear enough. So by "layers" I mean: solids, nulls, compositions in the active composition.

I don't understand what you said:
"What it would do is make copies of selected layers in the first place" - Why? It could link "selection 1" with "selection 2"

If there are 10 solids in my composition. First I select the first 5 solids, then I select another 5 and link the first 5 to second 5. By "link" I mean make parent-child connection.

I found this script here on the forum, and it's doing the same thing but in a different way.

Thanks for the help :)

//Parent
var myComp = app.project.activeItem;
var SecondGrp = myComp.selectedLayers[myComp.selectedLayers.length-1].index+1;

for (var i = 0; i &lt; myComp.selectedLayers.length; i++) {
myComp.selectedLayers[i].parent = myComp.layers [SecondGrp+i];
}
// Invert
var comp = app.project.activeItem;

for (var w = 1; w &lt;= comp.numLayers; w++) {
comp.layers[w].selected = !comp.layers[w].selected;
}


Return to posts index


Tomas Bumbulevičius
Re: How to edit this script and make it link layers?
on Jun 7, 2019 at 5:22:53 pm

Don,

thanks for a clarification - indeed, I haven't understood 'linking' aspect in first place!

Now with that clarified - lets say there are 10 layers, starting from top to bottom, 1 to 10. You select first 5, hit the button, then select another 5 (indexed 6 to 10) and hit the second button.

As a result:
1. Index 1 layer should be linked with 6th in such case, or vice versa?
2. What should happen if layers to be 'linked' with other layers, already has different parent?
3. What if selections doesn't have the same amount of layers selected?

This should help to get this down the line. Cheers.

Find out more:
After Effects Tutorials: motion design, expressions, scripting.
Boxer - Dynamic Text Boxes Template with a Live Preview


Return to posts index

Don Jobs
Re: How to edit this script and make it link layers?
on Jun 7, 2019 at 10:38:21 pm

Dear Tomas,

thank you very much for your time. ☺

1. Yes, index 1 layer should be linked with 6th.

2. The script should be used with non linked layers.

(If some layers are linked then the script should override the parenting - this feature is not necessary)

3. If first selection has 10 layers and second selection has 12 layers it should connect the first 10.

If it's easier, would it be possible just to edit the original script? So, first and second selection should be placed in the active composition and the result should be linking the two selections.

Thanks a lot!
Don


Return to posts index

Tomas Bumbulevičius
Re: How to edit this script and make it link layers?
on Jun 8, 2019 at 9:13:21 am

Don, check this out, it should be it.

The only think to keep in mind is that is you make selection not in an incremental order (lets say pick 1,3,2,5 layers for selection A), it will be applied in the same order for your parenting. Other than that, it should be it.

Cheers!

var w = new Window ("palette", "Link");
w.add("button", undefined,"Selection 1",{name:"ok"}).onClick = function(){ selectLayersA(); }
w.add("button", undefined,"Link To Selection 2",{name:"ok"}).onClick = function(){ selectLayersBLink(); }
w.show();
var selectionArray = new Array();

function selectLayersA(){
var activeComp = app.project.activeItem;
var selectedLayersA = new Array();
selectedLayersA = activeComp.selectedLayers;
for (var b = 0; b &lt; selectedLayersA.length; b++){
selectionArray[selectionArray.length] = selectedLayersA[b];
}
}
function selectLayersBLink(){
app.beginUndoGroup("Link to comps");
var activeComp = app.project.activeItem;
var selectedLayersB = new Array();
selectedLayersB = activeComp.selectedLayers;
for (var i = 0; i &lt; selectionArray.length; i++){
if (selectedLayersB[i] != null){
layerA = selectionArray[i];
layerB = selectedLayersB[i];
layerB.parent = layerA;
}
}
selectionArray = []
app.endUndoGroup();
}


Find out more:
After Effects Tutorials: motion design, expressions, scripting.
Boxer - Dynamic Text Boxes Template with a Live Preview


Return to posts index


Don Jobs
Re: How to edit this script and make it link layers?
on Jun 8, 2019 at 11:19:56 am

I love you man! Thanks a million! 😁😊😄

It's working and you just saved me hours and hours of "linking"...

I had to replace "&I" with "<=" ...I guess it's went wrong in copy-paste 😉

God bless you!
Don

var w = new Window ("palette", "Link");
w.add("button", undefined,"Selection 1",{name:"ok"}).onClick = function(){ selectLayersA(); }
w.add("button", undefined,"Link To Selection 2",{name:"ok"}).onClick = function(){ selectLayersBLink(); }
w.show();
var selectionArray = new Array();

function selectLayersA()
{
var activeComp = app.project.activeItem;
var selectedLayersA = new Array();
selectedLayersA = activeComp.selectedLayers;
for (var b = 0; b &lt;= selectedLayersA.length; b++)
{
selectionArray[selectionArray.length] = selectedLayersA[b];
}
}
function selectLayersBLink(){
app.beginUndoGroup("Link to comps");
var activeComp = app.project.activeItem;
var selectedLayersB = new Array();
selectedLayersB = activeComp.selectedLayers;
for (var i = 0; i &lt;= selectionArray.length; i++)
{
if (selectedLayersB[i] != null){
layerA = selectionArray[i];
layerB = selectedLayersB[i];
layerB.parent = layerA;
}
}
selectionArray = []
app.endUndoGroup();
}


Return to posts index

Tomas Bumbulevičius
Re: How to edit this script and make it link layers?
on Jun 10, 2019 at 1:06:46 pm

Hey Don, you are welcome! Yes, those '<' are being escaped into special characters - glad you managed to make this to work.

On the other hand - just curious! Where you will use it?? ☺ Good luck!

Find out more:
After Effects Tutorials: motion design, expressions, scripting.
Boxer - Dynamic Text Boxes Template with a Live Preview


Return to posts index

Don Jobs
Re: How to edit this script and make it link layers?
on Jun 10, 2019 at 4:01:52 pm

I'm working with particles in 3ds Max and need to link all the particles with the after effects layers... So that's why I need it ☺ It's a personal project I'm working on.

Thank you very much! :)


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]