script that converts images into smartobjects and links images to layer shapes

Engaged ,
Sep 10, 2022 Sep 10, 2022

Copy link to clipboard

Copied

I want a script that converts images into smartobjects and links images to layer shapes based on similar numbers between images and layer shapes.

 

I have attached examples with pictures that show what I want

The first picture
I made a model with numbered layer shapes
001.jpg


In the second image
I have inserted numbered image layers with the same number of layer shapes
002.jpg


third picture
I want to convert image layers into smartobjects and link them to the shapes of the layers by making a mask between them and resizing the image layers based on the width of the shapes layers
003.jpg
Thanks for the interest
TOPICS
Actions and scripting , SDK

Views

103

Likes

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

correct answers 2 Correct answers

Community Expert , Sep 14, 2022 Sep 14, 2022

@Mohamed Hameed 

 

Test the following with care, it hasn't had exhaustive testing, however, as it is based on previous scripts most of the wrinkles have hopefully been ironed out.

 

/*
Apply Clipping Mask to All Smart Object Layers.jsx
v1.0, Stephen Marsh, 14th September 2022
https://community.adobe.com/t5/photoshop-ecosystem-discussions/script-that-converts-images-into-smartobjects-and-links-images-to-layer-shapes/td-p/13191501
With special thanks to Christoph Pfaffenbichler for the recursive S
...

Likes

Translate

Translate
Community Expert , Sep 14, 2022 Sep 14, 2022

Try this 1.1 version:

 

/*
Apply Clipping Mask to All Smart Object Layers.jsx
v1.1, Stephen Marsh, 14th September 2022
https://community.adobe.com/t5/photoshop-ecosystem-discussions/script-that-converts-images-into-smartobjects-and-links-images-to-layer-shapes/td-p/13191501
With special thanks to Christoph Pfaffenbichler for the recursive SO processing framework.
Note: Assumes that there is a pair of layers, with the upper layer a smart object and the lower layer content acting as the source for
...

Likes

Translate

Translate
Community Expert ,
Sep 13, 2022 Sep 13, 2022

Copy link to clipboard

Copied

This is similar to the late JJMack's BatchMultiImageCollage.jsx:

 

https://github.com/MarshySwamp/JJMack-Archive

 

It uses alpha channels instead of shape layers.

Likes

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
Engaged ,
Sep 13, 2022 Sep 13, 2022

Copy link to clipboard

Copied

Sorry, but I found many files and scripts and it is based on previously saved templates

I came up with a way to convert image layers into smartobjects and filter and arrange layers by numbers

I just want a script that makes a mask between the image layer and the shape layer for all layers sequentially according to numbers

Likes

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 ,
Sep 13, 2022 Sep 13, 2022

Copy link to clipboard

Copied

Sounds like all you need to do is script making a clipping group, then run it over all the layers in a loop... and it sounds like you know how to do this for all layers anyway, so:

 

app.runMenuItem(stringIDToTypeID('groupEvent'));

 

or

 

createClippingMask();

function createClippingMask() {
var idgroupEvent = stringIDToTypeID( "groupEvent" );
    var desc219 = new ActionDescriptor();
    var idnull = stringIDToTypeID( "null" );
        var ref10 = new ActionReference();
        var idlayer = stringIDToTypeID( "layer" );
        var idordinal = stringIDToTypeID( "ordinal" );
        var idtargetEnum = stringIDToTypeID( "targetEnum" );
        ref10.putEnumerated( idlayer, idordinal, idtargetEnum );
    desc219.putReference( idnull, ref10 );
executeAction( idgroupEvent, desc219, DialogModes.NO );
}

 

If this isn't the case, please provide a screenshot of the layers panel from where your current script leaves things. Providing your code may also help.

 

Likes

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
Engaged ,
Sep 13, 2022 Sep 13, 2022

Copy link to clipboard

Copied

Sorry dear
I meant that I have a script that converts the image layers inside the list of layers to a samrt . object
I just need the process of associating each image layer with the shape layer below it or tracing it with the same number
I tried the code you attached but it doesn't work on selected layers or all layers

Likes

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 ,
Sep 13, 2022 Sep 13, 2022

Copy link to clipboard

Copied

Please provide screenshots, sample code and or PSD layered examples to help others to try to help you!

Likes

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 ,
Sep 13, 2022 Sep 13, 2022

Copy link to clipboard

Copied


@Mohamed Hameed wrote:

... it is based on previously saved templates


 

So why can't you create your layout as a previously saved template with alpha channels named Image 1, Image 2 etc? Why re-invent the wheel to work with vector shape layer clipping masks?

Likes

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
Engaged ,
Sep 13, 2022 Sep 13, 2022

Copy link to clipboard

Copied

I have already made saved templates in order to work on them.. but my working conditions sometimes require me to work on different styles and prepare the images

I want a flexible code that handles any number of images, not a number of static or selected images


The code I used to convert image layers to a Smart Object is a code that was previously taken by this forum by Kukurykus.

https://community.adobe.com/t5/photoshop-ecosystem-discussions/script-that-converts-layers-to-separa... 

 

I have attached the psd file with the image layers and under each image layer there is a shape layer that I want to link between them

https://drive.google.com/file/d/1wKzTxX07Is0PfrwgHdu6X9F-S2urHr71/view?usp=sharing 

 

 

Likes

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 ,
Sep 14, 2022 Sep 14, 2022

Copy link to clipboard

Copied

@Mohamed Hameed - I have worked on a semiautomatic based action as a proof of concept. 

I'll look into adapting this into an automated loop later this evening.

Likes

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 ,
Sep 14, 2022 Sep 14, 2022

Copy link to clipboard

Copied

@Mohamed Hameed 

 

Test the following with care, it hasn't had exhaustive testing, however, as it is based on previous scripts most of the wrinkles have hopefully been ironed out.

 

/*
Apply Clipping Mask to All Smart Object Layers.jsx
v1.0, Stephen Marsh, 14th September 2022
https://community.adobe.com/t5/photoshop-ecosystem-discussions/script-that-converts-images-into-smartobjects-and-links-images-to-layer-shapes/td-p/13191501
With special thanks to Christoph Pfaffenbichler for the recursive SO processing framework.
Note: Assumes that there is a pair of layers, with the upper layer a smart object and the lower layer content acting as the source for the clipping mask.
      No special checks or validation are performed to ensure that the layers are in pairs.
*/

