Photoshop: Add dynamic string substitution to Generator for asset creation

  • 3
  • Idea
  • Updated 3 days ago
  • (Edited)
I use adobe generator ALL the time for my UI work, slicing up bits and pieces ready for use in all sorts of apps.
When making assets for any kind of application development, it is not uncommon to need to adhere to naming conventions, especially with regard to product specific work.

It would be AWESOME to have some kind of dynamic string substition to make the need to rename one's layers a quick and easy task, that also provides the added benefit of less opportunity for human error (due to a person not having to find lots of layers and rename each one specifically).

My suggestion would be to be able to provide a list of name value pairs on an empty layer, just like current practice with an empty Defaults layer.
For exmaple, one could define layer with a name like StringDefaults[MyId1:MyValue1, MyId2:MyValue2]
This could then be implemented on document layers in the following way:
%MyId1%_productDetail.jpg (which would generate MyValue1_productDetail.jpg)
%MyId1%_productShadow.jpg (which would generate MyValue1_productShadow.jpg)
%MyId1%_productFeatureIcon.jpg (which would generate MyValue1_productFeatureIcon.jpg)

A feature such as this would be a massive time and effort saving for designers that have to produce volumes of assets that have specific and consistent naming requirements.

My apologies if this exists and have missed it. I have looked around quite a lot to see if a feature such as this exists and couldn't find one.
Thanks for your time and consideration.
Photo of Michael Winner

Michael Winner

  • 10 Posts
  • 2 Reply Likes

Posted 1 week ago

  • 3
Photo of Max Johnson

Max Johnson, Champion

  • 488 Posts
  • 235 Reply Likes
All of this. Yes. I use the generator at work for promotional blocker dialogs that need to have different $$$ values baked into the same background for 10-20 different offers. This would help a lot!
Photo of Michael Winner

Michael Winner

  • 10 Posts
  • 2 Reply Likes
Here here! I have templates galore for all sorts of designs and UI and it astounding how much time is used renaming things.
Photo of Kukurykus

Kukurykus

  • 634 Posts
  • 149 Reply Likes
Scripting working together with assets would do it for you if you don't want wait for Adobe move...
(Edited)
Photo of Michael Winner

Michael Winner

  • 10 Posts
  • 2 Reply Likes
I'm intrigued! What do you mean? Like using a layer renaming script? If so, I admit, I had not thought of that! I'll take a look and see what I can find :).

UPDATE*
I am currently looking to see if I can make a script to do the job - will check when I have time to see if I can pull a copy of the generator repository and extend it for this use. Will post back with my results once I've had a go.
(Edited)
Photo of Kukurykus

Kukurykus

  • 634 Posts
  • 149 Reply Likes
Once I attempted to 'hack' generator for my prsonal use after I got disappointed Adobe doesn't fix bugs. I found the reason something works the way it does is not because generator could not be corrected but because Photoshop has some bugs that generator can not handle. Fortunately it is possible to adjust Assets code in some scope, so that one's wants but can't wait Adobe ever will do.

What programming language you used for the changes you made, have you ever scripted in inner Ps language. btw I got for email original post you made so I assume you tried to do it some external way not connected directly to Photoshop:

For reference, I had considered, finding / writing my own batch renaming app that I could provide with a list of name value pairs, which on execution, would then recurse through my output folder structures, find unique id's in filenames and replace them with the matched target value(s). However, I saw potential issues/complexities that I didn't fancy getting into the nitty-gritty of and even if I did successfully find / make one, it would still be additional steps to a potential workflow that would be a welcome degree smoother if generator had it built in.

I would LOVE any thoughts or input. I happily accept that I may very well be missing a trick :)
(Edited)
Photo of Michael Winner

Michael Winner

  • 10 Posts
  • 2 Reply Likes
I haven't made any changes yet. I am planning on looking into it more this afternoon. I found some posts and videos of people approaching the same thing. Looked like they were writing javascript. I have never made any script for Ps, but I've used to a few languages and was hoping it wasn't too big a mountain to climb.

I am still wondering the same, is there any point in trying to hack generator if the inherent bugs aren't fixed at source. Especially if I am forced to modify and upkeep with new releases and changes.
Photo of Kukurykus

Kukurykus

  • 634 Posts
  • 149 Reply Likes
I read generator code and found some commented parts. There was explained engineers couldn't do anyting more (like keeping original document resolution for exported layers other than default so 72 dpi) since Ps source code should be rewritten in first instance.

Fortunately the question of your original post seem to be doable. It needs to find appropriate part and change it, however because of too many connections with other parts of code it might affect something else that worked well.

In my opinion the best, fastest and easiest approach would be to leave that code as is but only make attachement to external javascript script targeting the sole problem, so while Ps is beeing launched it'd take to memory your own script by Assets code that now would be its regular part.


Ps. regarding your last concern I doubt Assets were updated from time of introduction as there are still same limitations, as to sole generator if I am not wrong it is dated few releases back as well.
(Edited)
Photo of Michael Winner

Michael Winner

  • 10 Posts
  • 2 Reply Likes
hmmmm. Thank you for the insight! Perhaps it could do it without changing the layer name.... just the value that gets written to the file, so the layer name never has to change, leaving other things completely untouched.

my plan of action would be:

1. check if I can override whatever function/handler triggers generator to start generating.
2. check if specific layer exists that would hold targeted name value pairs for save filename substitution
3. override function that saves each asset to check if the asset name requires string substitution and if so, create a string with specified ID in the asset name replaced with value from dictionary, and pass this value as the filename to be written.

This rests on many assumptions, like being able to pass the filename as a parameter lol! If that can't be done, due to something like, asset name to be written is passed in an a Ps core object that I can't extend without re-compiling Ps... I'm sure Adobe could just provide an alias param that can hold such a value which can be used in an update...

Just saying @Adobe... I'm sure this isn't THAT bad ;).
Photo of Max Johnson

Max Johnson, Champion

  • 488 Posts
  • 235 Reply Likes
FYI on layer naming, this is the quickest scripted solution. There's another with more options, but doesn't do numerical increments... and the link to the better one is down.
https://blog.darkwark.com/layerRenamer/
(Edited)
Photo of Michael Winner

Michael Winner

  • 10 Posts
  • 2 Reply Likes
Thanks a lot for this. I'm going to use this as a temporary measure. In my free time I have been taking a deep dive through the generator code. Will certainly post back in here if/when I've implemented and tested a solution :)