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

Generative fill shouldn't pull visual information from nearby artboards

Community Beginner ,
Jul 30, 2023 Jul 30, 2023

I've been playing around with the new generative fill feature and one feature I'd really like to see implimented is the ability to toggle whether or not the fill pulls visual data from nearby artboards. I don't see lot of use cases where it'd be valuable to be able to do that and what often happens is the scraps of visual data from nearby images will muddle the final result. 

I often use Photoshop to comp together storyboards and it can get frustrating if I'm just trying to extend a scene in an ocean image and the results come out with bits of brick wall from a nearby artboard. I think a toggle feature would allow you to decide what would work best for your workflow. 

Idea No status
TOPICS
macOS
546
Translate
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
6 Comments
Community Beginner ,
Apr 15, 2025 Apr 15, 2025

2 years later and its still doing this. It really doens tmake sense for it to work this way and is likely an oversight that Adobe never thougth important enough to address. Its unfortunate because Id actually be able to use this feature if it were fixed.

Translate
Report
Community Expert ,
Apr 15, 2025 Apr 15, 2025

Artboards are a hack to make multiple, possibly different-sized "canvases" from a single canvas. So, it's not surprising that unwanted nearby content may influence the algorithm. This is certainly something that Adobe should address in development.

 

In the meantime, I can envision an action or script to copy the selected artboard active layer area to a new temporary document, process it, and then return the result to the original... Or perhaps a smart object instead of a temp doc. Anyway, something like that; I haven't tested this idea, I'm just shooting from the hip. 

Translate
Report
Community Expert ,
Apr 18, 2025 Apr 18, 2025

I played around and this is possible with an action, although scripts offer uninterrupted processing:

 

genatn.png

Translate
Report
Community Expert ,
Apr 18, 2025 Apr 18, 2025

This v1 script uses a new temporary document to isolate the generative fill source data, which was the original idea that I explored:

 

NOTE: updated v1.1 bug fix!

 

/*
Isolate Generative Fill Source to Active Artboard.jsx
Stephen Marsh
v1.0 - 18th April 2025
v1.1 - 19th April 2025, fixed the generative fill validation error
https://community.adobe.com/t5/photoshop-ecosystem-ideas/generative-fill-shouldn-t-pull-visual-information-from-nearby-artboards/idc-p/15277597#U15276446
*/

app.activeDocument.suspendHistory("Isolate Generative Fill Source to Active Artboard", "main()");

function main() {
    // Check if there are any open documents
    if (app.documents.length === 0) {
        alert("A document must be open to run this script!");
        return;
    }

    if (confirm("Double check the active layer. Generative content will be added above the active layer. Continue?")) {

        // Set the variables
        var origDoc = app.activeDocument;
        var origDocName = origDoc.name;
        var origDocActiveLayer = origDoc.activeLayer;
        var origDocActiveLayerName = origDocActiveLayer.name;
        var rootLayerGroup = getRootParentLayerGroup(app.activeDocument.activeLayer);
        var rootLayerGroupName = rootLayerGroup.name;

        // Add a temp filled layer to retain the original artboard dimensions
        var s2t = function (s) {
            return app.stringIDToTypeID(s);
        };
        var descriptor = new ActionDescriptor();
        var descriptor2 = new ActionDescriptor();
        var descriptor3 = new ActionDescriptor();
        var reference = new ActionReference();
        reference.putClass(s2t("layer"));
        descriptor.putReference(s2t("null"), reference);
        descriptor2.putString(s2t("name"), "395ea539-e812-46f3-bfd4-87486e26218f");
        descriptor.putObject(s2t("using"), s2t("layer"), descriptor2);
        descriptor.putInteger(s2t("layerID"), 79);
        executeAction(s2t("make"), descriptor, DialogModes.NO);
        descriptor3.putEnumerated(s2t("using"), s2t("fillContents"), s2t("foregroundColor"));
        executeAction(s2t("fill"), descriptor3, DialogModes.NO);
        app.activeDocument.activeLayer.fillOpacity = 0;

        // Set the root group as the active layer
        if (rootLayerGroup) {
            app.activeDocument.activeLayer = rootLayerGroup;
        }

        // Dupe the active layer to a new document
        dupeLayerToTempDoc("tempDoc", rootLayerGroupName);

        // Trim to transparency
        var descriptor = new ActionDescriptor();
        descriptor.putEnumerated(s2t("trimBasedOn"), s2t("trimBasedOn"), s2t("transparency"));
        descriptor.putBoolean(s2t("top"), true);
        descriptor.putBoolean(s2t("bottom"), true);
        descriptor.putBoolean(s2t("left"), true);
        descriptor.putBoolean(s2t("right"), true);
        executeAction(s2t("trim"), descriptor, DialogModes.NO);

        // Set the temp doc variable
        var tempDoc = app.activeDocument;

        // Set the active layer using the origDocActiveLayerName variable
        var targetLayer = findLayerByName(app.activeDocument, origDocActiveLayerName);
        if (targetLayer) {
            app.activeDocument.activeLayer = targetLayer;
        } else {
            alert("Layer not found: " + origDocActiveLayerName);
        }

        // Select all
        app.activeDocument.selection.selectAll();

        // Interactive generative fill
        app.beep();
        generativeFill();

        // Return to the original document
        app.activeDocument = origDoc;

        // Select the original active layer
        app.activeDocument.activeLayer = origDocActiveLayer;

        // Return to the temp document
        app.activeDocument = tempDoc;

        // Dupe the layers back to the temp doc
        var descriptor = new ActionDescriptor();
        var list = new ActionList();
        var reference = new ActionReference();
        var reference2 = new ActionReference();
        reference.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
        descriptor.putReference(s2t("null"), reference);
        reference2.putName(s2t("document"), origDocName); // Target doc name
        descriptor.putReference(s2t("to"), reference2);
        descriptor.putInteger(s2t("destinationDocumentID"), 59);
        descriptor.putInteger(s2t("version"), 5);
        descriptor.putString(s2t("artboard"), rootLayerGroupName); // Target artboard name
        descriptor.putList(s2t("ID"), list);
        executeAction(s2t("duplicate"), descriptor, DialogModes.NO);

        // Close the temp doc without saving
        tempDoc.close(SaveOptions.DONOTSAVECHANGES);

        // Delete the temp filled layer
        var layerFound = false;
        var layersToCheck = [];
        for (var k = 0; k < app.activeDocument.layers.length; k++) {
            layersToCheck.push(app.activeDocument.layers[k]);
        }
        while (layersToCheck.length > 0 && !layerFound) {
            var currentLayer = layersToCheck.pop();
            if (currentLayer.name === "395ea539-e812-46f3-bfd4-87486e26218f") {
                app.activeDocument.activeLayer = currentLayer;
                app.activeDocument.activeLayer.remove();
                layerFound = true;
            }
            else if (currentLayer.typename === "LayerSet") {
                for (var j = 0; j < currentLayer.layers.length; j++) {
                    layersToCheck.push(currentLayer.layers[j]);
                }
            }
        }

        // End of script
        app.beep();

    }
}


