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

After Effects Script to create compositing and open it

New Here ,
Sep 18, 2024 Sep 18, 2024

Copy link to clipboard

Copied

Is a script that create a compositing with 3 layers, all works, but can't make to open the compositing


I tried different codes for internet app.project.activeItem and app.project.numItems and no one open a compositing

 

 

//*

````

function createCompositionWithShapes() {
    app.beginUndoGroup("Create Composition with Shapes");

    // Create a new composition
    var comp = app.project.items.addComp("ColorComp", 1920, 1080, 1, 10, 30);
    
    // Create shape layers
    var shapes = ["Red", "Green", "Blue"];
    var colors = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]; // RGB colors for Red, Green, Blue

    for (var i = 0; i < shapes.length; i++) {
        var shapeLayer = comp.layers.addShape();
        shapeLayer.name = shapes[i];

        // Create a shape group
        var shapeGroup = shapeLayer.property("Contents").addProperty("ADBE Vector Group");
        var shape = shapeGroup.property("Contents").addProperty("ADBE Vector Shape - Ellipse");
        shape.property("Size").setValue([200, 200]); // Set size of the shape

        // Create a fill for the shape
        var fill = shapeGroup.property("Contents").addProperty("ADBE Vector Graphic - Fill");
        fill.property("Color").setValue(colors[i]); // Set color for the fill

        // Position the shape layer
        shapeLayer.transform.position.setValue([comp.width / 2, comp.height / 2 + i * 150]);
    }

  

    app.endUndoGroup();
}

// Run the function to create the composition
createCompositionWithShapes();

  // Ensure the composition is visible in the viewer
    var viewerFound = false;
    for (var i = 0; i < app.project.viewers.length; i++) {
        var viewer = app.project.viewers[i];
        if (viewer && viewer.type === ViewerType.VIEWER_COMPOSITION) {
            viewer.setActive();
            viewerFound = true;
            break;
        }
    }

````

*//

 

 

TOPICS
Error or problem , Expressions , How to , Scripting , User interface or workspaces

Views

93

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

correct answers 1 Correct answer

Enthusiast , Sep 18, 2024 Sep 18, 2024

You can use openInViewer();

 

function createCompositionWithShapes() {
  app.beginUndoGroup("Create Composition with Shapes");

  // Create a new composition
  var comp = app.project.items.addComp("ColorComp", 1920, 1080, 1, 10, 30);
  // Open the comp
  comp.openInViewer();

  // Create shape layers
  var shapes = ["Red", "Green", "Blue"];
  var colors = [
    [1, 0, 0],
    [0, 1, 0],
    [0, 0, 1]
  ]; // RGB colors for Red, Green, Blue

  for (var i = 0; i < shapes.length; i++) {
    var shape
...

Votes

Translate

Translate
Enthusiast ,
Sep 18, 2024 Sep 18, 2024

Copy link to clipboard

Copied

You can use openInViewer();

 

function createCompositionWithShapes() {
  app.beginUndoGroup("Create Composition with Shapes");

  // Create a new composition
  var comp = app.project.items.addComp("ColorComp", 1920, 1080, 1, 10, 30);
  // Open the comp
  comp.openInViewer();

  // Create shape layers
  var shapes = ["Red", "Green", "Blue"];
  var colors = [
    [1, 0, 0],
    [0, 1, 0],
    [0, 0, 1]
  ]; // RGB colors for Red, Green, Blue

  for (var i = 0; i < shapes.length; i++) {
    var shapeLayer = comp.layers.addShape();
    shapeLayer.name = shapes[i];

    // Create a shape group
    var shapeGroup = shapeLayer.property("Contents").addProperty("ADBE Vector Group");
    var shape = shapeGroup.property("Contents").addProperty("ADBE Vector Shape - Ellipse");
    shape.property("Size").setValue([200, 200]); // Set size of the shape

    // Create a fill for the shape
    var fill = shapeGroup.property("Contents").addProperty("ADBE Vector Graphic - Fill");
    fill.property("Color").setValue(colors[i]); // Set color for the fill

    // Position the shape layer
    shapeLayer.transform.position.setValue([comp.width / 2, comp.height / 2 + i * 150]);
  }
  app.endUndoGroup();
}

// Run the function to create the composition
createCompositionWithShapes();

 

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
New Here ,
Sep 18, 2024 Sep 18, 2024

Copy link to clipboard

Copied

LATEST

sergio_1221_0-1726703172658.jpeg

It works, thanks a lot

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