Highlighted

How to “update markers from source” using ExtendScript?

Contributor ,
Oct 18, 2020

Copy link to clipboard

Copied

Is it possible to copy comp markers to the corresponding layer using ExtendScript? Manually this is done by creating a “dummy” marker on the layer, right-clicking it and then selecting “update markers from source”.

Correct answer by Greg5F9B | Community Beginner

You can do ths with app.executeCommand(number returned by find); and app.findMenuCommandId(string);

 

The way most of these work are the same if you was to do it manually. E.g. To update markers you need to have the layer selected, then Layer > Markers > Update... So you need to do the same in script.

 

 Also if a layer that isn't a comp and is selected that menu would be greyed out same will happen with scripting.

 

app.beginUndoGroup("Update Markers From Source");

layers = app.project.activeItem.layers;

app.executeCommand(app.findMenuCommandId("Deselect All")); //Make sure non comp items are selected

for(var i = 1;  i <= layers.length; i++){
        
        if (layers[i].source instanceof CompItem){ //Make sure layer is a comp
            layers[i].selected = true;
            app.executeCommand(app.findMenuCommandId("Update Markers From Source"));
            layers[i].selected = false;
        }        
    }

app.endUndoGroup();

 

TOPICS
How to, Scripting

Views

56

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

How to “update markers from source” using ExtendScript?

Contributor ,
Oct 18, 2020

Copy link to clipboard

Copied

Is it possible to copy comp markers to the corresponding layer using ExtendScript? Manually this is done by creating a “dummy” marker on the layer, right-clicking it and then selecting “update markers from source”.

Correct answer by Greg5F9B | Community Beginner

You can do ths with app.executeCommand(number returned by find); and app.findMenuCommandId(string);

 

The way most of these work are the same if you was to do it manually. E.g. To update markers you need to have the layer selected, then Layer > Markers > Update... So you need to do the same in script.

 

 Also if a layer that isn't a comp and is selected that menu would be greyed out same will happen with scripting.

 

app.beginUndoGroup("Update Markers From Source");

layers = app.project.activeItem.layers;

app.executeCommand(app.findMenuCommandId("Deselect All")); //Make sure non comp items are selected

for(var i = 1;  i <= layers.length; i++){
        
        if (layers[i].source instanceof CompItem){ //Make sure layer is a comp
            layers[i].selected = true;
            app.executeCommand(app.findMenuCommandId("Update Markers From Source"));
            layers[i].selected = false;
        }        
    }

app.endUndoGroup();

 

TOPICS
How to, Scripting

Views

57

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 18, 2020 0
Community Beginner ,
Oct 18, 2020

Copy link to clipboard

Copied

You can do ths with app.executeCommand(number returned by find); and app.findMenuCommandId(string);

 

The way most of these work are the same if you was to do it manually. E.g. To update markers you need to have the layer selected, then Layer > Markers > Update... So you need to do the same in script.

 

 Also if a layer that isn't a comp and is selected that menu would be greyed out same will happen with scripting.

 

app.beginUndoGroup("Update Markers From Source");

layers = app.project.activeItem.layers;

app.executeCommand(app.findMenuCommandId("Deselect All")); //Make sure non comp items are selected

for(var i = 1;  i <= layers.length; i++){
        
        if (layers[i].source instanceof CompItem){ //Make sure layer is a comp
            layers[i].selected = true;
            app.executeCommand(app.findMenuCommandId("Update Markers From Source"));
            layers[i].selected = false;
        }        
    }

app.endUndoGroup();

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 18, 2020 1
Contributor ,
Oct 18, 2020

Copy link to clipboard

Copied

Thank you. This is a very useful advice. I tried it and it works if I manually open the comp in AE and then run the script.

 

In my case, I’m creating a lot of comps dynamically and adding layers to them without doing anything manually in AE:

 

var newComp = compTemplate.duplicate();
var newLayer = newComp.layers.add(some_comp_with_markers);

if (newLayer instanceof AVLayer) {

newLayer.selected = true;
var command = app.findMenuCommandId("Update Markers From Source")
var result = app.executeCommand(command);
newLayer.selected = false;
}

 

 

For some reason calling executeCommand() doesn’t do anything.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 18, 2020 0
Contributor ,
Oct 18, 2020

Copy link to clipboard

Copied

Thank you. This is a very useful advice. I tried it and it works if I manually open the comp in AE and then run the script.

 

In my case, I’m creating a lot of comps dynamically and adding layers to them without doing anything manually in AE:

 

var newComp = compTemplate.duplicate();
var newLayer = newComp.layers.add(some_comp_with_markers);

if (newLayer instanceof AVLayer) {

newLayer.selected = true;
var command = app.findMenuCommandId("Update Markers From Source")
var result = app.executeCommand(command);
newLayer.selected = false;
}

 

 

For some reason calling executeCommand() doesn’t do anything.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 18, 2020 0
Community Beginner ,
Oct 18, 2020

Copy link to clipboard

Copied

Because of the way execute commands work you'll need

newLayer.openInViewer();

 near the beginning so the selected = true can work.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 18, 2020 1
Contributor ,
Oct 18, 2020

Copy link to clipboard

Copied

That's what I was missing. Thank you so much!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 18, 2020 0