///// Functions /////

function getRootParentLayerGroup(layer) {
    while (layer.parent && layer.parent.typename === "LayerSet") {
        layer = layer.parent;
    }
    return layer; // Root group
}

function dupeLayerToTempDoc(name2, layerName) {
    var s2t = function (s) {
        return app.stringIDToTypeID(s);
    };
    var descriptor = new ActionDescriptor();
    var reference = new ActionReference();
    var reference2 = new ActionReference();
    reference.putClass(s2t("document"));
    descriptor.putReference(s2t("null"), reference);
    descriptor.putString(s2t("name"), name2);
    reference2.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
    descriptor.putReference(s2t("using"), reference2);
    descriptor.putString(s2t("layerName"), layerName);
    executeAction(s2t("make"), descriptor, DialogModes.NO);
}

function findLayerByName(layerSet, name) {
    for (var i = 0; i < layerSet.layers.length; i++) {
        var layer = layerSet.layers[i];
        if (layer.name === name) {
            return layer;
        } else if (layer.typename === "LayerSet") {
            var foundLayer = findLayerByName(layer, name);
            if (foundLayer) {
                return foundLayer;
            }
        }
    }
    return null; // If no layer is found
}

function generativeFill() {
    try {
        var idsyntheticFill = stringIDToTypeID("syntheticFill");
        var desc299 = new ActionDescriptor();
        var idnull = stringIDToTypeID("null");
        var ref20 = new ActionReference();
        var iddocument = stringIDToTypeID("document");
        var idordinal = stringIDToTypeID("ordinal");
        var idtargetEnum = stringIDToTypeID("targetEnum");
        ref20.putEnumerated(iddocument, idordinal, idtargetEnum);
        desc299.putReference(idnull, ref20);
        var iddocumentID = stringIDToTypeID("documentID");
        desc299.putInteger(iddocumentID, 64);
        var idlayerID = stringIDToTypeID("layerID");
        desc299.putInteger(idlayerID, 43);
        var idprompt = stringIDToTypeID("prompt");
        desc299.putString(idprompt, """""");
        var idserviceID = stringIDToTypeID("serviceID");
        desc299.putString(idserviceID, """clio""");
        var idworkflowType = stringIDToTypeID("workflowType");
        var idgenWorkflow = stringIDToTypeID("genWorkflow");
        var idin_painting = stringIDToTypeID("in_painting");
        desc299.putEnumerated(idworkflowType, idgenWorkflow, idin_painting);
        var idserviceOptionsList = stringIDToTypeID("serviceOptionsList");
        var desc300 = new ActionDescriptor();
        var idclio = stringIDToTypeID("clio");
        var desc301 = new ActionDescriptor();
        var idgi_PROMPT = stringIDToTypeID("gi_PROMPT");
        desc301.putString(idgi_PROMPT, """""");
        var idgi_MODE = stringIDToTypeID("gi_MODE");
        desc301.putString(idgi_MODE, """ginp""");
        var idgi_SEED = stringIDToTypeID("gi_SEED");
        desc301.putInteger(idgi_SEED, -1);
        var idgi_NUM_STEPS = stringIDToTypeID("gi_NUM_STEPS");
        desc301.putInteger(idgi_NUM_STEPS, -1);
        var idgi_GUIDANCE = stringIDToTypeID("gi_GUIDANCE");
        desc301.putInteger(idgi_GUIDANCE, 6);
        var idgi_SIMILARITY = stringIDToTypeID("gi_SIMILARITY");
        desc301.putInteger(idgi_SIMILARITY, 0);
        var idgi_CROP = stringIDToTypeID("gi_CROP");
        desc301.putBoolean(idgi_CROP, false);
        var idgi_DILATE = stringIDToTypeID("gi_DILATE");
        desc301.putBoolean(idgi_DILATE, false);
        var idgi_CONTENT_PRESERVE = stringIDToTypeID("gi_CONTENT_PRESERVE");
        desc301.putInteger(idgi_CONTENT_PRESERVE, 0);
        var idgi_ENABLE_PROMPT_FILTER = stringIDToTypeID("gi_ENABLE_PROMPT_FILTER");
        desc301.putBoolean(idgi_ENABLE_PROMPT_FILTER, true);
        var iddualCrop = stringIDToTypeID("dualCrop");
        desc301.putBoolean(iddualCrop, true);
        var idgi_ADVANCED = stringIDToTypeID("gi_ADVANCED");
        desc301.putString(idgi_ADVANCED, """{"enable_mts":true}""");
        var idclio = stringIDToTypeID("clio");
        desc300.putObject(idclio, idclio, desc301);
        var idnull = stringIDToTypeID("null");
        desc299.putObject(idserviceOptionsList, idnull, desc300);
        executeAction(idsyntheticFill, desc299, DialogModes.ALL);

        var genLayerName = app.activeDocument.activeLayer.name;

        // Verify the addition of the generative fill layer
        if (!app.activeDocument.activeLayer || app.activeDocument.activeLayer.name !== genLayerName) {
            throw new Error("Generative Fill operation failed or was canceled.");
        }

    } catch (e) {
        alert("Generative Fill was canceled or encountered an error. Cleanup will be performed.");
        performCleanup(); // Call a cleanup function to handle temporary layers/documents
        throw e; // Re-throw the error if needed
    }
}

function performCleanup() {
    // Add logic to clean up temporary layers or documents
    try {
        // Close temp documents if they exist
        var tempDoc = app.documents.getByName("tempDoc");
        if (tempDoc) {
            tempDoc.close(SaveOptions.DONOTSAVECHANGES);
        }
    } catch (e) {
        // Ignore if the document doesn't exist
    }

    // Remove the temporary layer named "395ea539-e812-46f3-bfd4-87486e26218f"
    try {
        var layerFound = false;
        var layersToCheck = [];
        for (var k = 0; k < app.activeDocument.layers.length; k++) {
            layersToCheck.push(app.activeDocument.layers[k]);
        }
        while (layersToCheck.length > 0 && !layerFound) {
            var currentLayer = layersToCheck.pop();
            if (currentLayer.name === "395ea539-e812-46f3-bfd4-87486e26218f") {
                app.activeDocument.activeLayer = currentLayer;
                app.activeDocument.activeLayer.remove();
                layerFound = true;
            } else if (currentLayer.typename === "LayerSet") {
                for (var j = 0; j < currentLayer.layers.length; j++) {
                    layersToCheck.push(currentLayer.layers[j]);
                }
            }
        }
    } catch (e) {
        alert(e);
    }
}

 

  1. Copy the code text to the clipboard
  2. Open a new blank file in a plain-text editor (not in a word processor)
  3. Paste the code in
  4. Save as a plain text format file – .txt
  5. Rename the saved file extension from .txt to .jsx
  6. Install or browse to the .jsx file to run (see below)

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

Translate
Report
Community Expert ,
Apr 18, 2025 Apr 18, 2025

I prefer this v2 script, it uses a smart object instead of a separate document to isolate the generative fill source data:

 

Note: updated v2.1 bug fix!

 

/*
Isolate Generative Fill Source to Active Artboard v2.jsx
Stephen Marsh
v2.0 - 18th April 2025
v2.1 - 19th April 2025, fixed the generative fill validation error
https://community.adobe.com/t5/photoshop-ecosystem-ideas/generative-fill-shouldn-t-pull-visual-information-from-nearby-artboards/idc-p/15277597#U15276450
*/

