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

repeats the layer , Sort Layer and Auto Arrange by position

Enthusiast ,
Jan 04, 2022 Jan 04, 2022

Copy link to clipboard

Copied

welcome everybody
- First: I want a code that repeats the layer according to a certain number.

Second: I have a number of layers that I want to sort by position
I have attached a picture of exactly what I want
Thanks for the interest

TOPICS
Actions and scripting , SDK

Views

662

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 1 Correct answer

Community Expert , Jan 05, 2022 Jan 05, 2022

Votes

Translate

Translate
Adobe
Enthusiast ,
Jan 04, 2022 Jan 04, 2022

Copy link to clipboard

Copied

Example.jpg

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
Guide ,
Jan 04, 2022 Jan 04, 2022

Copy link to clipboard

Copied

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
LEGEND ,
Jan 04, 2022 Jan 04, 2022

Copy link to clipboard

Copied

Loll I thought of the same thread, but couldn't find it.

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
Enthusiast ,
Jan 05, 2022 Jan 05, 2022

Copy link to clipboard

Copied

@jazz-y @Kukurykus 

I found the same code but for Illustrator
Does this code do the same thing but modify it?
But I don't know how to edit it

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
Enthusiast ,
Jan 05, 2022 Jan 05, 2022

Copy link to clipboard

Copied

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
Enthusiast ,
Jan 05, 2022 Jan 05, 2022

Copy link to clipboard

Copied

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
LEGEND ,
Jan 05, 2022 Jan 05, 2022

Copy link to clipboard

Copied

I don't use Illustrator

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 ,
Jan 05, 2022 Jan 05, 2022

Copy link to clipboard

Copied

A very simple for loop to repeat the active layer by a variable amount of times in my script here:

 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/creating-duplicate-images-for-multi-p...

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
Enthusiast ,
Jan 05, 2022 Jan 05, 2022

Copy link to clipboard

Copied

@Stephen_A_Marsh 

The code is really nice, but I don't want the layers to be merged after it's repeated

 

Is it possible to use this symbol on selected or existing layers

not the layer that has been duplicated?

Like the picture attached to this article

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 ,
Jan 05, 2022 Jan 05, 2022

Copy link to clipboard

Copied

1) Your post reads as two separate questions. 

 

You wrote:

"First: I want a code that repeats the layer according to a certain number."

 

I was referring to one specific "for" loop function to repeat an active layer N number of times, not the entire script. All the function does is duplicate the layer from a variable number input.

 

Specifically:

 

var count = 5;
    for (var i = 0; i < count; i++) {
        doc.activeLayer.duplicate();
    }

 

What you do after that is up to you.

 

2) Your second question has many different approaches, depending on the structure of your layers. This is impossible to comment on from a screenshot. This is covered in the link provided by jazz-y to another forum post.

 

You would be best posting a link to the layered PSD so that the layer structure can be examined from a programming viewpoint (not a visual one).

 

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
Enthusiast ,
Jan 05, 2022 Jan 05, 2022

Copy link to clipboard

Copied

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 ,
Jan 05, 2022 Jan 05, 2022

Copy link to clipboard

Copied

Unless this is representative of a real production file, it is hard to offer any useful advice. Once I deleted off the "after" stuff, I was left with layers 1-9 running sequentially from bottom to top. So if production files were the same, then one could select them in turn by layer ID and position them into columns and rows:

 

layerid.png

 

EDIT: If you had each layer saved as a separate file, there are scripts that that can combine the separate files into a grid layout.

 

https://www.andrewnoske.com/wiki/Adobe_Photoshop_-_Scripts_Related_to_Montaging

 

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
Enthusiast ,
Jan 05, 2022 Jan 05, 2022

Copy link to clipboard

Copied

@Stephen_A_Marsh 

These layers are for illustration not the actual application of the project
Model without repeating layers
Please this link

https://drive.google.com/file/d/1dQpcmzWCDX5ESHCMNtG_yA_pY60IWuVt/view?usp=sharing 

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 ,
Jan 05, 2022 Jan 05, 2022

Copy link to clipboard

Copied