#target photoshop

var myDocument = app.activeDocument;
myDocument.suspendHistory("processAllSmartObjects", "processSOLayers(myDocument)");

function processSOLayers(theParent) {
    for (var m = theParent.layers.length - 1; m >= 0; m--) {
        var theLayer = theParent.layers[m];
        // apply the function to layers; 
        if (theLayer.typename == "ArtLayer") {
            if (theLayer.kind == LayerKind.SMARTOBJECT) {
                var theVisibility = theLayer.visible;
                myDocument.activeLayer = theLayer;
                app.runMenuItem(stringIDToTypeID('groupEvent'));
                theLayer.visible = theVisibility;
            }
        // Run on the contents of layerSets
        } else {
            processSOLayers(theLayer)
        }
    }
    return;
}

 

Likes

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
Engaged ,
Sep 14, 2022 Sep 14, 2022

Copy link to clipboard

Copied

@Stephen_A_Marsh 

Thank you for your great and wonderful effort

Likes

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
Engaged ,
Sep 14, 2022 Sep 14, 2022

Copy link to clipboard

Copied

@Stephen_A_Marsh 

The code is excellent and does what is required well and excellent

- But I'd like something else if it doesn't bother you

After the linking process, I want to align the image layer and the shape layer from the top and left because most of the image layers are identical to the shape layers

- If there is a problem in this mode, there is no problem
Thanks for your hard work and effort

Likes

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 ,
Sep 14, 2022 Sep 14, 2022

Copy link to clipboard

Copied

Try this 1.1 version:

 