#target photoshop;

app.activeDocument.suspendHistory("Isolate Generative Fill Source to Active Artboard v2", "main()");

function main() {
    // Check if there are any open documents
    if (app.documents.length === 0) {
        alert("A document must be open to run this script!");
        return;
    }

    if (confirm("Double check the active layer. Generative content will be added above the active layer. Continue?")) {
        try {
            // Set the variables
            var origDoc = app.activeDocument;
            var origDocName = origDoc.name;
            var origDocActiveLayer = origDoc.activeLayer;
            var origDocActiveLayerName = origDocActiveLayer.name;
            var rootLayerGroup = getRootParentLayerGroup(app.activeDocument.activeLayer);
            var rootLayerGroupName = rootLayerGroup.name;

            // Set the root group as the active layer
            if (rootLayerGroup) {
                app.activeDocument.activeLayer = rootLayerGroup;
            }

            // Convert the artboard to an embedded smart object
            executeAction(stringIDToTypeID("newPlacedLayer"), undefined, DialogModes.NO);

            // Edit the embedded smart object
            app.runMenuItem(stringIDToTypeID('placedLayerEditContents'));

            // Set the active layer using the origDocActiveLayerName variable
            var targetLayer = findLayerByName(app.activeDocument, origDocActiveLayerName);
            if (targetLayer) {
                app.activeDocument.activeLayer = targetLayer;
            } else {
                alert("Layer not found: " + origDocActiveLayerName);
            }

            // Select all
            app.activeDocument.selection.selectAll();

            // Interactive generative fill
            app.beep();
            generativeFill();

            // Close the edited smart object doc saving changes
            app.activeDocument.close(SaveOptions.SAVECHANGES);

            // Return to the original document
            app.activeDocument = origDoc;

            // Convert the embedded smart object back to a layer
            executeAction(stringIDToTypeID("placedLayerConvertToLayers"), undefined, DialogModes.NO);

            // Unlock the artboard
            applyLocking(true);

            // Set the active layer using the origDocActiveLayerName variable
            var targetLayer = findLayerByName(app.activeDocument, origDocActiveLayerName);
            if (targetLayer) {
                app.activeDocument.activeLayer = targetLayer;
            } else {
                alert("Layer not found: " + origDocActiveLayerName);
            }

            // End of script
            app.beep();

        } catch (e) {
            // Handle errors and cleanup
            alert("An error or cancellation occurred: " + e.message);
            // Perform cleanup
            try {
                // Close the edited smart object doc
                if (app.activeDocument.name !== origDoc.name) {
                    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
                }
                // Convert the smart object back to a layer
                executeAction(stringIDToTypeID("placedLayerConvertToLayers"), undefined, DialogModes.NO);
                // Unlock layers if necessary
                applyLocking(false);
                // Set the active layer using the origDocActiveLayerName variable
                var targetLayer = findLayerByName(app.activeDocument, origDocActiveLayerName);
                if (targetLayer) {
                    app.activeDocument.activeLayer = targetLayer;
                } else {
                    alert("Layer not found: " + origDocActiveLayerName);
                }
            } catch (e) {
                alert(e);
            }
        }
    }
}

///// Functions /////

function getRootParentLayerGroup(layer) {
    while (layer.parent && layer.parent.typename === "LayerSet") {
        layer = layer.parent;
    }
    return layer; // Root group
}

function findLayerByName(layerSet, name) {
    for (var i = 0; i < layerSet.layers.length; i++) {
        var layer = layerSet.layers[i];
        if (layer.name === name) {
            return layer;
        } else if (layer.typename === "LayerSet") {
            var foundLayer = findLayerByName(layer, name);
            if (foundLayer) {
                return foundLayer;
            }
        }
    }
    return null; // If no layer is found
}

function generativeFill() {
    try {
        var idsyntheticFill = stringIDToTypeID("syntheticFill");
        var desc299 = new ActionDescriptor();
        var idnull = stringIDToTypeID("null");
        var ref20 = new ActionReference();
        var iddocument = stringIDToTypeID("document");
        var idordinal = stringIDToTypeID("ordinal");
        var idtargetEnum = stringIDToTypeID("targetEnum");
        ref20.putEnumerated(iddocument, idordinal, idtargetEnum);
        desc299.putReference(idnull, ref20);
        var iddocumentID = stringIDToTypeID("documentID");
        desc299.putInteger(iddocumentID, 64);
        var idlayerID = stringIDToTypeID("layerID");
        desc299.putInteger(idlayerID, 43);
        var idprompt = stringIDToTypeID("prompt");
        desc299.putString(idprompt, """""");
        var idserviceID = stringIDToTypeID("serviceID");
        desc299.putString(idserviceID, """clio""");
        var idworkflowType = stringIDToTypeID("workflowType");
        var idgenWorkflow = stringIDToTypeID("genWorkflow");
        var idin_painting = stringIDToTypeID("in_painting");
        desc299.putEnumerated(idworkflowType, idgenWorkflow, idin_painting);
        var idserviceOptionsList = stringIDToTypeID("serviceOptionsList");
        var desc300 = new ActionDescriptor();
        var idclio = stringIDToTypeID("clio");
        var desc301 = new ActionDescriptor();
        var idgi_PROMPT = stringIDToTypeID("gi_PROMPT");
        desc301.putString(idgi_PROMPT, """""");
        var idgi_MODE = stringIDToTypeID("gi_MODE");
        desc301.putString(idgi_MODE, """ginp""");
        var idgi_SEED = stringIDToTypeID("gi_SEED");
        desc301.putInteger(idgi_SEED, -1);
        var idgi_NUM_STEPS = stringIDToTypeID("gi_NUM_STEPS");
        desc301.putInteger(idgi_NUM_STEPS, -1);
        var idgi_GUIDANCE = stringIDToTypeID("gi_GUIDANCE");
        desc301.putInteger(idgi_GUIDANCE, 6);
        var idgi_SIMILARITY = stringIDToTypeID("gi_SIMILARITY");
        desc301.putInteger(idgi_SIMILARITY, 0);
        var idgi_CROP = stringIDToTypeID("gi_CROP");
        desc301.putBoolean(idgi_CROP, false);
        var idgi_DILATE = stringIDToTypeID("gi_DILATE");
        desc301.putBoolean(idgi_DILATE, false);
        var idgi_CONTENT_PRESERVE = stringIDToTypeID("gi_CONTENT_PRESERVE");
        desc301.putInteger(idgi_CONTENT_PRESERVE, 0);
        var idgi_ENABLE_PROMPT_FILTER = stringIDToTypeID("gi_ENABLE_PROMPT_FILTER");
        desc301.putBoolean(idgi_ENABLE_PROMPT_FILTER, true);
        var iddualCrop = stringIDToTypeID("dualCrop");
        desc301.putBoolean(iddualCrop, true);
        var idgi_ADVANCED = stringIDToTypeID("gi_ADVANCED");
        desc301.putString(idgi_ADVANCED, """{"enable_mts":true}""");
        var idclio = stringIDToTypeID("clio");
        desc300.putObject(idclio, idclio, desc301);
        var idnull = stringIDToTypeID("null");
        desc299.putObject(idserviceOptionsList, idnull, desc300);
        executeAction(idsyntheticFill, desc299, DialogModes.ALL);

        var genLayerName = app.activeDocument.activeLayer.name;

    } catch (e) {
        throw new Error("Generative Fill was canceled or failed: " + e.message);
    }
}

function applyLocking(protectNone) {
    var s2t = function (s) {
        return app.stringIDToTypeID(s);
    };
    var descriptor = new ActionDescriptor();
    var descriptor2 = new ActionDescriptor();
    var reference = new ActionReference();
    reference.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
    descriptor.putReference(s2t("null"), reference);
    descriptor2.putBoolean(s2t("protectNone"), protectNone); // true or false
    descriptor.putObject(s2t("layerLocking"), s2t("layerLocking"), descriptor2);
    executeAction(s2t("applyLocking"), descriptor, DialogModes.NO);
}

 

  1. Copy the code text to the clipboard
  2. Open a new blank file in a plain-text editor (not in a word processor)
  3. Paste the code in
  4. Save as a plain text format file – .txt
  5. Rename the saved file extension from .txt to .jsx
  6. Install or browse to the .jsx file to run (see below)

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

Translate
Report
Community Expert ,
Apr 18, 2025 Apr 18, 2025
LATEST

Here is a v3 script using an interface to select either Generative Fill or Generate Image:

 

Isolate-Generative-Fill-Source-to-Active-Artboard-UI-v3.png

/*
Isolate Generative Fill Source to Active Artboard UI v3.jsx
Stephen Marsh
v3.0 - 19th April 2025
https://community.adobe.com/t5/photoshop-ecosystem-ideas/generative-fill-shouldn-t-pull-visual-information-from-nearby-artboards/idc-p/15277597#U15277597
*/

#target photoshop;

// Ensure that v2024 or later is being used for generative features
var versionNumber = app.version.split(".");
var versionCheck = parseInt(versionNumber[0]);
if (versionCheck < 25) { // Photoshop 2024 is version 25.x
    alert("You must use Photoshop 2024 or later to run this script.");
    exit();
}

