• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Running a script within an action

New Here ,
Jan 27, 2019 Jan 27, 2019

Copy link to clipboard

Copied

I'm trying to achieve a very specific, easy but time consuming task with Photoshop, but I'm very much a beginner to the action / scripting side of things, my only frame of reference is that it might be like Macros in Excel. Mainly I was hoping to run a couple of ideas past the forum, and some expert might be able to tell me if I'm barking up the wrong tree, or if I'm onto something.

I've got to put labels on jars of sweets using Photoshop. I've got 30-odd varieties of sweets, each with 3 different sized jars, and 40-odd labels.

What I've done so far is put all of my labels into a Smart Object. This allows me to warp the labels around my jar naturally. I've then put every iteration of the jars in my Photoshop document. I've made every iteration into a group, and within each group I've put a copy of the Smart Object label, perfectly placed over the jar.

I've found a bit of script that will then take every group, and save it as a jpg in a file of my choosing.

The time consuming bit is that every . time the script runs, I then have to go to the Smart Object, turn off the top layer, to reveal the next label, and then run the script again. That sounds like a quick process, but the file is so big now, that it takes about 10 minutes just to save the Smart Object, and update the 120-odd instances of the Smart Object, then it takes another 10 minutes for the script to save 90-odd jpgs. And I've got to do this for 41 labels, with 50-odd more coming each month.

I was hoping I might be able to create an action that goes into the smart object, finds the next visible layer and turns it off, copies the name of the layer, saves the Smart Object, runs the script, uses the copied name as a file extension, and then repeats until it's run out of visible rows. Then it can take as long as it wants, and I can leave it running overnight.

Does that sound possible? Is it there a more efficient way of achieving the same result?

Thanks in advance.

Views

8.9K

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 Expert ,
Feb 10, 2019 Feb 10, 2019

Copy link to clipboard

Copied

Well I create the setup structure for you so I coded the script to populate a collection of mockup in a folder. The script will run a very long time populating 41 labels into 84 templates that would create 3,444 populated mockup files.   It took my machine over 6 minuets to populate 41 labels into the three candy mockup templates I did for your setup.  84 mockup would be like three and a half hours.

The  BatchReplaceOneObject.jsx is redundant it can only replace the top layer stack smart object layers object

Next I wrote  BatchUpdateSmartObject.jsx It can replace  a collection of Smart Object Layers objects.  For each Smart Object layer there needs  to be object replacement folder that has the replacement images and the folder name must be obj(n) where n is the number sequence 0,1,2,3,...n  these relate to the top smart object layers in the layer stack, obj0 top layer, obj1 next layer down in the layer stack, etc. The first none smart object layer in the  mockup template layer stack marks the end of the layer to be updated.  So the script can populate your mockup.  The replacement labels would need  to be in folder   ...\Labels\obj0\   Lets say you wanted a mockup that show two labels on a jar. The front label and the back label you would add the back view of the jar and add a second indepentant smart object layer  for the collectionof back labels  your replacement collection would  be ...\Labels\obj0\ and ...\Labels\obj1\

next I wrote BatchMockupTemplates.jsx  which more less  populates the same replacement images into a collection of templates like yours  that would use your  Labels collection  ...\Labels\obj0\

Here are the scripts I did not include the required preference script I hope you have set that up for your environment. MockupScripts.zip

BatchMockupTemplates.jsx can do what BatchUpdateSmartObject.jsx does and BatchUpdateSmartObject.jsx can do what BatchReplaceOneObject.jsx does. So BatchMockupTemplates.jsx can do all.

JJMack

Votes

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
New Here ,
May 19, 2021 May 19, 2021

Copy link to clipboard

Copied

I not found MockupScripts.zip 😞 

Votes

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
Community Expert ,
Oct 20, 2023 Oct 20, 2023

Copy link to clipboard

Copied

LATEST
quote

I not found MockupScripts.zip 😞 


By @Nam5CCF

 

Sadly, JJMack has passed on.

 

You can find an archives of his scripts here:

 

https://github.com/MarshySwamp/JJMack-Archive

 

Votes

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
Community Expert ,
Jan 28, 2019 Jan 28, 2019

Copy link to clipboard

Copied

Sounds like multi-step workflow may be better than trying to do it all in one file.

1) Setup variants in spreadsheet

2) Create variables/data driven graphics in Photoshop, Illustrator or InDesign (data merge).

3) Save out flat labels for each variety and size etc.

4) Batch the placement of the flat labels onto the jar, warping and saving out final files

Votes

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
Community Expert ,
Feb 11, 2019 Feb 11, 2019

Copy link to clipboard

Copied

Today I added a timer to the script to time how long it runs.  I also recorder an Action to create Candy Jar Mockup from your layer group  player it 84 time to create your mockup templates and ran the script.  I walked way and came back some time later.  The script was displaying a Photoshop error it  had caught which pauses the script.   The message was user canceled. Since the script was into processing the mockup templates  at that stage all the the script does is replace Content and save as jpeg.  It was processing the 04LM Mockup template so I let the script continue  and look at the output.  It looks like it is a bug in Photoshop the Replace Content messed up and did  something very strange to the current document. The first 22 Replace content  worked and all the save jpeg worked al 3,444 mockup were save.  However in the 04LM while the first 22 are correct the last 19 are not.  While there is only one shared smart object label that is on both jars the last 19 mockup have different  labels on the jars  which should not be.  So CC 2019  must have so,e weird bug. The net result was there were 3,425 good output files and 19 bad output files. It too 2.7 hours but I doe not know how long the script was pause displaying the  error message.  Here is a Capture of CC 2019 Problem. I may try CS6.Capture.jpg

JJMack

Votes

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
Community Expert ,
Feb 12, 2019 Feb 12, 2019

Copy link to clipboard

Copied

Photoshop cc 2019 doing some strange things;  I redid all the templates and labels.  I had left the 41 label layer in the templates smart object. So I remove all but one and changed the one remaining label opacity to zero so it would not be visible in the templates.  I change all the label file format from png to psd for when I have edited png objects the save took a long time.  The smart object is your template was created in photoshop from a raster layer so when it is opened in Photoshop.  Photoshop creates a PSB work file for the object. So PSD in more in line with psb.  CS6 did not fail. CC 2019 fails consistently populating the 04LM mockup when batched with all 84 mockups but not in the same place.  It does not fail if I just populate the 04LM template or all the mockup before 0LM4 and 04LM.   When I saved PSD as well I notice the jpeg files have the wrong date. The PSD files have today's date the jpg yesterdays date.  In the 04LM Output PSD files, the last PSD with two alike labels is messed up though it looks correct it must have been where the replace content was canceled by the user. All the  04LM PSD file after the only have the small label updated.  If I try to update the last PSD with two identical labels the update of the object fails with a program error. If I try a second time there is no program error, however only the small jar label layer updates.  CC 2019 has some issues and the kind the will be very hard for Adobe to track down and fix.   

CC 2018 seems to hang if I leave the machine alone. When I come back and play with the mouse CC 2018 seem t0 get out of its funk and continues to populate templates.

I testing CC 2019 at this moment batching all 84 templates it has passed the 04LM template this time without the user canceled operation error I think it is going to be very hard for Adobe to track down.

JJMack

Votes

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
Community Expert ,
Feb 12, 2019 Feb 12, 2019

Copy link to clipboard

Copied

The fourth time CC 2019 ran without error. It took my machine around 1 and 1/2 hour to populate the 84 Templates with the 41 replacement labels. My machine is only 2 GHZ slow it has 40GB Ran and two 6core xeons.  Photoshop only seems to be single threaded only one processor thread was  pegged. The other 23 were mostly idle. I was saving ]both PSD and JPG files. so 6,888 files were saved.  For some unknown reason the net JPG file had the wrong data ant time. Where the PSD had the the correct run date and time.  Cs6, cc 2018 and CC 2019 all saved the jpg files with the wrong date and time. Instead of 2/15/2019  5pm the date was 2/11/2019 10pm on the jpg files.  When I open a template in cc 2019 use replace content and save as jpg manually the jpg is saved with the correct data time.01L.jpg

Any way here is a link Candy-Jars.zip It contain the scripts, jars, labels, and Templates. its 1.5GB I'll leave it up a few days then recover the 1.5GB on my server.

I see no problem in my Save JPG code

function SaveAsJPEG(saveFile, jpegQuality){

var doc = activeDocument;

if (doc.bitsPerChannel != BitsPerChannelType.EIGHT) doc.bitsPerChannel = BitsPerChannelType.EIGHT;

jpgSaveOptions = new JPEGSaveOptions();

jpgSaveOptions.embedColorProfile = true;

jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;

jpgSaveOptions.matte = MatteType.NONE;

jpgSaveOptions.quality = jpegQuality;

activeDocument.saveAs(File(saveFile+".jpg"), jpgSaveOptions, true,Extension.LOWERCASE);

}

