Copy link to clipboard
Copied
Good day everyone,
Im trying to have a script where It can;
- unlock all objects on "Design" layer
Then a separate script to;
- change stroke size and color of selected object
- then move it from "art" layer to "Design" layer.
Thank you in advance
The color needs to be named in your Swatch panel, and that name needs to be referenced in 'Color Swatch Name' this line:
var col = doc.swatches.itemByName("Color Swatch Name");
Also, I thought you wanted to change the object color, not stroke color. Fixed below:
var doc = app.activeDocument;
var al = doc.layers.itemByName("art");
var dl = doc.layers.itemByName("Design");
var col = doc.swatches.itemByName("Color Swatch Name");
var apis = al.allPageItems;
for (var i = 0; i < apis.length; i++)
...
Copy link to clipboard
Copied
#1
var dl = app.activeDocument.layers.itemByName("Design").allPageItems;
for (var i = 0; i < dl.length; i++) {
try { dl[i].locked = false; } catch(e) {}
}
#2
var doc = app.activeDocument;
var al = doc.layers.itemByName("art");
var dl = doc.layers.itemByName("Design");
var col = doc.swatches.itemByName("Color Swatch Name");
var apis = al.allPageItems;
for (var i = 0; i < apis.length; i++) {
try {
apis[i].fillColor = col;
apis[i].strokeWeight = "1 pt";
apis[i].itemLayer = dl;
} catch(e) {}
}
Copy link to clipboard
Copied
thank you so much @brianp311 , though im still getting this pop up error.
- how do i change the stroke color to a C0M0Y0K0 value (current object selected)
Copy link to clipboard
Copied
The color needs to be named in your Swatch panel, and that name needs to be referenced in 'Color Swatch Name' this line:
var col = doc.swatches.itemByName("Color Swatch Name");
Also, I thought you wanted to change the object color, not stroke color. Fixed below:
var doc = app.activeDocument;
var al = doc.layers.itemByName("art");
var dl = doc.layers.itemByName("Design");
var col = doc.swatches.itemByName("Color Swatch Name");
var apis = al.allPageItems;
for (var i = 0; i < apis.length; i++) {
try {
apis[i].strokeColor = col;
apis[i].strokeWeight = "1 pt";
apis[i].itemLayer = dl;
} catch(e) {}
}
Copy link to clipboard
Copied
thanks @brianp311 , what if I dont have a swatches and I want to set it up here on the script is that possible? or should I add a line to create a swatch then call it on the "var col" line?
Copy link to clipboard
Copied
also, how can i change the var apis = al.allPageItems; to current selected object?
thank you
Copy link to clipboard
Copied
Here you go.
var doc = app.activeDocument;
var al = doc.layers.itemByName("art");
var dl = doc.layers.itemByName("Design");
var col = doc.swatches.itemByName("myWhite");
if (!col.isValid) {
col = doc.colors.add({
colorValue: [0,0,0,0],
space: ColorSpace.CMYK,
name: "myWhite",
});
}
try {
var sel = app.selection[0];
sel.strokeColor = col;
sel.strokeWeight = "1 pt";
sel.itemLayer = dl;
} catch(e) { }
Copy link to clipboard
Copied
Thank you so much! This is prefect