// Create the UI dialog
function createDialog() {
    var dlg = new Window("dialog", "Isolate Generative Fill Source to Active Artboard (v3.0)", undefined);
    dlg.orientation = "column";
    dlg.alignChildren = "fill";
    dlg.preferredSize.width = 400;

    // Create a panel for the generation options
    var genPanel = dlg.add("panel", undefined, ""); // unused
    genPanel.orientation = "column";
    genPanel.alignChildren = "left";
    genPanel.margins = 20;

    // Add dropdown for generation type
    var generationTypes = ["Generative Fill", "Generate Image"];
    var typeGroup = genPanel.add("group");
    typeGroup.orientation = "row";
    typeGroup.add("statictext", undefined, "Generation Type:");
    var typeDropdown = typeGroup.add("dropdownlist", undefined, generationTypes);
    typeDropdown.selection = 0;

    // Add OK and Cancel buttons
    var btnGroup = dlg.add("group");
    btnGroup.orientation = "row";
    btnGroup.alignment = "right";

    var cancelBtn = btnGroup.add("button", undefined, "Cancel");
    var okBtn = btnGroup.add("button", undefined, "OK", { name: "ok" });

    // Set button handlers
    cancelBtn.onClick = function () {
        dlg.close();
    };

    okBtn.onClick = function () {
        var generationType = typeDropdown.selection.text;
        dlg.close();
        executeGenerativeFunction(generationType);
    };

    return dlg;
}

// Main function to execute selected dropdown menu generative function
function executeGenerativeFunction(generationType) {

    app.activeDocument.suspendHistory("Isolate Generative Fill Source to Active Artboard v3", "main()");

    function main() {

        // Check if there are any open documents
        if (app.documents.length === 0) {
            alert("A document must be open to run this script!");
            return;
        }

        if (confirm("Double check the active layer. Generative content will be added above the active layer. Continue?")) {
            try {
                // Set the variables
                var origDoc = app.activeDocument;
                var origDocName = origDoc.name;
                var origDocActiveLayer = origDoc.activeLayer;
                var origDocActiveLayerName = origDocActiveLayer.name.toString();
                var rootLayerGroup = getRootParentLayerGroup(app.activeDocument.activeLayer);
                var rootLayerGroupName = rootLayerGroup.name;

                // Set the root group as the active layer
                if (rootLayerGroup) {
                    app.activeDocument.activeLayer = rootLayerGroup;
                }

                // Convert the artboard to an embedded smart object
                executeAction(stringIDToTypeID("newPlacedLayer"), undefined, DialogModes.NO);

                // Edit the embedded SO
                app.runMenuItem(stringIDToTypeID('placedLayerEditContents'));

                // Set the active layer using the origDocActiveLayerName variable
                var targetLayer = findLayerByName(app.activeDocument, origDocActiveLayerName);
                if (targetLayer) {
                    app.activeDocument.activeLayer = targetLayer;
                } else {
                    alert("Layer not found: " + origDocActiveLayerName);
                    return;
                }

                // Select all
                app.activeDocument.selection.selectAll();

                // Execute the selected generation function
                app.beep();
                if (generationType === "Generative Fill") {
                    generativeFill();
                } else if (generationType === "Generate Image") {
                    generateImage();
                }

                // Close the edited smart object doc saving changes
                app.activeDocument.close(SaveOptions.SAVECHANGES);

                // Convert the embedded smart object back to layers
                executeAction(stringIDToTypeID("placedLayerConvertToLayers"), undefined, DialogModes.NO);

                // Unlock the artboard
                applyLocking(true);

                // Set the active layer using the origDocActiveLayerName variable
                var targetLayer = findLayerByName(app.activeDocument, origDocActiveLayerName);
                if (targetLayer) {
                    app.activeDocument.activeLayer = targetLayer;
                } else {
                    alert("Layer not found: " + origDocActiveLayerName);
                    return;
                }
                // End of script
                app.beep();

            } catch (e) {
                // Handle errors and cleanup
                alert("An error or cancellation occurred: " + e.message);
                try {
                    // Close any smart object without saving changes
                    if (app.documents.length > 0 && app.activeDocument.name !== origDoc.name) {
                        app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
                    }
                    // Return to the original document
                    if (app.documents.length > 0 && origDoc) {
                        app.activeDocument = origDoc;
                        // Convert the smart object back to a layer
                        executeAction(stringIDToTypeID("placedLayerConvertToLayers"), undefined, DialogModes.NO);
                    }
                    // Unlock layers if necessary
                    applyLocking(false);
                    // Set the active layer using the origDocActiveLayerName variable
                    var targetLayer = findLayerByName(app.activeDocument, origDocActiveLayerName);
                    if (targetLayer) {
                        app.activeDocument.activeLayer = targetLayer;
                    } else {
                        alert("Layer not found: " + origDocActiveLayerName);
                        return;
                    }
                } catch (e) {
                    alert(e);
                }
            }
        }
    }
}

// Display the dialog
var dialog = createDialog();
dialog.center();
dialog.show();


///// Functions /////

function getRootParentLayerGroup(layer) {
    while (layer.parent && layer.parent.typename === "LayerSet") {
        layer = layer.parent;
    }
    return layer; // Root group
}

