7 Replies Latest reply on Mar 23, 2015 8:44 PM by tharea

    Vector Layer rasterization

    tharea Level 1

      Hello,

       

      I am trying to "rasterize vector layer mask" by a script.

      For this, I need to identify current layer is vector layer or not.

       

      I need to do rasterize operation, if layer is a vector layer only.

      How do I directly get this?

       

      Thanks

        • 1. Re: Vector Layer rasterization
          nvkzNemo Level 2

          Try this. If I understand you correctly.


          var lyr = app.activeDocument.activeLayer;
          
          if (lyr.kind == 'LayerKind.SOLIDFILL') {
            lyr.rasterize(RasterizeType.SHAPE);
          }
          
          

           

          or just

           

          app.activeDocument.activeLayer.rasterize(RasterizeType.SHAPE);
          
          • 2. Re: Vector Layer rasterization
            Philip Cord Level 4

            A solidfill layer is not forced to be a shape layer and can fail, you can check if it has a vector mask before raster.

             

            var ref = new ActionReference();
            ref.putEnumerated( charIDToTypeID('Lyr '),charIDToTypeID('Ordn'),charIDToTypeID('Trgt') );
            var desc = executeActionGet(ref);
            if(desc.hasKey (stringIDToTypeID( 'hasVectorMask'))){
            if(desc.getBoolean(stringIDToTypeID( 'hasVectorMask')) == true) {
                activeDocument.activeLayer.rasterize(RasterizeType.SHAPE );
                }
            }
            
            • 3. Re: Vector Layer rasterization
              xbytor2 Level 4

              If you add

                 ref.putProperty ( charIDToTypeID('Prpr'), stringIDToTypeID( 'hasVectorMask') );

               

              immediately after creating ref, it will retrieve just the desired property instead of the all of the properties of the layer, which is far more efficient.

              • 4. Re: Vector Layer rasterization
                matias.kiviniemi Level 3

                If you want to rasterize everything in the layer (e.g. shape, smart objects, styles, smart filters), simplest way is to create an empty layer below and merge to it.

                • 5. Re: Vector Layer rasterization
                  tharea Level 1

                  Hello,

                   

                  Thanks for your kindly reply.

                  If I am correct, a layer will be a vector layer if we specify a "vector mask".

                  We rather consider a "layer mask" if we do pixel based operation such as paint brush.

                   

                  I tested both layer.kind and key "hasVectorMask".

                  But I feel like return values are inconsistent among different versions of PS.


                  Even rectangle shape layers are identified as a NORMAL by layer kind.

                  Key "hasVectorMask" seems ok but it is returning 0 in PS 5.1 and PS 6 for rectangle shape layers.


                  I created TC with rectangle shape layers. Please see below test case and its results of specific layers.

                  BUGLayerMask cc.psd - Google Drive

                  Capture.PNG

                  I wonder, why PS giving different values for same PSD ?

                  • 6. Re: Vector Layer rasterization
                    matias.kiviniemi Level 3

                    One has to remember that there's quite a few years between PS5.1 and CC (2012) that is still getting updates so it's inherent that there will be differences that you will need to handle. Probably when they discovered the issue, CS5 no longer got updates. And Adobe is maybe a bit erratic here, I've been fighting with paragraph text bounding box extents that has very different behaviour in Win/Mac CS6/CC2012/CC2014 that also changes every so often in updates.

                     

                    My other point was that a layer can lots of things that can be rasterized and just calling .rasterize() will not get rid of all of them. So unless you need tight control (e.g. "rasterize shape, keep layer style") merging to an empty layer is the easiest way to get rid of all non-raster content.

                    • 7. Re: Vector Layer rasterization
                      tharea Level 1
                      I've been fighting with paragraph text bounding box extents that has very different behaviour in Win/Mac CS6/CC2012/CC2014 that also changes every so often in updates.

                      Please take a PSD which gives you different behavior on bounding box extents.

                      I think first rasterize those layers can avoid your issue with different versions.