Unable to pass parameters when calling a "batchPlay function" in API 2

Hi,

I’m encountering a strange behavior when using batchPlay code within a function.

I usually wrap my batchPlay code in function like that:

const makeChannelMixer = async (cv, mv, yv, bv, constant) => {
		await batchPlay(
			[
				{
					_obj: "make",
					_target: [
					{
						_ref: "adjustmentLayer"
					}
					],
					using: {
						_obj: "adjustmentLayer",
						type: {
							_obj: "channelMixer",
							presetKind: {
								_enum: "presetKindType",
								_value: "presetKindCustom"
							},
							monochromatic: true,
							gray: {
								_obj: "channelMatrix",
								cyan: {
									_unit: "percentUnit",
									_value: cv
								},
								magenta: {
									_unit: "percentUnit",
									_value: mv
								},
								yellowColor: {
									_unit: "percentUnit",
									_value: yv
								},
								black: {
									_unit: "percentUnit",
									_value: bv
								},
								constant: {
									_unit: "percentUnit",
									_value: constant
								}
							}
						}
					},
					_options: {
						dialogOptions: "dontDisplay"
					}
				}
			],{});
		};

Calling that function using parameters and not only fixed values worked perfectly fine with API 1:
makeChannelMixer(25,25,25,25,0);

Since I use API 2 – and therefore executeAsModal – using parameters with the function call doesn’t work anymore. Nothing happens when calling that function:
await require('photoshop').core.executeAsModal(makeChannelMixer(25,25,25,25,0));

But it does work without the use of parameters (of course with fixed values in the batchPlay code):
await require('photoshop').core.executeAsModal(makeChannelMixer);

@kerrishotts It seems like a bug to me, but maybe I miss something completely obvious?!

Thanks

Try wrapping your function in an executeAsModal rather than passing it as a parameter.

const makeChannelMixer = async (cv, mv, yv, bv, constant) => {
      await core.executeAsModal(() => {
        return batchPlay(
            // batchPlay code using params
        )
      })
}

*Excuse the janky formatting above, I wrote it on my phone!

1 Like

Not at my PC right now and can’t test for sure, but I think this should work

require('photoshop').core.executeAsModal(() => makeChannelMixer(25,25,25,25,0));

When you use like executeAsModal(makeChannelMixer()), it tries to execute your function and use the response as executeAsModal(responseOfYourFunc), but you need to pass a function. So either executeAsModal(makeChannelMixer), where you pass not the response, but function itself, or executeAsModal(() => makeChannelMixer()), where you pass a function, which will execute your makeChannelMixer()

1 Like

@Karmalakas and @Timothy_Bennett Thank you both for your answers. I just tried them and they both work fine! And thanks for your explanation, Karmalakas :+1:

1 Like