function findLayerByName(layerSet, name) {
    for (var i = 0; i < layerSet.layers.length; i++) {
        var layer = layerSet.layers[i];
        if (layer.name === name) {
            return layer;
        } else if (layer.typename === "LayerSet") {
            var foundLayer = findLayerByName(layer, name);
            if (foundLayer) {
                return foundLayer;
            }
        }
    }
    return null; // If no layer is found
}

function generativeFill() {
    var idsyntheticFill = stringIDToTypeID("syntheticFill");
    var desc299 = new ActionDescriptor();
    var idnull = stringIDToTypeID("null");
    var ref20 = new ActionReference();
    var iddocument = stringIDToTypeID("document");
    var idordinal = stringIDToTypeID("ordinal");
    var idtargetEnum = stringIDToTypeID("targetEnum");
    ref20.putEnumerated(iddocument, idordinal, idtargetEnum);
    desc299.putReference(idnull, ref20);
    var iddocumentID = stringIDToTypeID("documentID");
    desc299.putInteger(iddocumentID, 64);
    var idlayerID = stringIDToTypeID("layerID");
    desc299.putInteger(idlayerID, 43);
    var idprompt = stringIDToTypeID("prompt");
    desc299.putString(idprompt, """""");
    var idserviceID = stringIDToTypeID("serviceID");
    desc299.putString(idserviceID, """clio""");
    var idworkflowType = stringIDToTypeID("workflowType");
    var idgenWorkflow = stringIDToTypeID("genWorkflow");
    var idin_painting = stringIDToTypeID("in_painting");
    desc299.putEnumerated(idworkflowType, idgenWorkflow, idin_painting);
    var idserviceOptionsList = stringIDToTypeID("serviceOptionsList");
    var desc300 = new ActionDescriptor();
    var idclio = stringIDToTypeID("clio");
    var desc301 = new ActionDescriptor();
    var idgi_PROMPT = stringIDToTypeID("gi_PROMPT");
    desc301.putString(idgi_PROMPT, """""");
    var idgi_MODE = stringIDToTypeID("gi_MODE");
    desc301.putString(idgi_MODE, """ginp""");
    var idgi_SEED = stringIDToTypeID("gi_SEED");
    desc301.putInteger(idgi_SEED, -1);
    var idgi_NUM_STEPS = stringIDToTypeID("gi_NUM_STEPS");
    desc301.putInteger(idgi_NUM_STEPS, -1);
    var idgi_GUIDANCE = stringIDToTypeID("gi_GUIDANCE");
    desc301.putInteger(idgi_GUIDANCE, 6);
    var idgi_SIMILARITY = stringIDToTypeID("gi_SIMILARITY");
    desc301.putInteger(idgi_SIMILARITY, 0);
    var idgi_CROP = stringIDToTypeID("gi_CROP");
    desc301.putBoolean(idgi_CROP, false);
    var idgi_DILATE = stringIDToTypeID("gi_DILATE");
    desc301.putBoolean(idgi_DILATE, false);
    var idgi_CONTENT_PRESERVE = stringIDToTypeID("gi_CONTENT_PRESERVE");
    desc301.putInteger(idgi_CONTENT_PRESERVE, 0);
    var idgi_ENABLE_PROMPT_FILTER = stringIDToTypeID("gi_ENABLE_PROMPT_FILTER");
    desc301.putBoolean(idgi_ENABLE_PROMPT_FILTER, true);
    var iddualCrop = stringIDToTypeID("dualCrop");
    desc301.putBoolean(iddualCrop, true);
    var idgi_ADVANCED = stringIDToTypeID("gi_ADVANCED");
    desc301.putString(idgi_ADVANCED, """{"enable_mts":true}""");
    var idclio = stringIDToTypeID("clio");
    desc300.putObject(idclio, idclio, desc301);
    var idnull = stringIDToTypeID("null");
    desc299.putObject(idserviceOptionsList, idnull, desc300);
    executeAction(idsyntheticFill, desc299, DialogModes.ALL);
}

