Copy link to clipboard
Copied
Hi All,
I am developing an extension for CS5 and above (including CC version). I want to get the stroke color and size of a rectangle. I was able to do so in CS5. But, I noticed that in the CC version, there are two ways in which the user can apply a stroke. One is by applying effect in Layer Style, and the other is through the Properties panel. I am able to get the stroke values in my script if it is applied through Layer Style but I fail to do so in the other scenario.
How are these two strokes different and how can I get the stroke color and size if it is applied through Properties panel using script?
Thanks!
Here is what I have so far. It needs more work but I don't think it will ever be very accurate.
...function toggleOtherLayersVisibility() {
var desc = new ActionDescriptor();
var list = new ActionList();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
list.putReference( ref );
desc.putList( charIDToTypeID('null'), list );
desc.putBoolean( charIDToTypeID('TglO'), true );
execu
Copy link to clipboard
Copied
I want to get the stroke color and size of a rectangle.
The size should be easy as you can just evaluate the Vector Mask’s pathItem’s subPathItem’s pathPoints.
Can the rectangle be rotated (other than multiples of 90Ëš)?
The Shape Layer Stroke on the other hand … changing it creates Action Manager code, so I would expect that one should be able to evaluate the current settings, but so far I’ve drawn a blank.
Action Manager code is not comfortable for me, hopefully someone else can shed light on the issue.
Copy link to clipboard
Copied
Thanks guys for the reply,
I thought if Adobe added some new features, so there might be some API in scripting through which we can get the current value of properties panel. But I couldn't find anything there.
So I thought there might be some way we can do it using Action Manager code that's why I came here to take help from you guys.
But I guess I am out of luck here too.
Copy link to clipboard
Copied
How are these two strokes different and how can I get the stroke color and size if it is applied through Properties panel using script?
One is done with a layer style( or effect ) and the other is done with the new live shape feature.
I have looked at this several times. I have found a way to change the values in the properties panel but I have been unable to get the current values. I can not find them in either the layer or path descriptor.
Copy link to clipboard
Copied
I have found a way to change the values in the properties panel but I have been unable to get the current values.
Pity.
Do you think this indicates a trend that we will see more Scripting-inaccessible features in the future?
Copy link to clipboard
Copied
Do you think this indicates a trend that we will see more Scripting-inaccessible features in the future?
I do not think this is a new trend. There has always been things that could not be done via scripting. And there has always been things that could be 'set' but not 'get' with Action Manager. As an example in another recent post here I posted code that enabled/disabled channel and vector masks. I also posted how to 'get' the current enabled state of the channel mask. But I have not found a good way to do the same for vector masks.
Live shape is a new feature. It could be that scripting access to the current values in the properties panel will be added in the future. Especially if we ask for it in the request forum and the feature is expanded to work with other shapes. It is also possible that there is a way and we just have not found it yet.
Copy link to clipboard
Copied
Hi guys,
I need to get these stroke values, without this I am not able to move further.
If It is not possible with scripting, Is there any other way to do this?
Or may be there is any work around for getting the stroke values in scripting.
Need your help on this.
Thanks..
Copy link to clipboard
Copied
Sorry but I don't see a good way to do this.
You could get the layer's bounds and place a colorSampler at the edge of the bounds to get the color. But in my tests that only works if the stroke is at least one px and set to inside. If the stroke is set to outside you will get the fill color. If the stoke is smaller than one pixel you either get a mix of the stroke color and whatever is below that layer or an error if only that layer is visible. If the stoke is not a solid line the colorSampler may be at a position where the stroke is transparent. In other words when sampling the color at the edge you can not be sure the sampled color is really the stroke color used by the live shape.
I don't see a way to get the size of the stroke even using colorSamplers.
Copy link to clipboard
Copied
To more reliably get the color could one not duplicate the Layer, hide all others, set it to Fill 0%, rasterize it (or group and flatten the Group), use Layer > Layer Mask > From Transparency, delete the Layer Mask?
Copy link to clipboard
Copied
I tried something similar during my testing and it is slightly more reliable getting the color than trying to sample the live shape layer. I thought I got an inaccurate reading during my testing but I can not reproduce one now. So maybe the extra steps would be worthwhile. But I am still not sure a sampled color will always be the same as the color in the properties panel.
And the size of the stroke is still a problem with those extra steps.
Depending the on the OP needs that method may be good enough and better than nothing.
Copy link to clipboard
Copied
I suppose with Shape Layers one could determine a point on the path and its direction and then determine the width of the stroke by moving a Color Picker away from that at a 90˚ angle until it hits »empty« … but that would really be a quite convoluted approach.
And I don’t intend to attempt that but consider that more of an exercise at »theorizing«.
Copy link to clipboard
Copied
The problem I saw with using the colorSampler to determine the stroke width is it wasn't accurate. The determined width is rounded up to an integer and may or may not be one pixel too large. Even though it is a vector object the live stroke is shown using anti-aliasing and that effect the sampled size. For example the colorSampler would see a .5px stroke as 1px,1px as 2px, and 3px as 3px.
I also tried loading the shape layer transparency and intersecting that with a smaller selection that would only leave a small part of one edge selected to try to get the width from the selection but is has a similar anti-aliasing issue. It does seem to be slightly more accurate than using the color to determine the size.
Some times convoluted is the only approach that works but to me trying to get the stroke info is too convoluted and inaccurate to be useful.
Copy link to clipboard
Copied
I see you’ve been quite thorough in your approach.
Doesn’t look good for the OP’s request then, I guess.
Copy link to clipboard
Copied
Here is what I have so far. It needs more work but I don't think it will ever be very accurate.
function toggleOtherLayersVisibility() {
var desc = new ActionDescriptor();
var list = new ActionList();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
list.putReference( ref );
desc.putList( charIDToTypeID('null'), list );
desc.putBoolean( charIDToTypeID('TglO'), true );
executeAction( charIDToTypeID('Shw '), desc, DialogModes.NO );
};
function liveShapeFillEnabled( enable ) {// boolean
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( stringIDToTypeID('contentLayer'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
desc.putReference( charIDToTypeID('null'), ref );
var shapeDesc = new ActionDescriptor();
var styleDesc = new ActionDescriptor();
styleDesc.putInteger( stringIDToTypeID('strokeStyleVersion'), 2 );
styleDesc.putBoolean( stringIDToTypeID('fillEnabled'), enable );
shapeDesc.putObject( stringIDToTypeID('strokeStyle'), stringIDToTypeID('strokeStyle'), styleDesc );
desc.putObject( charIDToTypeID('T '), stringIDToTypeID('shapeStyle'), shapeDesc );
executeAction( charIDToTypeID('setd'), desc, DialogModes.NO );
};
function dupeVisibleMerged() {
var desc = new ActionDescriptor();
desc.putBoolean( charIDToTypeID('Dplc'), true );
executeAction( charIDToTypeID('MrgV'), desc, DialogModes.NO );
};
function loadTransparency(){
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putProperty( charIDToTypeID( "Chnl" ), charIDToTypeID( "fsel" ) );
desc.putReference( charIDToTypeID( "null" ), ref );
var ref1 = new ActionReference();
ref1.putEnumerated( charIDToTypeID( "Chnl" ), charIDToTypeID( "Chnl" ), charIDToTypeID( "Trsp" ) );
desc.putReference( charIDToTypeID( "T " ), ref1 );
executeAction( charIDToTypeID( "setd" ), desc, DialogModes.NO );
};
function getLiveShapeStrokeInfo(){
var doc = app.activeDocument;
var lyr = doc.activeLayer;
liveShapeFillEnabled( false );
toggleOtherLayersVisibility();
doc.artLayers.add();
dupeVisibleMerged();
var bounds = doc.activeLayer.bounds;
var horzCenter = (bounds[2]-bounds[0])/2;
var vertCenter = (bounds[3]-bounds[1])/2;
lyr.visible = false;
var sampler = doc.colorSamplers.add([bounds[0]+UnitValue(.5,'px'),bounds[1]+vertCenter]);
sizeObject.color = sampler.color;
loadTransparency();
doc.selection.select([
[bounds[0],bounds[1]+vertCenter],
[bounds[0]+horzCenter,bounds[1]+vertCenter],
[bounds[0]+horzCenter,bounds[1]+vertCenter+UnitValue(1,'px')],
[bounds[0]+UnitValue(1,'px'),bounds[1]+vertCenter+UnitValue(1,'px')]],SelectionType.INTERSECT);
sizeObject.size = doc.selection.bounds[2]-doc.selection.bounds[0];
};
var sizeObject = {};
app.activeDocument.suspendHistory('Get Live stroke info','getLiveShapeStrokeInfo()');
executeAction( charIDToTypeID('undo'), undefined, DialogModes.NO );
sizeObject.size;
Copy link to clipboard
Copied
Thanks a lot guys for ur help,
I think it is better to have something than nothing..
Is there also a possibility of getting its alignment, I mean what condition I have to write in the script to know that stroke is Inside, Outside or Center?
Copy link to clipboard
Copied
To be clear, I do not recommend you use the code I posted without more editing. In addition to being inaccurate it will fail if the layer is not a live shape layer or if there isn't a stroke. It may fail if the stroke is not solid and the sampled area is at an area where the stoke is transparent. And the color could be way off if the stroke is a gradient or pattern.
You could get the live shape layer bounds, turn off the stroke, and get the bounds again. If the two sets of bounds are the same you know the stroke is inside. If they are not the same you know it's either center or outside. But first I think you need to make sure there is a stroke.
Copy link to clipboard
Copied
The feature seems to be accessible in Photoshop CC.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now