function SaveAsPSD( inFileName, inEmbedICC ) {

var psdSaveOptions = new PhotoshopSaveOptions();

psdSaveOptions.embedColorProfile = inEmbedICC;

app.activeDocument.saveAs( File( inFileName + ".psd" ), psdSaveOptions );

}

JJMack

Votes

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
Community Expert ,
Feb 15, 2019 Feb 15, 2019

Copy link to clipboard

Copied

It turned out that jpeg files had the correct file modification date.  File explorer was displaying some other file date.  A file has many dates in its file information. File explorer can display.  Is the script working for you? The only problem I see on my system is that  Photoshop CC 2019 fails occasionally  replacing a smart object layers content.  That is an  Adobe Photoshop CC 2019 bug.  It take my slow 2Ghz machine 1.5hours to populate you 41  labels into your 84 templates.   I'll be removing the Candy-jar.zip from my web server soon. Its 1.5GB.

JJMack

Votes

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
New Here ,
Feb 22, 2021 Feb 22, 2021

Copy link to clipboard

Copied

Hello, 
I've downloaded your script "BatchUpdateSmartObject", after reading this whole thread, I've followed your guidelines for using this script.
I've created for PSDs, JPEGs, and outputs separated folders, and at the end, the script only shows me an alert.
You can see it in the attachments.

Hopefully, you or anyone in this community can help me with this one.
Thanks 🙂

Votes

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
Community Expert ,
May 11, 2021 May 11, 2021

Copy link to clipboard

Copied

image.png

You do not have exactly 200 support image files in each of the replacement collection folders for each of your smar object layers.  You need to correct your setup.

JJMack

Votes

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
Participant ,
Oct 20, 2023 Oct 20, 2023

Copy link to clipboard

Copied

Mockup image creation is a very simple thing to automate using the Batch Replace Smart Objects plugin for Photoshop. Basically, just select the Photoshop document to use (in this case, your mockup images of the jar which contains the Smart Object), the input folder of your images (in this case, your label designs), then the output folder to save the final images to.

 

However in your specific case, note that I don't think this plugin will work for complex .psd documents that have multiple Smart Objects that all need to be replaced. Like, if you have a Photoshop document with 2 or 3 jars, and you want all 3 of the jars updated simultaneously with the one artwork images or label design? I don't think this plugin will work. I've only used it for mockup images with one single Smart Object that needs to be replaced with images (such as apparel mockups featuring one hoodie, or wall art mockups featuring one art piece.)

 

If you're doing something super complex and customized like that, really I don't think there is ANY kind of pre-built template script or software that can do that for you. Something that highly customized will almost certainly require a separate, standalone .jsx script that's specifically built for the exact workflow and set of Photoshop documents you're using. There was another guy on these forums who posted a similar question inquiring about how to batch-generate mockups when the .psd documents contain 4 separate wall art mockups -- each needing to use 4 different artworks designs, grouped together in sequence but iterated through as groups of 4. Like if you're doing THAT level of complexity, the only answer is a custom script designed for that exact unique workflow.

 

If possible for what you're doing, it'd be way easier to simplify your workflow + stick to just one mockup at a time. That way, you could just use a Photoshop plugin or simpler .jsx script to automate it by iterating through all images in your input folder. Is it absolutely mission critical that you create product images featuring 3 jars instead of 1? Do you have any valid reason to believe that your conversion rate will substantially drop if the product photos feature just 1 jar instead of 3 side-by-side like that? Not trying to be a smartass, but honestly, you might be very needlessly overcomplicating things just to try to create a much more complex image when a much simpler image will be exactly as effective at driving conversions, satisfying the client, or doing whatever it is that you're trying to do. I would honestly ask yourself: "Would a simpler mockup automation workflow be exactly as effective for achieving my ultimate goals here? If so, why am I making things so much more complicated than they need to be?"

 

This more complex stuff -- I mean if you don't know how to write the .jsx scripts yourself, you'll probably have to hire a freelancer who specializes in Photoshop automation to do it for you. (You can find some on Upwork if needed -- just search Photoshop automation or Photoshop scripting or something like that.)

Votes

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