set "fillColor" using a variable?
I'd like to assign a color to a selection based on the selection name (or any other variable). How do I do that? I tried defining a color and giving it the selection name but AI VSCode says "Object expected".
I'd like to assign a color to a selection based on the selection name (or any other variable). How do I do that? I tried defining a color and giving it the selection name but AI VSCode says "Object expected".
You need to assign a fillColor a color object, not a name. How you target your item depends on your needs.
To assign a selected item a color:
app.selection[0].fillColor = Bar;
A selection element won't accept a string identifier. So if you want to target a selected item by name, you will have to iterate through the selection collection and test for the name:
for (var i = 0; i < app.selection.length; i++) {
if (app.selection[i].name == "Something") {
app.selection[i].fillColor = Bar;
}
}
But in your case the above only applies if you are specifically selecting members of groups. The selection collection contains only top level items (i.e. only the group), so it won't contain members of groups. If you are targeting a member of a group by name, do you need it selected?
setCustomCrop()
function setCustomCrop() {
var aDoc = app.activeDocument;
var CropGroup = aDoc.groupItems['CropGroup'];
var myItems = CropGroup.pageItems;
var myMask = myItems["Something"];
myMask.fillColor = Bar;
// ...
}
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.