Copy link to clipboard
Copied
I am trying to change stroke width of all path in a layer using java script.
I am trying to do as below
var layer = doc.layers;
for (var j=0; j<doc.layers.length; j++){
if ((layer
layer
layer
}
}
but this is not working, could any one help?
thanks
1 Correct answer
Hi,
The following snippet will change the stroke width of all pageItems inside the layer with layer name as "Layer 1". This will change stroke width for items inside the group and compound path as well
var doc = app.activeDocument;
var layerName = "Layer 1";
var _layer = app.activeDocument.layers.getByName(layerName);
app.executeMenuCommand("deselectall");
var _pageItems = doc.pageItems;
var allItems = [];
for (var i = 0; i < _pageItems.length; i++) {
if (_pageItems[i].layer == _layer) {
...
Explore related tutorials & articles
Copy link to clipboard
Copied
var targetLayer = app.activeDocument.layers.getByName('targetlayername');
var color1 = new RGBColor();
color1.red = 200;
color1.green = 0;
color1.blue = 255;
for (var i = 0; i < targetLayer.pageItems.length; i++) {
pathArt = targetLayer.pageItems[i];
pathArt.stroked = true;
pathArt.strokeWidth = 0.25;
pathArt.strokeColor = color1
}
Copy link to clipboard
Copied
Hi,
The following snippet will change the stroke width of all pageItems inside the layer with layer name as "Layer 1". This will change stroke width for items inside the group and compound path as well
var doc = app.activeDocument;
var layerName = "Layer 1";
var _layer = app.activeDocument.layers.getByName(layerName);
app.executeMenuCommand("deselectall");
var _pageItems = doc.pageItems;
var allItems = [];
for (var i = 0; i < _pageItems.length; i++) {
if (_pageItems[i].layer == _layer) {
allItems.push(_pageItems[i]);
}
}
for (var i = 0; i < allItems.length; i++) {
allItems[i].stroked = true;
allItems[i].strokeWidth = 0.25;
}
If you just want only pathItems, not any group or compound pathItems then you can use below version of the script.
var _layer = app.activeDocument.layers.getByName("Layer 1");
for (var i = 0; i < _layer.pathItems.length; i++) {
_layer.pathItems[i].stroked = true;
_layer.pathItems[i].strokeWidth = 0.25;
}

