joonaspaakko / Batch-Mockup-Smart-Object-Replacement-photoshop-script

Batch Mockup Smart Object Replacement - Photoshop script - A script that can batch process multiple mockup files and is able to replace multiple smart objects per mockup.
96 stars 23 forks source link

Help With Script Modifications #38

Closed UrNotKevin closed 1 month ago

UrNotKevin commented 1 month ago

The output is divided into the folders as per the different mockups but I wanted it to be like it should be divided into folders of input so if I put different designs and 4 mockup.psd so all the 4 mockups with same design should be in one folder and same fore other rather than 4 different designs of 1 mockup being in one

joonaspaakko commented 1 month ago

You should be able to do this by adding a folder path in the output.filename option:

var output = {
  path: './_output files',
  format: 'jpg',
- filename: '@mockup - @input',
+ filename: '@input/@mockup - @input',
};

It's a little janky since there is the output.path option, why not just have the @keywords there, but I faintly remember this was easier to implement or something.

If that fails (I haven't tested the option in forever, so who knows), you could probably output everything in the same folder prefixing everything with the mockup name so that files aren't overwritten and then use some batch renaming application (or script) to distribute them into folders based on the latter half of the filename. I used to use Better Finder Rename all the time for stuff like this.

UrNotKevin commented 1 month ago

Thank you for your response and it worked with the second line one @input/mockup

Also you have to make the folders option false so it will put all the mockups with same design in one folder

Thank you very much sir

Also a suggestion if you are still going to update this why don't you add a auto fit option.

Thank you

joonaspaakko commented 1 month ago

Also a suggestion if you are still going to update this why don't you add a auto fit option.

Given that the script only has automatic resizing using either fit or fill and a couple other forms of those, I don't think I understand?

Kinda recently someone wanted to set the size manually (#35), which kinda baffled me because their goal was to basically fit by ignoring the aspect ratio of the input files. I hope you don't want something like that. I still haven't fully recovered from that conversation. You should never squish or stretch an image! In situations like that you should always custom make every input file fit the aspect ratio of your smart object. It's more work but it looks good. If you don't want it to look good, just use fit or fill as is. Thinking about this gave me a headache again Lol.

UrNotKevin commented 1 month ago

Oh Yeah Found It fit or fill

yeah coding is pretty hard not making everything is easy LOL.

again thanks for the helps

UrNotKevin commented 1 month ago

Heyy Im Here Again Sorry To Disturb You Everytime But Coding Is Out Of My League

So The hidelayers, show layers

after one mockup is made i want to do it like i have 6 different tshirt colors so i want it to hide/show each layer after the first one is done

joonaspaakko commented 1 month ago

So you have multiple colors in different layers inside one mockup? There isn't a built in way to save each smart object as their own output file. As you might know, defining multiple smart objects per mockup is meant for situations where you have multiple visible smart objects, like that example with like a laptop and a smart phone. Show and hide layers are both mockup settings, so it's execured once per mockup, not once per smart object, so it won't help your situation as is.

What you could do is define a separate mockup object for each color:

  1. Save the mockup with all color layers hidden.
    • If you do this, it's easier to then just use show layers on one layer per mockup and not have to worry about hiding all the others.
  2. Define a separate mockup object (settings) for each color in your "settings script".
    • You could do this similar to how the output is defined as a variable, but since every mockup would need some unique settings, in this case the name for the shirt color at the very least, it would be better to make it a function: check the last code example here.
    • Defining a function would be the less cluttered way to do it, but you could also just copy & paste the mockup object as many times as needed and just change the "show layer" name for each. So like this, but just identical settings for each mockup, aside from the show layers setting. This would be easier since it's just a fancy text document and doesn't require any coding, but like I said, this would make it more cluttered and harder to read with like maybe ~25 lines of settings per color.
UrNotKevin commented 1 month ago

Hey That Worked Thank You But Is there anyway to replicate exact structure of the input folders and files in the output

ie if there are 2 folders with 1-1 folder in them and files inside them so the same structure to be made in output

this is my script

include "script/Batch Mockup Smart Object Replacement.jsx"

function addMockup(config) { var options = { output: { path: '$/example-3 (output)', // Base path for output format: config.format || 'png', // Output format filename: '@input/' + '@mockup/' + '@mockup ' + config.color , // Unique filename for each color }, showLayers: config.showLayers || [], // Layers to be shown mockupPath: '$/mockup/', // Path to mockup files mockupNested: false, // Whether mockups are nested or not smartObjects: [ { target: '@design', // Smart object target layer input: config.input || '$/input', // Input files path inputNested: true, // Whether to process input files in nested folders }, ] };

return options; }

// Create an array of mockup configurations with different colors var mockupConfigurations = [ addMockup({ color: 'Black', // Color for red mockup showLayers: ['1'], // Layers to be shown for red mockup input: ['$/input'], }), addMockup({ color: 'Charcoal Grey', // Color for red mockup showLayers: ['2'], // Layers to be shown for red mockup input: ['$/input'], }), addMockup({ color: 'Green', // Color for grey mockup showLayers: ['3'], // Layers to be shown for grey mockup input: ['$/input'], }), addMockup({ color: 'Grey', // Color for red mockup showLayers: ['4'], // Layers to be shown for red mockup input: ['$/input'], }), addMockup({ color: 'Lavender', // Color for grey mockup showLayers: ['5'], // Layers to be shown for grey mockup input: ['$/input'], }), addMockup({ color: 'White', // Color for red mockup showLayers: ['6'], // Layers to be shown for red mockup input: ['$/input'], }), ];

// Execute the mockups function with the configurations mockups(mockupConfigurations);

UrNotKevin commented 1 month ago

image this is my output now

and this is my input image

i want the output to be exactly like the input structure can you help please

joonaspaakko commented 1 month ago

I presume wanting the output path to be @input was a failed attempt at doing this, since @input is not the same as parent folder. Looking at your project folder, I think adding a folder using the input filename seems like a bad idea.

Honestly I'm not sure if it's worth the trouble, but you could perhaps do something like this:

Note: I don't have access to Photoshop so I couldn't test it.

#include "script/Batch Mockup Smart Object Replacement.jsx"

function addMockup(config) {
  var options = {
    output: {
      path: '$/output/' + config.output,
      format: config.format || 'png',
      filename: '@mockup-@input',
    },
    showLayers: config.showLayers || [],
    mockupPath: '$/mockup/',
    mockupNested: false,
    smartObjects: [{
      target: '@design',
      input: '$/input/' + config.input,
      inputNested: true,
    }, ]
  };

  return options;
}

// I noticed you set mockupPath as a folder, so this would be a good point to say it expects every single mockup to have 6 t-shirt (or equivalent) layers.
var layers = [1, 2, 3, 4, 5, 6];
var folders = ['Anime', 'Football', 'Retro'];

var mockupConfigurations = [];

// Generates mockups for every single folder and layer to be shown.
// Loop through all folder (name) → 1 new mockup per folder
each(folders, function(folderName) {
  // For each folder (name), loop through layers - 1 new mockup per layer
  each(layers, function(layer) {
    mockupConfigurations.push(
      addMockup({
        input: folderName, // Each folder is processed separately...
        output: folderName, // ...so output path can be the same as input path
        showLayers: [layer],
      })
    );
  });
});

mockups(mockupConfigurations);