Hi forum.
I am creating a CSS sprite consisting of 1000 tiny stickers - each with their own number. Rather than creating a layergroup with a sticker layer and a text layer (that holds the super imposed number) 1000 times, I would like to automate this process using JavaScript.
I have plenty of programming experience and some JavaScript experience. I hope you could give me a few pointers as to what objects in the DOM to look at and what methods I could be looking for.
In pseudocode I am imagining something like this:
Find newest/uppermost layergroup
Duplicate that group
Offset the duplicated layergroup by 20 pixels to the right
Modify the text layer in that group and increment its number by one
Repeat 1000 times
Any ideas as to what I should be looking for will be appreciated. Thanks.
Autonumbering some CSS sprite
-
Mike Hale
Autonumbering some CSS sprite
Something like this:
Code: Select allvar targetDoc = app.activeDocument;
for(var spriteGroupIndex = 0;spriteGroupIndex<1000;spriteGroupIndex++){
var targetLayerSet = targetDoc.layerSets[0];
var dupedSet = targetLayerSet.duplicate();
dupedSet.translate(new UnitValue(20,'px'), new UnitValue(0,'px'));
var textItem = dupedSet.artLayers[0].textItem;// assumes the text layer is the top layer in the set
textItem.contents = Number(textItem.contents)+1;
}
targetDoc.resizeCanvas(new UnitValue(20*(spriteGroupIndex+1),'px'), new UnitValue(20,'px'), AnchorPosition.MIDDLELEFT );
Code: Select allvar targetDoc = app.activeDocument;
for(var spriteGroupIndex = 0;spriteGroupIndex<1000;spriteGroupIndex++){
var targetLayerSet = targetDoc.layerSets[0];
var dupedSet = targetLayerSet.duplicate();
dupedSet.translate(new UnitValue(20,'px'), new UnitValue(0,'px'));
var textItem = dupedSet.artLayers[0].textItem;// assumes the text layer is the top layer in the set
textItem.contents = Number(textItem.contents)+1;
}
targetDoc.resizeCanvas(new UnitValue(20*(spriteGroupIndex+1),'px'), new UnitValue(20,'px'), AnchorPosition.MIDDLELEFT );
-
MadiZone
Autonumbering some CSS sprite
Hi Mike Hale
Thank you so much for your proposed solution and thanks for modelling it after my pseudo code, making it easy for me to understand. I've now tweaked it to do exactly what I wanted. Thanks again for helping me getting Photoshop to do my bidding and getting me a starting point at how to script Photoshop.
Thank you so much for your proposed solution and thanks for modelling it after my pseudo code, making it easy for me to understand. I've now tweaked it to do exactly what I wanted. Thanks again for helping me getting Photoshop to do my bidding and getting me a starting point at how to script Photoshop.