Pulling all mockups from a folder #21
-
Hello, I have quite a few mockups and am trying to figure out a way to pull all the mockups from a folder, instead of creating a new mockup object for each one. I tried using an array for the mockupPath, but that doesn't seem to work. It would be ideal if there was a way to point to a folder for the script to look for all the mockup files from within a folder, sort of like the input folder. When you have 60+ mockups, duplicating the objects gets pretty messy and time consuming. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Yea, this isn't an existing feature, but the settings script can be extended with javascript. I made you an example that should do it, or at least get you pretty far. Though I should say I didn't really test it thoroughly, and keep in mind it requires each mockup to have the same exact settings. Most importantly all mockup files need to have the same name for the smart object target layer name.
You can test it with the standalone example by replacing the settings file's contents with the following code:
#include "script/Batch Mockup Smart Object Replacement.jsx"
var output = {
path: './_output files', // Outputs next to the mockup psd
format: 'jpg', // 'jpg', 'png', 'tif', 'psd', 'pdf'
filename: '@mockup - @input',
folders: true,
};
// Later on after it's been filled with mockup settings this array is fed to the mockups() method
// that starts the mockup batch process...
var mockupsArray = [];
// This method returns the settings object for a single mockup and replaces the "mockupPath" with
// the input "path".
var addMockup = function( path ) {
var mockup = {
output: output,
mockupPath: path,
smartObjects: [
{
target: '@screen',
input: [
'./_input files'
],
inputNested: true,
align: 'center center',
resize: 'fill',
},
]
};
return mockup;
};
// Get path to current file
var pathToThisFile = scriptFolder();
// Append relative path to the mockups...
var mockupsFolder = new Folder( pathToThisFile + 'assets' );
// Get mockup files in the specified folder (psd or psb)
var mockupFiles = getFiles( mockupsFolder, { inputFormats: "psd|psb", inputNested: false });
// Goes through every found mockup file...
each( mockupFiles, function( mockupFile ) {
// Get text string of the full (absolute) path to the file
var pathToMockup = mockupFile.fullName;
// Create new mockup settings object using the path...
var newMockupSettings = addMockup( pathToMockup );
// Add new mockup settings to the array of mockups
mockupsArray.push( newMockupSettings );
});
// scriptFolder(), getFiles, and each() are methods that come from the #included engine script
// This mockups() method is the method that you would normally fill up with objects manuall.
// With this setup you can still add mockup settings manually by pushing to the "mockupsArray"
mockups( mockupsArray ); |
Beta Was this translation helpful? Give feedback.
-
It never occurred to me that it could be because of the file type. I thought perhaps I had one of the paths mistyped. |
Beta Was this translation helpful? Give feedback.
Yea, this isn't an existing feature, but the settings script can be extended with javascript. I made you an example that should do it, or at least get you pretty far. Though I should say I didn't really test it thoroughly, and keep in mind it requires each mockup to have the same exact settings. Most importantly all mockup files need to have the same name for the smart object target layer name.
You can test it with the standalone example by replacing the settings file's contents with the fol…