3 Replies Latest reply on Apr 21, 2015 11:00 AM by matias.kiviniemi

    How to access smartobjects within for-loop?

    michaelhelmrich Level 1

      Hi everybody,

       

      I am working on a script that that changes the color of all the layers in a psd-document called "Fill". This works fine. However, now I would like to expand the functionality and make it check through all my smart-objects and check whether they have any layers called "Fill". If yes, then change their color as well.

      So far I could only find script-listener code which doesn't work for me. It always gives the same error. It's in German, but roughly translates to "General Photoshop error. This functionality might not be available in this version of Photoshop..."

      I tested it in CS5 and the newest CC version, both with the same results.

       

      Are there any other ways?

       

      Here is the code I used:

       

      function openSmart(layerNode) {   

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

       

       

              openSmart(layerNode[i].layerSets);

       

       

              for(var layerIndex=0; layerIndex < layerNode[i].artLayers.length; layerIndex++) {

                  var layer=layerNode[i].artLayers[layerIndex];

                  if (layer.kind == LayerKind.SMARTOBJECT) {

                      layer.visible = 1;

                      var idAction = stringIDToTypeID( "placedLayerEditContents" );

                      var idDesc = new ActionDescriptor();

                      executeAction(idAction, idDesc, DialogModes.NO);

                  }

              }

          }

      }

       

       

      openSmart(app.activeDocument.layerSets);