function generateImage() {
    var idsyntheticTextToImage = stringIDToTypeID("syntheticTextToImage");
    var desc262 = new ActionDescriptor();
    var idnull = stringIDToTypeID("null");
    var ref2 = new ActionReference();
    var iddocument = stringIDToTypeID("document");
    var idordinal = stringIDToTypeID("ordinal");
    var idtargetEnum = stringIDToTypeID("targetEnum");
    ref2.putEnumerated(iddocument, idordinal, idtargetEnum);
    desc262.putReference(idnull, ref2);
    var idworkflow = stringIDToTypeID("workflow");
    desc262.putString(idworkflow, """text_to_image""");
    var iddocumentID = stringIDToTypeID("documentID");
    desc262.putInteger(iddocumentID, 64);
    var idlayerID = stringIDToTypeID("layerID");
    desc262.putInteger(idlayerID, 215);
    var idprompt = stringIDToTypeID("prompt");
    desc262.putString(idprompt, """"""); // Empty string
    var idserviceID = stringIDToTypeID("serviceID");
    desc262.putString(idserviceID, """clio""");
    var idworkflowType = stringIDToTypeID("workflowType");
    var idgenWorkflow = stringIDToTypeID("genWorkflow");
    var idtext_to_image = stringIDToTypeID("text_to_image");
    desc262.putEnumerated(idworkflowType, idgenWorkflow, idtext_to_image);
    var idserviceOptionsList = stringIDToTypeID("serviceOptionsList");
    var desc263 = new ActionDescriptor();
    var idclio = stringIDToTypeID("clio");
    var desc264 = new ActionDescriptor();
    var idgi_PROMPT = stringIDToTypeID("gi_PROMPT");
    desc264.putString(idgi_PROMPT, """""");
    var idgi_MODE = stringIDToTypeID("gi_MODE");
    desc264.putString(idgi_MODE, """ginp""");
    var idgi_SEED = stringIDToTypeID("gi_SEED");
    desc264.putInteger(idgi_SEED, -1);
    var idgi_NUM_STEPS = stringIDToTypeID("gi_NUM_STEPS");
    desc264.putInteger(idgi_NUM_STEPS, -1);
    var idgi_GUIDANCE = stringIDToTypeID("gi_GUIDANCE");
    desc264.putInteger(idgi_GUIDANCE, 6);
    var idgi_SIMILARITY = stringIDToTypeID("gi_SIMILARITY");
    desc264.putInteger(idgi_SIMILARITY, 0);
    var idgi_CROP = stringIDToTypeID("gi_CROP");
    desc264.putBoolean(idgi_CROP, false);
    var idgi_DILATE = stringIDToTypeID("gi_DILATE");
    desc264.putBoolean(idgi_DILATE, false);
    var idgi_CONTENT_PRESERVE = stringIDToTypeID("gi_CONTENT_PRESERVE");
    desc264.putInteger(idgi_CONTENT_PRESERVE, 0);
    var idgi_ENABLE_PROMPT_FILTER = stringIDToTypeID("gi_ENABLE_PROMPT_FILTER");
    desc264.putBoolean(idgi_ENABLE_PROMPT_FILTER, true);
    var iddualCrop = stringIDToTypeID("dualCrop");
    desc264.putBoolean(iddualCrop, true);
    var idgi_ADVANCED = stringIDToTypeID("gi_ADVANCED");
    desc264.putString(idgi_ADVANCED, """{"enable_mts":true}""");
    var idclio_advanced_options = stringIDToTypeID("clio_advanced_options");
    var desc265 = new ActionDescriptor();
    var idtext_to_image_styles_options = stringIDToTypeID("text_to_image_styles_options");
    var desc266 = new ActionDescriptor();
    var idtext_to_image_content_type = stringIDToTypeID("text_to_image_content_type");
    desc266.putString(idtext_to_image_content_type, """none""");
    var idtext_to_image_effects_count = stringIDToTypeID("text_to_image_effects_count");
    desc266.putInteger(idtext_to_image_effects_count, 0);
    var idtext_to_image_effects_list = stringIDToTypeID("text_to_image_effects_list");
    var list4 = new ActionList();
    list4.putString("""none""");
    list4.putString("""none""");
    list4.putString("""none""");
    desc266.putList(idtext_to_image_effects_list, list4);
    var idnull = stringIDToTypeID("null");
    desc265.putObject(idtext_to_image_styles_options, idnull, desc266);
    var idnull = stringIDToTypeID("null");
    desc264.putObject(idclio_advanced_options, idnull, desc265);
    var idclio = stringIDToTypeID("clio");
    desc263.putObject(idclio, idclio, desc264);
    var idnull = stringIDToTypeID("null");
    desc262.putObject(idserviceOptionsList, idnull, desc263);
    executeAction(idsyntheticTextToImage, desc262, DialogModes.ALL);
}

function applyLocking(protectNone) {
    var s2t = function (s) {
        return app.stringIDToTypeID(s);
    };
    var descriptor = new ActionDescriptor();
    var descriptor2 = new ActionDescriptor();
    var reference = new ActionReference();
    reference.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
    descriptor.putReference(s2t("null"), reference);
    descriptor2.putBoolean(s2t("protectNone"), protectNone); // true or false
    descriptor.putObject(s2t("layerLocking"), s2t("layerLocking"), descriptor2);
    executeAction(s2t("applyLocking"), descriptor, DialogModes.NO);
}

 

  1. Copy the code text to the clipboard
  2. Open a new blank file in a plain-text editor (not in a word processor)
  3. Paste the code in
  4. Save as a plain text format file – .txt
  5. Rename the saved file extension from .txt to .jsx
  6. Install or browse to the .jsx file to run (see below)

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

Translate
Report