Skip to main content
huyct1507
Participant
July 1, 2024
Answered

Can I duplicate groups contain Smart Objects but Make a New S.O via Copy for the same time?

  • July 1, 2024
  • 1 reply
  • 307 views

I'm trying to make somethings like a league schedule with logos (a smart object (S.O) can change the logo), each group for one game. Then I duplicate the group, but all the S.O are linked (change one is change all), I have to use Make a New Smart Object via Copy for every single S.O and it takes some times. 

 

CAN I DUPLICATE A GROUP, THAT ALSO MAKE A NEW SMART OBJECT VIA COPY FOR EVERY SINGLE S.O IN THE GROUP, FOR THE SAME TIME?

This topic has been closed for replies.
Correct answer Stephen Marsh

@huyct1507 

 

You can try this:

 

/*
Dupe Selected Group and All Smart Objects as Copies.jsx
v1.0, 1st July 2024 - Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/can-i-duplicate-groups-contain-smart-objects-but-make-a-new-s-o-via-copy-for-the-same-time/td-p/14712098
*/

#target photoshop

app.activeDocument.suspendHistory ("Dupe Selected Group and All Smart Objects as Copies...", "main()");

function main() {

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

    var selectedLayerSet = app.activeDocument.activeLayer;
    if (!(selectedLayerSet instanceof LayerSet)) {
        alert("A layer group must be selected to run this script!");
        // End the script
        return;
    }
    var duplicatedLayerSet = selectedLayerSet.duplicate();
    duplicatedLayerSet.name = selectedLayerSet.name + " copy";
    processActiveGroup(duplicatedLayerSet);


    // Functions

    function processActiveGroup(layerSet) {
        for (var i = layerSet.layers.length - 1; i >= 0; i--) {
            var theSOLayer = layerSet.layers[i];
            if (theSOLayer.kind === LayerKind.SMARTOBJECT) {
                dupeSOasCopy(theSOLayer);
            } else if (theSOLayer.typename === "LayerSet") {
                processActiveGroup(theSOLayer);
            }
        }
    }

    function dupeSOasCopy(theLayer) {
        app.activeDocument.activeLayer = theLayer;
        executeAction(stringIDToTypeID("placedLayerMakeCopy"), undefined, DialogModes.NO);
        var theNewLayer = app.activeDocument.activeLayer;
        // Depends on layer panel options for adding copy
        theNewLayer.name = theLayer.name; //+ " copy";
        theLayer.remove();
    }

}

 

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

 

1 reply

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
July 1, 2024

@huyct1507 

 

You can try this:

 

/*
Dupe Selected Group and All Smart Objects as Copies.jsx
v1.0, 1st July 2024 - Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/can-i-duplicate-groups-contain-smart-objects-but-make-a-new-s-o-via-copy-for-the-same-time/td-p/14712098
*/

#target photoshop

app.activeDocument.suspendHistory ("Dupe Selected Group and All Smart Objects as Copies...", "main()");

function main() {

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

    var selectedLayerSet = app.activeDocument.activeLayer;
    if (!(selectedLayerSet instanceof LayerSet)) {
        alert("A layer group must be selected to run this script!");
        // End the script
        return;
    }
    var duplicatedLayerSet = selectedLayerSet.duplicate();
    duplicatedLayerSet.name = selectedLayerSet.name + " copy";
    processActiveGroup(duplicatedLayerSet);


    // Functions

    function processActiveGroup(layerSet) {
        for (var i = layerSet.layers.length - 1; i >= 0; i--) {
            var theSOLayer = layerSet.layers[i];
            if (theSOLayer.kind === LayerKind.SMARTOBJECT) {
                dupeSOasCopy(theSOLayer);
            } else if (theSOLayer.typename === "LayerSet") {
                processActiveGroup(theSOLayer);
            }
        }
    }

    function dupeSOasCopy(theLayer) {
        app.activeDocument.activeLayer = theLayer;
        executeAction(stringIDToTypeID("placedLayerMakeCopy"), undefined, DialogModes.NO);
        var theNewLayer = app.activeDocument.activeLayer;
        // Depends on layer panel options for adding copy
        theNewLayer.name = theLayer.name; //+ " copy";
        theLayer.remove();
    }

}

 

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