Script to Check for Existing DataSets? (Variables, Data-driven Graphics)
Copy link to clipboard
Copied
I have been extending the original code from the late Mike Hale here:
https://community.adobe.com/t5/photoshop-ecosystem-discussions/using-datasets/td-p/2665594/page/2
I am currently using a confirm dialog for the user to OK to run the script, which relies on them knowing that the file already has Variables/Data Sets defined.
Ideally, the script would check for the existence of Data Sets and terminate if none were found.
Unfortunately, the action manager code is beyond me, so I was wondering if anyone knew how to check for this.
Explore related tutorials & articles
Copy link to clipboard
Copied
I couldn’t identify the information via AM-code so far.
Reading the image-file itself might offer an approach (if the image has been saved since the creation of the datasets at least).
Copy link to clipboard
Copied
@c.pfaffenbichler - Thank you for your time, I appreciate that this is a rather esoteric niche for scripting.
Copy link to clipboard
Copied
I suspect UXP Scripting might offer a better handle on the feature … but I don’t know.
Copy link to clipboard
Copied
Tried UXP, can apply but not get a Deta Set. And it needs to specify the name exactly when applying, not the index.
const { app, core, action } = require('photoshop') ;
try {
await core.executeAsModal(async () =>
{
const dataSetName = 'set 1' ;
const result = await action.batchPlay(
[
{
_obj: 'apply',
_target: [
{
_name: dataSetName,
_ref: 'dataSetClass'
}
]
}
],
{}
) ;
app.showAlert(JSON.stringify(result)) ;
},
{
commandName: 'Apply Dataset'
}
) ;
} catch(e) {
app.showAlert(e) ;
}
This is similar to the structure of Workspace, which can select but not get.
Copy link to clipboard
Copied
Thank you for trying!
Looks like I'll need to stick with the confirm prompt and put the onus on the user (not to mention that rewriting this script in UXP isn't possible for me).
Copy link to clipboard
Copied
Applying to a non-existent dataset will return [{}] in the result.
If you know the name of the dataset, you can determine whether it succeeded or was ignored by trying to apply it. In other words, it is possible to know indirectly whether the dataset exists or not.
If it succeeds, the result will look like this.
[
{
"_obj": "apply",
"_target": [
{
"_ref": "dataSetClass",
"_name": "set 1"
}
]
}
]

