Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
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 );
}
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
I wonder, why PS giving different values for same PSD ?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.