Having the after layers and other stuff complicates this and it is no longer representative of a raw production file. Please provide separate files for before and after so that the before file is truly representative of a production file.

 

I'll give it a look...

 

EDIT: OK the layers don't appear to be in any "consistent or logical" order for automated selection for the final layout compared to the layer stacking order.

 

How are the layers added to the document in the first place? Please describe the workflow step by step, dragging this out like this is painful.

 

Can the layers be automated to use a pre-defined, consistent name or placement order that reflects what you wish to achive in your step and repeat layout?

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 ,
Jan 05, 2022 Jan 05, 2022

Copy link to clipboard

Copied

A good alternative option is create a template, then use one of JJMack's scripts to populate the template with the images.

 

http://www.mouseprints.net/old/dpr/PhotoCollageToolkit.html

 

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
Enthusiast ,
Jan 05, 2022 Jan 05, 2022

Copy link to clipboard

Copied

@Stephen_A_Marsh @Kukurykus @jazz-y 

Well, I will suggest an idea, but the implementation I don't know how to do
What if we select and name the layers, choose layer number 1, and move it to the first design from the top left, then repeat the same movement next to the position of the first layer, then the second, then the third and so on
Is this possible or not?
If it was difficult, well, thank you for your concern and effort

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
LEGEND ,
Jan 05, 2022 Jan 05, 2022

Copy link to clipboard

Copied

Don't use our names this way, unless you see anyone not attending here is willing to help.

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
Enthusiast ,
Jan 05, 2022 Jan 05, 2022

Copy link to clipboard

Copied

quote

Don't use our names this way, unless you see anyone not attending here is willing to help.


Well I'm sorry I didn't mention names until I saw all of you posting solutions
I didn't mean to mention the names on purpose
Well, I'm sorry again

 

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 ,
Jan 05, 2022 Jan 05, 2022

Copy link to clipboard

Copied

That is what I suggested by using a logical layer name and or placement order.

 

Only you know the workflow and how the images are added as layers in the order and naming shown. If you design the workflow with automation in mind things will be easier.

 

If one could select layers by consistent and logical names, then an action could do this without need of scripting.


Presuming that this layout will always be consistent of course... Always 3x3 layout, same resolution, same positions and spacing etc.

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
Enthusiast ,
Jan 05, 2022 Jan 05, 2022

Copy link to clipboard

Copied

@Stephen_A_Marsh 

This code does a really nice job

https://community.adobe.com/t5/photoshop-ecosystem-discussions/creating-duplicate-images-for-multi-p... 

, but on layers that are iterated

 

Is it possible to change the mechanism of this code to be executed on the specified number of layers or is it difficult?

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 ,
Jan 05, 2022 Jan 05, 2022

Copy link to clipboard

Copied

Bits of the code could be used. As mentioned, your main issue is that you have 9 layers that are not in any consistent order or naming that could be used for automation.

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
Enthusiast ,
Jan 05, 2022 Jan 05, 2022

Copy link to clipboard

Copied

@Stephen_A_Marsh 

OK ..
Does the code work in the pattern of numbers or names, as if the names of the layers were changed
What modification will be made in the code to perform this action?

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
Guide ,
Jan 05, 2022 Jan 05, 2022

Copy link to clipboard

Copied

LATEST

I have a code that I wrote for a completely different task (automatic align and fit selected layers to frames), but after a slight modification it can solve your problem.

Input state:

1. The layers to be sorted and the frames must go in the same order.

2. Layers and frames must be marked with the same label color

3. Before starting work, the layers that need to be placed in frames must be selected.

 

 

#target photoshop

var lr = new AM('layer'),
    doc = new AM('document'),
    previousLayer = new AM('layer', 'backwardEnum');

activeDocument.suspendHistory('Align and fit subject', 'alignAndFit()')
function alignAndFit() { app.doProgress('', 'main ()') }

