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.
97 stars 23 forks source link

Doesn't work with Windows and Photoshop 2022/2023 #30

Closed evolucja closed 8 months ago

evolucja commented 11 months ago

Hi, it looks like a ton of a great work and I'd love to use it.

However I downloaded the standalone example, cleared the output folded and executed the script in Photoshop. It just opened the "example-mockup.psd" and did nothing more. No errors, messages, no output.

Any idea if it was tested under Windows and Photoshop 2022/2023?

What can I check?

Best regards Dave

@EDIT Looks to be the same on CC 2019..

evolucja commented 11 months ago

After some debugging I made it working but not sure how it should be properly fixed.

I changed relative paths to absolute: image

And commented out:

  // Input folder path
  // if ( data.doc.input && typeof data.doc.input === 'string' ) data.doc.input = [ data.doc.input ];
  // each( data.doc.input, function( item, index ) {
  //   data.doc.input[ index ] = absolutelyRelativePath( data.doc.input[index] ).decoded;
  // });

because the script was failing at this moment (something undefined).

So I'm pretty sure it's something about Windows paths..

joonaspaakko commented 11 months ago

@evolucja, I didn't have time to even attempt a fix, but I took a look at it and sure enough it failed to run Windows. That said I tested it on PS CS6, just because I didn't have immediate access to CC. I have a feeling it could be the same issue even though I got an error dialog.

I found out that the previous version of the script worked just fine. I was wondering if you could try Standalone example - Version 1.8 (direct download link).

panagakis commented 11 months ago

@joonaspaakko I tried but 1.8 stopped right after 3-4 saves of my files. I used @evolucja method which works perfectly with the latest version and i also added the webp file in the input formats and everything worked perfectly fine with the same images i tried in 1.8.

joonaspaakko commented 11 months ago

1.8 stopped right after 3-4 saves of my files. — I also added the webp file in the input formats

If it saves any files, I would think it's not about the inability to figure out the path, since it should be done the same way for each file. Are you sure it didn't just ignore your WebP files on the first run before you added it into the input formats? I think another possibility could be that your input path(s) were partially invalid. A lot of people have had a hard time with relative paths. Maybe those 3-4 files were in one of the input folders and another input path didn't lead anywhere.

I've so far had 2 people (and also me) confirm 1.8 works in Windows, so that's why I'm a bit skeptical when you say it didn't work. Unfortunately, OP hasn't commented on it so we don't have a fifth opinion.

nfourteen commented 9 months ago

@joonaspaakko Th issue here I found was the error undefined is not an object being thrown when the settings config didn't contain an input property at the doc level (to override the smartObjects[].input property). The undefined value is assigned here: https://github.com/joonaspaakko/Batch-Mockup-Smart-Object-Replacement-photoshop-script/blob/master/script/Batch%20Mockup%20Smart%20Object%20Replacement.jsx#L450

I fixed it by adding || [] to the loop at L456 to:

  each( data.doc.input || [], function( item, index ) {
    data.doc.input[ index ] = absolutelyRelativePath( data.doc.input[index] ).decoded;
  });

That fixes the error. But now it's not processing correctly. I think this has something to do with my settings config and data structure. The first for loop conditional is true here: https://github.com/joonaspaakko/Batch-Mockup-Smart-Object-Replacement-photoshop-script/blob/master/script/Batch%20Mockup%20Smart%20Object%20Replacement.jsx#L226, so the loop is never entered and smart objects are never swapped. Not sure what's going on here, but working on that now.

Something is failing here: https://github.com/joonaspaakko/Batch-Mockup-Smart-Object-Replacement-photoshop-script/blob/master/script/Batch%20Mockup%20Smart%20Object%20Replacement.jsx#L360 when a single input file is used. The call to getFiles() when typeof input === string is executed here: https://github.com/joonaspaakko/Batch-Mockup-Smart-Object-Replacement-photoshop-script/blob/master/script/Batch%20Mockup%20Smart%20Object%20Replacement.jsx#L207, but that doesn't return any files for me.