/*
Apply Clipping Mask to All Smart Object Layers.jsx
v1.1, Stephen Marsh, 14th September 2022
https://community.adobe.com/t5/photoshop-ecosystem-discussions/script-that-converts-images-into-smartobjects-and-links-images-to-layer-shapes/td-p/13191501
With special thanks to Christoph Pfaffenbichler for the recursive SO processing framework.
Note: Assumes that there is a pair of layers, with the upper layer a smart object and the lower layer content acting as the source for the clipping mask.
      No special checks or validation are performed to ensure that the layers are in pairs.
*/

#target photoshop

var myDocument = app.activeDocument;
myDocument.suspendHistory("processAllSmartObjects", "processSOLayers(myDocument)");

function processSOLayers(theParent) {
    for (var m = theParent.layers.length - 1; m >= 0; m--) {
        var theLayer = theParent.layers[m];
        // apply the function to layers; 
        if (theLayer.typename == "ArtLayer") {
            if (theLayer.kind == LayerKind.SMARTOBJECT) {
                var theVisibility = theLayer.visible;
                myDocument.activeLayer = theLayer;
                app.runMenuItem(stringIDToTypeID('groupEvent'));
                selectForwardORBackwardLayer("backwardEnum");
                selectionFromVectorMask();
                align2Selection('AdLf');
                align2Selection('AdTp'); 
                activeDocument.selection.deselect();
                theLayer.visible = theVisibility;
            }
        // Run on the contents of layerSets
        } else {
            processSOLayers(theLayer)
        }
    }
    return;
}


// Functions

function selectionFromVectorMask() {
	function s2t(s) {
        return app.stringIDToTypeID(s);
    }
	var descriptor = new ActionDescriptor();
	var reference = new ActionReference();
	var reference2 = new ActionReference();
	reference.putProperty( s2t( "channel" ), s2t( "selection" ));
	descriptor.putReference( s2t( "null" ), reference );
	reference2.putEnumerated( s2t( "path" ), s2t( "path" ), s2t( "vectorMask" ));
	reference2.putEnumerated( s2t( "layer" ), s2t( "ordinal" ), s2t( "targetEnum" ));
	descriptor.putReference( s2t( "to" ), reference2 );
	descriptor.putInteger( s2t( "version" ), 1 );
	descriptor.putBoolean( s2t( "vectorMaskParams" ), true );
	executeAction( s2t( "set" ), descriptor, DialogModes.NO );
}

function selectForwardORBackwardLayer(forwardORbackward) {
	function s2t(s) {
        return app.stringIDToTypeID(s);
    }
	var descriptor = new ActionDescriptor();
	var list = new ActionList();
    var reference = new ActionReference();
    // "forwardEnum" or "backwardEnum"
	reference.putEnumerated( s2t( "layer" ), s2t( "ordinal" ), s2t( forwardORbackward ));
	descriptor.putReference( s2t( "null" ), reference );
	descriptor.putEnumerated( s2t( "selectionModifier" ), s2t( "selectionModifierType" ), s2t( "addToSelection" ));
	descriptor.putBoolean( s2t( "makeVisible" ), false );
	list.putInteger( 10 );
	list.putInteger( 30 );
	descriptor.putList( s2t( "layerID" ), list );
	executeAction( s2t( "select" ), descriptor, DialogModes.NO );
}

function align2Selection(method) {
   /* https://gist.github.com/MarshySwamp/df372e342ac87854ffe08e79cbdbcbb5 */
    var desc = new ActionDescriptor();
    var ref = new ActionReference();
    ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
    desc.putReference(charIDToTypeID("null"), ref);
    desc.putEnumerated(charIDToTypeID("Usng"), charIDToTypeID("ADSt"), charIDToTypeID(method));
    try {
        executeAction(charIDToTypeID("Algn"), desc, DialogModes.NO);
    } catch (e) {}
}

 

Likes

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
Engaged ,
Sep 14, 2022 Sep 14, 2022

Copy link to clipboard

Copied

LATEST

@Stephen_A_Marsh 

You are really amazing and creative
You are a good and respectful man who does not skimp on anyone to help

Likes

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

Save time with Adobe Express quick actions