How to change stroke width of all paths for a selected layer using javascript

New Here ,
Nov 07, 2016 Nov 07, 2016

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.name == "layer 1") || (layer.name == "layer 2")){

        layer.pathItems.selected = true;

        layer.pathItems.strokeWeight = 0.25;

        }

    }

but this is not working, could any one help?

thanks

Views

183

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct Answer

Adobe Community Professional , May 03, 2021 May 03, 2021
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) { ...

Likes

Translate

Translate
Explorer ,
Apr 04, 2021 Apr 04, 2021

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
}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 03, 2021 May 03, 2021

Copy link to clipboard

Copied

LATEST

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;
}

 

 

 

Best regards

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines