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

PSD file structure

New Here ,
Jun 27, 2021 Jun 27, 2021

Copy link to clipboard

Copied

Is it possible to make a script that writes the structure of file to text document?

4popILD

— Слой 1

— Слой 2

— Группа 1

— — Слой 4

— — Группа 2

— — — Слой 5

— — Слой 3

TOPICS
Actions and scripting

Views

680

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
Valorous Hero ,
Jun 27, 2021 Jun 27, 2021

Copy link to clipboard

Copied

alert(print_folder(activeDocument, -1));

function print_folder(f, level)
    {
    try {
        var result = "";

        for (var n = 0; n < level; n++) result += "- ";

        if (f.typename == "LayerSet") result += f.name + "\n";

        ++level;

        for (var i = 0; i < f.layers.length; i++)
            {
            if (f.layers[i].typename == "LayerSet") 
                {
                result += print_folder(f.layers[i], level);
                }
            else 
                {
                for (var n = 0; n < level; n++) result += "- ";

                result += f.layers[i].name + "\n";
                }
            }

        return result;
        }
    catch (e) { alert(e); }        
    }

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 ,
Jun 27, 2021 Jun 27, 2021

Copy link to clipboard

Copied

 

ids = [], tbltr = txt = ''; (function(v1, v2) {
	var lrs = [].slice.call(v1); while(lrs.length) {
		currentLayerSets = '(?=(,?' + v2 + ')).*'
		strng = String(ids).replace(RegExp(currentLayerSets), '$1')
		if ((ids = strng ? strng.split(',') : Array()).length) tbltr +='\t'
		txt += (tbltr = tbltr.slice(0, ids.length)) + (shft = lrs.shift()).name + '\n'
		if (shft.typename != 'ArtLayer') ids.push(shft.id), callee(shft.layers, shft.id)
	}
})(activeDocument.layers, ''), strctr = '/strctr.txt'; with
(File(Folder.desktop + strctr)) open('w'), write(txt), close()

 

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 ,
Jun 27, 2021 Jun 27, 2021

Copy link to clipboard

Copied

— Layer 1
— Layer 2
— Group 1
— — Layer 4
— — Group 2
— — — Layer 5
— — Layer 3

 

#target photoshop

var layers = new AM()
layers.writeToFile(Folder.desktop + '/strctr.txt')

function AM() {
    s2t = stringIDToTypeID;
    t2s = typeIDToStringID;

    (r = new ActionReference()).putProperty(s2t('property'), p = s2t('hasBackgroundLayer'));
    r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
    var indexFrom = executeActionGet(r).getBoolean(p) ? 0 : 1;

    (r = new ActionReference()).putProperty(s2t('property'), p = s2t('numberOfLayers'));
    r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'))
    var indexTo = executeActionGet(r).getInteger(p);

    this.layers = parseLayers(indexFrom, indexTo)

    this.writeToFile = function (pth) {
        var f = File(pth)
        f.open('w'); f.write(makeTXT(this.layers, '', '')); f.close()
    }

    function parseLayers(from, to, parentObj) {
        parentObj = parentObj ? parentObj : {}
        for (var i = from; i <= to; i++) {
            (r = new ActionReference()).putProperty(s2t('property'), p = s2t('layerSection'));
            r.putIndex(s2t('layer'), i);
            var section = t2s(executeActionGet(r).getEnumerationValue(p));

            if (section == 'layerSectionEnd') {
                i = parseLayers(i + 1, to, parentObj[i] = {});
                continue;
            }

            var properties = {};
            (r = new ActionReference()).putProperty(s2t('property'), p = s2t('name'));
            r.putIndex(s2t('layer'), i);
            properties.name = executeActionGet(r).getString(p);

            if (section == 'layerSectionStart') {
                for (o in properties) { parentObj[o] = properties[o] }
                return i;
            } else { parentObj[i] = properties }
        }
        return parentObj
    }

    function makeTXT(layers, prefix, txt) {
        var l = layers.reflect.properties.length - 1;
        for (var i = l; i >= 0; i--) {
            var k = layers.reflect.properties[i].toString();
            if (k == '__proto__' || k == '__count__' || k == '__class__' || k == 'reflect') continue;
            var v = layers[k];
            switch (typeof (v)) {
                case 'object': txt = makeTXT(v, prefix + '— ', txt); break;
                default: txt += prefix + v + '\n'; break;
            }
        }
        return txt
    }
}

 

 

 

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 ,
Jun 27, 2021 Jun 27, 2021

Copy link to clipboard

Copied

LATEST

@r-bin , @jazz-y , @Kukurykus , when it comes to Photoshop Scripting your contributions on this Forum are quite impressive! 

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