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

How to copy the shape layer contents to another shape layer by scripting

Explorer ,
Apr 26, 2022 Apr 26, 2022

Copy link to clipboard

Copied

I want to copy the shape layer contents to another shape layer by scripting.

 

I tried to this by using

app.executeCommand(19); // Copy
and
app.executeCommand(20); // Paste
 
but this way not work in some environments.
 
Please help me.
TOPICS
Scripting

Views

428

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
LEGEND ,
Apr 26, 2022 Apr 26, 2022

Copy link to clipboard

Copied

And what is the rest of the code around it? Of course none of this will do anything without checking whether a layer is correctly selected, what type it is, in which comp it is and so on. If that's all you have, this will never work.

 

Mylenium

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
Explorer ,
Apr 26, 2022 Apr 26, 2022

Copy link to clipboard

Copied

  function shapeMerge() {
    try {
      var comp = app.project.activeItem
      var selectedLayers = comp.selectedLayers;

      var contents = {};
      for (var i = 0; i < selectedLayers.length; i++) {
        var selectedLayer = selectedLayers[i];
        contents[selectedLayer.name] = []
        for (var j = 1; j <= selectedLayer.property("ADBE Root Vectors Group").numProperties; j++) {
          contents[selectedLayer.name][j] = selectedLayer.property("ADBE Root Vectors Group")(j);
        }
      }

      var newShapeLayer = comp.layers.addShape();

      for (var i = 0; i < Object.keys(contents).length; i++) {
        var shapeGroup = newShapeLayer.property('ADBE Root Vectors Group').addProperty('ADBE Vector Group')
        shapeGroup.name = Object.keys(contents)[i];

        for (var j = 1; j < contents[Object.keys(contents)[i]].length; j++) {
          deselectAll(comp);
          contents[Object.keys(contents)[i]][j].selected = true;
          app.executeCommand(19);

          deselectAll(comp);
          shapeGroup.selected = true;
          app.executeCommand(20);
        }
      }

      newShapeLayer.moveBefore(getTopLayer(selectedLayers));

      for (var i = 0; i < selectedLayers.length; i++) {
        var selectedLayer = selectedLayers[i];
        selectedLayer.enabled = false;
      }
    } catch (e) {
      alert(e)
    }
  }

  function deselectAll(theComp) {
    for (var i = 1; i <= theComp.numLayers; i++) {
      theComp.layer(i).selected = false;
    }
    var theProps = theComp.selectedProperties;
    for (var i = 0; i < theProps.length; i++) {
      theProps[i].selected = false;
    }
  }

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
LEGEND ,
Apr 26, 2022 Apr 26, 2022

Copy link to clipboard

Copied

Both your functions are in the same loop and will constantly interfere with each other by toggling the selection state. Why not simply create the new layer after the copy and then insert the content i a structured why into the default shape group?

 

Mylenium

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
Explorer ,
Apr 26, 2022 Apr 26, 2022

Copy link to clipboard

Copied

LATEST

it mean this?

      for (var i = 0; i < Object.keys(contents).length; i++) {
        for (var j = 1; j < contents[Object.keys(contents)[i]].length; j++) {
          deselectAll(comp);
          contents[Object.keys(contents)[i]][j].selected = true;
          app.executeCommand(19);
        }
      }

      var newShapeLayer = comp.layers.addShape();

      for (var i = 0; i < Object.keys(contents).length; i++) {
        var shapeGroup = newShapeLayer.property('ADBE Root Vectors Group').addProperty('ADBE Vector Group')
        shapeGroup.name = Object.keys(contents)[i];
        deselectAll(comp);
        shapeGroup.selected = true;
        app.executeCommand(20);
      }

 

this will paste only last one copied content

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