• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Copying Illustrator masks to After Effects project layers using BridgeTalk

Engaged ,
Aug 07, 2022 Aug 07, 2022

Copy link to clipboard

Copied

Hi all.

 

Practice using the BridgeTalk class.

I want to transfer masks from Illustrator to After Effects layers, c
using the functions of this class.

Here is a description of the sequence of actions of the script.

 

              Export an Illustrator file to a PSD file.

              Opening a PSD file in After Effects.

              Copy the layers of the Illustrator file.

             Place the copied Illustrator file layer on the After Effects project layer.

 

Why is only one copied to all the layers in an After Effects file, the last layer mask from the Illustrator file?

----------------------------------------------------------------------------------------------------------------------------------

I wanted to attach a file Draw.ai, but the form does not let it through.

The file contains one layer, inside of which there are 5 layers.
Each of which contains one free-form pathItems.

-----------------------------------------------------------------------------------------------------------------------------------

 

function F_exportFileToPSD(string) {
    if (app.documents.length > 0) {
      var exportOptions = new ExportOptionsPhotoshop();
      exportOptions.resolution = 72;
      exportOptions.imageColorSpace.RGB;
      exportOptions.maximumEditability = true;
      exportOptions.writeLayers = true;
      var type = ExportType.PHOTOSHOP;
      var fileSpec = new File(string);
      app.activeDocument.exportFile(fileSpec, type, exportOptions);
    }
  }
//  Exporting an Illustrator file to a PSD file.
var fileName = app.activeDocument.name.split(".")[0];
var filePathName = filePath + "/" + fileName + "_PSD.psd"
F_exportFileToPSD(filePathName);


// Opening the PSD file in After Effects.
var ImpFileString = "var ImpFile = \"" + filePathName + "\";";

var bt = new BridgeTalk();
var specifier = "aftereffects";

if (!BridgeTalk.isRunning(specifier)) {
    BridgeTalk.launch(specifier);
}

var bt = new BridgeTalk();
bt.target = specifier;
var scp = "app.project.close(CloseOptions.DO_NOT_SAVE_CHANGES);";
scp += "ImpFileOpt = new ImportOptions();";
scp += ImpFileString;
scp += "ImpFileOpt.file = new File(ImpFile);";
scp += "ImpFileOpt.importAs = ImportAsType.COMP_CROPPED_LAYERS;";
scp += "app.project.importFile(ImpFileOpt);";
scp += "app.disableRendering =true;";
bt.body = scp;
bt.send();

for (i = 0; i < app.activeDocument.layers.length; i++) {
    var carentLayer = app.activeDocument.layers[i].name;
    var bt = new BridgeTalk();
    var specifier = "aftereffects";
    bt.target = specifier;
    var scp = 'function F_findeCompItemByName(Name) {\n';
    scp += '\tfor (f = 1; f <= app.project.numItems; f++) {;\n';
    scp += '\t\tif ((app.project.item(f).name == Name) && (app.project.item(f) instanceof CompItem)){\n';
    scp += '\t\t\treturn app.project.item(f);\n';
    scp += '\t\t}\n';
    scp += '\t}\n';
    scp += '}\n';
    scp += 'carentComp = F_findeCompItemByName("' + carentLayer + '");\n';
    scp += 'carentComp.openInViewer();\n';
    bt.body = scp;
    bt.send();
    for (var j = 1; j <= app.activeDocument.layers[i].layers.length; j++) {
        var Ill_layer = j - 1;
        app.redraw();
        app.activeDocument.layers[i].layers[Ill_layer].hasSelectedArtwork = true;
        app.copy(); // Copy layer of an Illustrator file.
        app.redraw();
        var bt = new BridgeTalk();
        var specifier = "aftereffects";
        bt.target = specifier;
        // Place the copied Illustrator file layer into the After Effects project layer.
        scp = 'carentComp.layer(' + j + ').selected = true;\n';
        scp += 'app.executeCommand(20);\n';
        scp += 'carentComp.layer('+ j + ').selected = false;\n';
        bt.body = scp;
        bt.send();
        app.activeDocument.layers[i].layers[Ill_layer].hasSelectedArtwork = false;
    }
        var bt = new BridgeTalk();
        var specifier = "aftereffects";
        bt.target = specifier;
        var scp = "app.disableRendering = false;";
        bt.body = scp;
        bt.send();
}
TOPICS
Scripting