joonaspaakko commented 9 months ago

@nfourteen, all I can say for now (on mobile) is that if data.doc.input doesn't return anything, the issue is somewhere deeper. It should always find a mockup unless the settings script is somehow pointing into the wrong place. I would use any of the examples to debug this because they use relative paths that are known to work. Hint: The issue should be somewhere in the diff between v.1.8 and v.1.9.

nfourteen commented 9 months ago

@joonaspaakko Yup, I just figured out the input property at the smart object level was pointing to a file and not a folder. I also believe that the input property can't point to the directory the settings config file is in (that also didn't work)? But with some adjustments (moving the input file down a directory and pointing input to said directory), the v1.9 is up and running for me.

I did have to leave the fix in place. The data.doc.input remained undefined at the mockup level as the settings file didn't define it. To reproduce:

mockups([
  {
    input: '',   // leave this property out of settings config
    smartObjects: [
      {
        target: '@so',
        input: './image',
        inputNested: false,
      },
    ]
  },
]);

Then when replaceLoopOptionsFiller executes, the script ends up running:

...

  if ( rawData.inputNested ) data.doc.inputNested = rawData.inputNested;
  data.doc.input  = rawData.input; // this is undefined currently
  data.doc.inputFormats = rawData.inputFormats;
  data.doc.inputIndex = 0;

  // Input folder path
  if ( data.doc.input && typeof data.doc.input === 'string' ) data.doc.input = [ data.doc.input ];
  each( data.doc.input, function( item, index ) { // each tries to iterate over "undefined"
    data.doc.input[ index ] = absolutelyRelativePath( data.doc.input[index] ).decoded;
  });

...

If you're ok with the || [] fix, I can submit a PR. But I'm still new to this script and don't want to cover up any deeper issues...

joonaspaakko commented 9 months ago

I feel a bit bad that I'm giving you these half passed tips (and or comments), but the mockup path is defined by a slightly inconsistent mockupPath rather than input, so it shouldn't work at all unless you changed its "name".

nfourteen commented 9 months ago

@joonaspaakko Well, that's my fault. I should've left a little more config in the example...went for too much brevity. The mockupPath should be defined within the script to reproduce. I've underlined the property that's causing issues from a screen shot of the docs and attached it here.

Screenshot 2024-02-02 at 1 19 36 PM
joonaspaakko commented 9 months ago

Gotcha. If you make a pull request I can take a look at it. I'll try to do that this weekend.

I still haven't quite read everything thoroughly so I'm not a 100% if you posted all of the code you changed. If you did, it wasn't a big change, I can easily test that too, if you'd prefer not making a pull request.

schroef commented 9 months ago

Seems like the script stop because it's missing props or attributes in the Jax file which has the paths. Seem the if data.doc.inoit should be wrapped in a try/catch

I've tried debugging where it stops and it's at the part where it's checking for input ik data.doc.input

joonaspaakko commented 9 months ago

@schroef, I guess I'll see if I have time to fix it over the weekend. I was kinda waiting for @nfourteen to make a pull request not to steal his thunder, but I'll either fix it this weekend or rollback 1.8 if I don't have enough time.

schroef commented 9 months ago

Well I looked at his profile and he either uses something else or only works offline. There is nothing there.

Did this version have more features?

nfourteen commented 9 months ago

@joonaspaakko @schroef I apologize...I got sidetracked on some other features for the script and work. I'll get a few PRs up for some things I've been working on tomorrow or Sat, including the fix for this issue.

joonaspaakko commented 8 months ago

Did this version have more features?

@schroef pretty much 2 niche features that most users probably don't need.

https://github.com/joonaspaakko/Batch-Mockup-Smart-Object-Replacement-photoshop-script/blob/fc546baacf6ea29cab95eb3b97cb869ae2baeccd/script/Batch%20Mockup%20Smart%20Object%20Replacement.jsx#L39-L51