function main() {

    var subjects = [],
        subjectColors = {},
        subjectIds = {},
        frames = [],
        frameColors = {},
        targetIds = doc.getProperty('targetLayersIDs');

    app.updateProgress(1, 4)

    for (var i = 0; i < targetIds.count; i++) {
        var subject = lr.descToObject(lr.getProperty('bounds', false, (id = targetIds.getReference(i).getIdentifier('layerID'))))

        with (subject) {
            subject.width = right - left
            subject.height = bottom - top
            subject.center = { y: top + height / 2, x: left + width / 2 }
            subject.vertical = bottom - top > right - left
            subject.ratio = width / height
        }

        subject.color = lr.getProperty('color')[1]
        subject.id = id

        if (!subjectColors[subject.color]) subjectColors[subject.color] = []
        subjectColors[subject.color].push(id)
        subjectIds[id] = subject.color
        subjects.push(subject)

        if (subject.color == 'none') break;
    }

    subjects.sort(function (a, b) { return a.ratio > b.ratio ? 1 : -1 })

    if (subjects.length > 1) {
        var from = doc.getProperty('hasBackgroundLayer') ? 0 : 1,
            len = doc.getProperty('numberOfLayers');

        for (var i = from; i <= len; i++) {
            if (lr.getProperty('layerSection', false, i, true)[1] == 'layerSectionEnd') continue;
            if (subjectIds[id = lr.getProperty('layerID', false, i, true)]) continue;
            var color = lr.getProperty('color', false, i, true)[1];
            if (color != 'none') {
                if (!frameColors[color]) frameColors[color] = []
                frameColors[color].push(id)
            }
        }
    } else {
        frameColors[color = previousLayer.getProperty('color')[1]] = []
        frameColors[color].push(previousLayer.getProperty('layerID'))
    }
    for (var a in subjectColors) {
        if (frameColors[a]) {
            frames = frames.concat(frameColors[a])
        }
    }

    app.updateProgress(2, 4)

    for (var i = 0; i < frames.length; i++) {
        var frame = lr.descToObject(lr.getProperty('bounds', false, frames[i]))

        with (frame) {
            frame.height = bottom - top
            frame.width = right - left
            frame.center = { y: top + height / 2, x: left + width / 2 }
            frame.vertical = bottom - top > right - left
            frame.ratio = width / height
        }

        frame.color = lr.getProperty('color', false, frames[i])[1]
        frame.id = lr.getProperty('layerID', false, frames[i])
        frame.processed = false
        frames[i] = frame
    }

    frames.sort(function (a, b) { return a.ratio > b.ratio ? 1 : -1 })

    app.updateProgress(3, 4)

    var offset = doc.getProperty('hasBackgroundLayer') ? 1 : 0
    for (var i = 0; i < subjects.length; i++) {
        app.changeProgressText('Align layer: ' + lr.getProperty('name', false, subjects[i].id))
        for (var x = 0; x < frames.length; x++) {
            if (frames[x].processed) continue;
            if (frames[x].color != subjects[i].color) continue;

            doc.moveLayer(lr.getProperty('itemIndex', false, subjects[i].id) - offset, lr.getProperty('itemIndex', false, frames[x].id) >= lr.getProperty('count', false, frames[x].id) ? lr.getProperty('count', false, frames[x].id) - 1 : lr.getProperty('itemIndex', false, frames[x].id))

            lr.selectLayer(subjects[i].id)
            if (!lr.getProperty('group', false, subjects[i].id)) lr.groupCurrentLayer()
            alignLayer(subjects[i], frames[x])
            frames[x].processed = true
            break;
        }
    }

}

function alignLayer(subject, frame) {
    var dH = frame.center.x - subject.center.x,
        dV = frame.center.y - subject.center.y,
        sW = frame.width / subject.width * 100,
        sH = frame.height / subject.height * 100,
        scale = sW > sH ? sW : sH

    lr.transform(dH, dV, scale, subject.center.x, subject.center.y)
}

function AM(target, order) {
    var s2t = stringIDToTypeID,
        t2s = typeIDToStringID;

    target = s2t(target)

    this.getProperty = function (property, descMode, id, idxMode) {
        property = s2t(property);
        (r = new ActionReference()).putProperty(s2t('property'), property);
        id != undefined ? (idxMode ? r.putIndex(target, id) : r.putIdentifier(target, id)) :
            r.putEnumerated(target, s2t('ordinal'), order ? s2t(order) : s2t('targetEnum'));
        return descMode ? executeActionGet(r) : getDescValue(executeActionGet(r), property)
    }

    this.descToObject = function (d) {
        var o = {}
        for (var i = 0; i < d.count; i++) {
            var k = d.getKey(i)
            o[t2s(k)] = getDescValue(d, k)
        }
        return o
    }

    this.selectLayer = function (id, add) {
        add = (add == undefined) ? add = false : add;
        (r = new ActionReference()).putIdentifier(s2t('layer'), id);
        (d = new ActionDescriptor()).putReference(s2t('null'), r);
        if (add) { d.putEnumerated(s2t('selectionModifier'), s2t('selectionModifierType'), s2t('addToSelection')) }
        d.putBoolean(s2t('makeVisible'), false)
        executeAction(s2t('select'), d, DialogModes.NO)
    }

    this.moveLayer = function (from, to) {
        (r = new ActionReference()).putIndex(s2t('layer'), from);
        (d = new ActionDescriptor()).putReference(s2t('null'), r);
        (r1 = new ActionReference()).putIndex(s2t('layer'), to);
        d.putReference(s2t('to'), r1);
        executeAction(s2t('move'), d, DialogModes.NO);
    }

    this.groupCurrentLayer = function () {
        (r = new ActionReference()).putEnumerated(s2t('layer'), s2t('ordinal'), s2t('targetEnum'));
        (d = new ActionDescriptor()).putReference(s2t('null'), r);
        executeAction(s2t('groupEvent'), d, DialogModes.NO);
    }

    this.transform = function (dX, dY, scale, x, y) {
        (r = new ActionReference()).putEnumerated(s2t('layer'), s2t('ordinal'), s2t('targetEnum'));
        (d = new ActionDescriptor()).putReference(s2t('null'), r);
        d.putEnumerated(s2t('freeTransformCenterState'), s2t('quadCenterState'), s2t('QCSIndependent'));
        ((d1 = new ActionDescriptor())).putUnitDouble(s2t('horizontal'), s2t('pixelsUnit'), x);
        d1.putUnitDouble(s2t('vertical'), s2t('pixelsUnit'), y);
        d.putObject(s2t('position'), s2t('paint'), d1);
        (d2 = new ActionDescriptor()).putUnitDouble(s2t('horizontal'), s2t('pixelsUnit'), dX);
        d2.putUnitDouble(s2t('vertical'), s2t('pixelsUnit'), dY);
        d.putObject(s2t('offset'), s2t('offset'), d2);
        d.putUnitDouble(s2t('width'), s2t('percentUnit'), scale);
        d.putUnitDouble(s2t('height'), s2t('percentUnit'), scale);
        d.putEnumerated(s2t('interfaceIconFrameDimmed'), s2t('interpolationType'), s2t('bicubic'));
        executeAction(s2t('transform'), d, DialogModes.NO);
    }

    function getDescValue(d, p) {
        switch (d.getType(p)) {
            case DescValueType.OBJECTTYPE: return (d.getObjectValue(p));
            case DescValueType.LISTTYPE: return d.getList(p);
            case DescValueType.REFERENCETYPE: return d.getReference(p);
            case DescValueType.BOOLEANTYPE: return d.getBoolean(p);
            case DescValueType.STRINGTYPE: return d.getString(p);
            case DescValueType.INTEGERTYPE: return d.getInteger(p);
            case DescValueType.LARGEINTEGERTYPE: return d.getLargeInteger(p);
            case DescValueType.DOUBLETYPE: return d.getDouble(p);
            case DescValueType.ALIASTYPE: return d.getPath(p);
            case DescValueType.CLASSTYPE: return d.getClass(p);
            case DescValueType.UNITDOUBLE: return (d.getUnitDoubleValue(p));
            case DescValueType.ENUMERATEDTYPE: return [t2s(d.getEnumerationType(p)), t2s(d.getEnumerationValue(p))];
            default: break;
        };
    }
}

 

 

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