• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Scripts Cannot Find Datasets

New Here ,
Nov 20, 2024 Nov 20, 2024

Copy link to clipboard

Copied

I'm trying to run a script that essentially does a find and replace for text in a specific variable for all data sets. However, no matter what I try, the script cannot find any datasets, even though I am able to import them, apply them, and export them as files. Any ideas? Below is my script (saved as replaceBulletScript.jsx in the same directory as my PSD):

#target photoshop

// Function to replace all occurrences of "•" with "•" in the "New-Card-Effect" variable across all datasets
function replaceBulletInAllDatasets(targetVariableName, targetString, replacementString) {
    try {
        // Get the active document
        var doc = app.activeDocument;

        // Ensure datasets exist
        if (!doc.dataSets || doc.dataSets.length === 0) {
            alert(
                "No datasets found in the active document: " + doc.name
            );
            return;
        }

        // Iterate through all datasets
        for (var i = 0; i < doc.dataSets.length; i++) {
            var dataSet = doc.dataSets[i];

            // Loop through the variables in the dataset
            for (var j = 0; j < dataSet.dataPoints.length; j++) {
                var dataPoint = dataSet.dataPoints[j];

                // Check if the variable name matches the target
                if (dataPoint.variable.name === targetVariableName) {
                    // Replace the target string in the data point's value
                    if (dataPoint.value.indexOf(targetString) !== -1) {
                        dataPoint.value = dataPoint.value.split(targetString).join(replacementString);
                    }
                }
            }
        }

        alert("Replacement complete for all datasets with variable name: " + targetVariableName);
    } catch (e) {
        alert("An error occurred: " + e.message);
    }
}

// Main execution
replaceBulletInAllDatasets("New-Card-Effect", "•", "•")

 

TOPICS
Actions and scripting , Windows

Views

52

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
New Here ,
Nov 20, 2024 Nov 20, 2024

Copy link to clipboard

Copied

Adobe Photoshop Version: 26.1.0 20241113.r.121 158e617 x64
Operating System: Windows 10 64-bit
Version: 10 10.0.19045.5131

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 20, 2024 Nov 20, 2024

Copy link to clipboard

Copied

LATEST

Is that the full code?

 

You mentioned being able to import, apply and export - presumably via scripting.

 

Did you write that code yourself, or did AI generate it for you?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines