Skip to main content
Known Participant
June 29, 2020
Answered

How to add transition by script

  • June 29, 2020
  • 1 reply
  • 476 views

Hello guys,

 

Please help me.

 

I try create an action to add transition but can't work. Is it possible with scripts?

 

I want add "Cross Fade" with duration 4s to all layer in Video group.

 

I appreciate any help.

 

Thank you so much!

This topic has been closed for replies.
Correct answer jazz-y

* before starting the script, at least one layer in the desired video group must be selected

 

#target photoshop

var s2t = stringIDToTypeID,
    p = app.activeDocument.activeLayer.parent,
    len = p.layers.length - 1

for (var i = len; i > 0; i--) {
    selectLayers([p.layers[i].id, p.layers[i - 1].id])
    addTimelineTransition(4)
}

function selectLayers(IDList) {
    var r = new ActionReference();
    for (var i = 0; i < IDList.length; i++) { r.putIdentifier(s2t("layer"), IDList[i]) }
    (d = new ActionDescriptor()).putReference(s2t("null"), r);
    executeAction(s2t("select"), d, DialogModes.NO)
}

function addTimelineTransition(seconds) {
    (d = new ActionDescriptor()).putObject(s2t("using"), s2t("crossDissolveTransition"), new ActionDescriptor());
    (d1 = new ActionDescriptor()).putInteger(s2t("seconds"), seconds);
    d.putObject(s2t("duration"), s2t("timecode"), d1);
    d.putEnumerated(s2t("placement"), s2t("transitionPlacement"), s2t("join"));
    executeAction(s2t("addTimelineTransition"), d, DialogModes.NO);
}

 

 

1 reply

jazz-yCorrect answer
Brainiac
June 29, 2020

* before starting the script, at least one layer in the desired video group must be selected

 

#target photoshop

var s2t = stringIDToTypeID,
    p = app.activeDocument.activeLayer.parent,
    len = p.layers.length - 1

for (var i = len; i > 0; i--) {
    selectLayers([p.layers[i].id, p.layers[i - 1].id])
    addTimelineTransition(4)
}

function selectLayers(IDList) {
    var r = new ActionReference();
    for (var i = 0; i < IDList.length; i++) { r.putIdentifier(s2t("layer"), IDList[i]) }
    (d = new ActionDescriptor()).putReference(s2t("null"), r);
    executeAction(s2t("select"), d, DialogModes.NO)
}

function addTimelineTransition(seconds) {
    (d = new ActionDescriptor()).putObject(s2t("using"), s2t("crossDissolveTransition"), new ActionDescriptor());
    (d1 = new ActionDescriptor()).putInteger(s2t("seconds"), seconds);
    d.putObject(s2t("duration"), s2t("timecode"), d1);
    d.putEnumerated(s2t("placement"), s2t("transitionPlacement"), s2t("join"));
    executeAction(s2t("addTimelineTransition"), d, DialogModes.NO);
}

 

 

ANCHINGOAuthor
Known Participant
June 30, 2020

That's great! Thank you so much! Have a nice day!