7 Replies Latest reply on Sep 18, 2015 12:01 AM by c.pfaffenbichler

    how to get fillcolor of  multiple pathItems?

    xizhilangx32372448

      var paths = app.activeDocument.pathItems;

      for (var a = 0; a < paths.length; a++) {

      path[a].fillcolor // ti is undefined

      }

       

      who can tell me how to get fillcolor of multiple pathItems?

       

      jelly

      thx.

        • 2. Re: how to get fillcolor of  multiple pathItems?
          Chuck Uebele Adobe Community Professional & MVP

          Moving to Photoshop Scripting forum.

          • 3. Re: how to get fillcolor of  multiple pathItems?
            c.pfaffenbichler Level 9

            By the way: pathItems have no fill color per se, do you mean Shape Layers?

            • 4. Re: how to get fillcolor of  multiple pathItems?
              xizhilangx32372448 Level 1

              yeah,pathItems  is object of shapeLayers.

              • 5. Re: how to get fillcolor of  multiple pathItems?
                c.pfaffenbichler Level 9

                Quote from the Object Model Viewer:

                PathItems

                Adobe Photoshop CC 2014 Object Library

                The collection of path item objects in the document.

                • 6. Re: how to get fillcolor of  multiple pathItems?
                  nvkzNemo Level 2

                  You can use

                   

                  function setFillColor(clr) {
                      var desc1 = new ActionDescriptor(),
                          desc2 = new ActionDescriptor(),
                          desc3 = new ActionDescriptor(),
                          ref1 = new ActionReference();
                      ref1.putEnumerated(stringIDToTypeID("contentLayer"), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));
                      desc1.putReference(charIDToTypeID('null'), ref1);
                      desc3.putDouble(charIDToTypeID('Rd  '), clr[0]);
                      desc3.putDouble(charIDToTypeID('Grn '), clr[1]);
                      desc3.putDouble(charIDToTypeID('Bl  '), clr[2]);
                      desc2.putObject(charIDToTypeID('Clr '), stringIDToTypeID("RGBColor"), desc3);
                      desc1.putObject(charIDToTypeID('T   '), stringIDToTypeID("solidColorLayer"), desc2);
                      executeAction(charIDToTypeID('setd'), desc1, DialogModes.NO);
                  }
                  
                  
                  
                  
                  

                   

                  and

                   

                  function getFillColor() {
                      var ref = new ActionReference();
                      ref.putEnumerated(stringIDToTypeID("contentLayer"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
                      var color = executeActionGet(ref).getList(charIDToTypeID("Adjs")).getObjectValue(0).getObjectValue(charIDToTypeID('Clr '));
                      return [color.getDouble(charIDToTypeID('Rd  ')), color.getDouble(charIDToTypeID('Grn ')), color.getDouble(charIDToTypeID('Bl  '))];
                  }
                  

                   

                  For example: Set color for All Layers (with folders and subfolders)

                   

                  var doc = app.activeDocument,
                      allLayers = new Array();
                  
                  
                  collectAllShapeLayers(doc, 0);
                  
                  
                  for (var i = 0; i < allLayers.length; i++) {
                      doc.activeLayer = allLayers[i];
                      setFillColor([0, 30, 255]);
                  }
                  
                  
                  function setFillColor(clr) {
                      var desc1 = new ActionDescriptor(),
                          desc2 = new ActionDescriptor(),
                          desc3 = new ActionDescriptor(),
                          ref1 = new ActionReference();
                      ref1.putEnumerated(stringIDToTypeID("contentLayer"), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));
                      desc1.putReference(charIDToTypeID('null'), ref1);
                      desc3.putDouble(charIDToTypeID('Rd  '), clr[0]);
                      desc3.putDouble(charIDToTypeID('Grn '), clr[1]);
                      desc3.putDouble(charIDToTypeID('Bl  '), clr[2]);
                      desc2.putObject(charIDToTypeID('Clr '), stringIDToTypeID("RGBColor"), desc3);
                      desc1.putObject(charIDToTypeID('T   '), stringIDToTypeID("solidColorLayer"), desc2);
                      executeAction(charIDToTypeID('setd'), desc1, DialogModes.NO);
                  }
                  
                  
                  function collectAllShapeLayers(theParent, level) {
                      for (var m = theParent.layers.length - 1; m >= 0; m--) {
                          var theLayer = theParent.layers[m];
                          if (theLayer.kind == "LayerKind.SOLIDFILL") {
                              allLayers.push(theLayer);
                          }
                          if (theLayer.typename != "ArtLayer") {
                              collectAllLayers(theLayer, level + 1)
                          }
                      }
                  }
                  
                  
                  
                  • 7. Re: how to get fillcolor of  multiple pathItems?
                    c.pfaffenbichler Level 9

                    Once again: Your terminology is off, pathItems are not identical to Shape Layers.

                    Anyway, you could try this:

                    // get rgb values for solid color layers with vector masks aka shape layers;
                    // 2015, use it at your own risk;
                    #target photoshop
                    if (app.documents.length > 0) {
                    main ();
                    };
                    ////////////////////////////////////
                    function main () {
                    // the file;
                    var myDocument = app.activeDocument;
                    // get number of layers;
                    var ref = new ActionReference();
                    ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
                    var applicationDesc = executeActionGet(ref);
                    var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));
                    // process the layers;
                    var theLayers = new Array;
                    for (var m = 0; m <= theNumber; m++) {
                    try {
                    var ref = new ActionReference();
                    ref.putIndex( charIDToTypeID( "Lyr " ), m);
                    var layerDesc = executeActionGet(ref);
                    ////////////////////////////////////
                    // collect values for solid color layers with vector masks;
                    if (layerDesc.hasKey(stringIDToTypeID('adjustment')) == true && layerDesc.getBoolean(stringIDToTypeID('hasVectorMask')) == true) {
                    var adjList = layerDesc.getList(stringIDToTypeID('adjustment'));
                    var theColors = adjList.getObjectValue(0).getObjectValue(stringIDToTypeID('color'));
                    var str = '';
                    for(var i=0;i<theColors.count;i++){
                    str = str + 'Key '+i+' = '+typeIDToStringID(theColors.getKey(i))+': '+theColors.getUnitDoubleValue(theColors.getKey(i))+'\n';
                    };
                    var theName = layerDesc.getString(stringIDToTypeID('name'));
                    var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
                    theLayers.push(["the layer »" +theName+"« has the layerID "+theID+" and the colors\n" +str])
                    };
                    }
                    catch (e) {};
                    };
                    alert (theLayers.join("\n"));
                    };