Views

223

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
community guidelines
Adobe
Valorous Hero ,
Aug 08, 2022 Aug 08, 2022

Copy link to clipboard

Copied

The problem is likely that the loop is too fast to copy items, or something - my suggestion is to use BridgeTalk's onResult method where another method can be used to do the operation. This way it should wait until the BT process is done with the entire copy/paste operation.

 

Votes

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
community guidelines
Engaged ,
Aug 16, 2022 Aug 16, 2022

Copy link to clipboard

Copied

LATEST

I attached to what I wrote last time, the function..

------------------------------------------------------------------------

 for (var j = 0j < app.activeDocument.layers[i].layers.lengthj++) {
        app.activeDocument.layers[i].layers[j].hasSelectedArtwork = true;
        app.copy();
        infoFromAE(j);
        app.activeDocument.layers[i].layers[j].hasSelectedArtwork = false;
    }
}

function infoFromAE(j) {
    var stringJ = j + 1;
    var bt = new BridgeTalk();
    var specifier = "aftereffects";
    bt.target = specifier;
    scp = 'carentComp.layer(' + stringJ + ').selected = true;\n';
    scp += 'carentComp.layer(' + stringJ + ').selected = true;\n';
    scp += 'app.executeCommand(20);\n';
    scp += 'var f = carentComp.layer(' + stringJ + ').mask.numProperties;\n';
    scp += 'carentComp.layer('stringJ + ').selected = false;\n';
    scp += 'f.toSource();';
    bt.body = scp;
    bt.onResult = function(msg) {
        var myResult = msg.body;
        doSomethingNow(myResult);
    }
    bt.send();
}

doSomethingNowfunction(result) {
    alert(result);
}

------------------------------------------------------------------------.

 

I have a question about the behavior of the "bt.onResult" method, and in general, about the results obtained.

 

When you run this script, there are processes that are not clear to me. On the one hand, for all sublayers of the layer, in the AE project, the same mask from the layer of the AI document is added.
On the other hand, after working out the scipt, I see such a chain of events. I'm running a script from AI, where I should receive messages from the "bt.onResult" method. The application freezes. The AE application logo flashes at the bottom of the screen. I switch to the AE application, there really appear sublayers, with the same mask. Then I switch to AI, I get a bunch of number messages " var f = carentComp.layer(' + stringJ + ').mask.numProperties; " and I press the Enter key dozens of times, .... confirming the received message, about number of vertices of the copied mask.....

 

it seems that the "bt.onResult" method works, but it works somehow crookedly, or I don't understand something .....

 

One more question.

 

I work with applications through Microsoft VS Code. Can I pause the execution of the script on the AI side, and during this pause, look at the data on the AE side?

On the third hand, you can also pass an array of data about the vertices of the mask...

------------------------------------------------------------------------------------------

 CarentPathPointArray.push(ActivePathItem.pathPoints[i].anchor);
CarentPathPointArray.push(ActivePathItem.pathPoints[i].leftDirection);
CarentPathPointArray.push(ActivePathItem.pathPoints[i].rightDirection);
CarentPathPointArray.push(ActivePathItem.pathPoints[i].pointType);;

----------------------------------------------------------------------------------------------

Advise, as in my case it is correct, to use the clipboard with the app.copy command, or to pass an array of vertex parameters? In my opinion, both methods are equivalent.

Votes

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
community guidelines