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

How to write this script

Explorer ,
Feb 23, 2022 Feb 23, 2022

Copy link to clipboard

Copied

I need a script to export 20.000 pdf. 

Every one of them should be different based on numbers.

Every number has its own color.

It should make an export from 153942 to 173942

How can i make this work ?

Thanks for suggestions.

32d849d2-bbd3-4df6-98b0-8351d89f9191.jpg

TOPICS
Actions and scripting , Windows

Views

558

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

Guide , Feb 24, 2022 Feb 24, 2022

I have no information about what your file requirements are, what version of Photoshop and other things... Therefore, I am writing my own solution, which will definitely work in the latest version of Photoshop. If necessary, you can make changes and adapt it yourself.

 

Required preparation:

1. Create layout with numbers from 0 to 9. You can use any colors, any shapes, the main thing is that:

a) one layer contains one number

b) the layer is named as the same number that is shown on it (no ad

...

Votes

Translate

Translate
Adobe
LEGEND ,
Feb 23, 2022 Feb 23, 2022

Copy link to clipboard

Copied

Not enough information. What are you starting with?

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 ,
Feb 23, 2022 Feb 23, 2022

Copy link to clipboard

Copied

It may sound strange, but it can be done with the help of actions and a standard batch processor. The script here, perhaps, can only be used to automatically rename files. I tried to make numbers from 1 to 100 - without prior preparation it took a little over 5 minutes.

 

Yes, with each new discharge, the number of operations in the action will increase, but you will not need much time to prepare. Photoshop will take longer to generate files (maybe it's not the best tool for such tasks and you should find out how this task was solved for the previous 153941 numbers)

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
Explorer ,
Feb 23, 2022 Feb 23, 2022

Copy link to clipboard

Copied

would like to know also, with the way u showed probally it will take me three days to get files i want,
Firstly i should generate numbers, barcodes

than place them to main file and export. 

 

Thank you for helping me.

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 ,
Feb 24, 2022 Feb 24, 2022

Copy link to clipboard

Copied

I have no information about what your file requirements are, what version of Photoshop and other things... Therefore, I am writing my own solution, which will definitely work in the latest version of Photoshop. If necessary, you can make changes and adapt it yourself.

 

Required preparation:

1. Create layout with numbers from 0 to 9. You can use any colors, any shapes, the main thing is that:

a) one layer contains one number

b) the layer is named as the same number that is shown on it (no additional characters)

c) the layers are located one above others

2022-02-24_11-45-59.png

2. Create digit groups. Name the group with ones "1", the group with tens "10", the group with hundreds "100", and so on. Each group should contain inside it layers with numbers from 0 to 9 (the ones you created in step 1)

2022-02-24_11-46-28.png

3. Arrange groups with numbers in your layout as you like 4.

2022-02-24_11-46-42.png

4. BE SURE to select these groups before running the script (the script polls only the selected layers)

2022-02-24_11-47-01.png

6. Run script

 

#target photoshop
var apl = new AM('application'),
    doc = new AM('document'),
    lr = new AM('layer');
if (apl.getProperty('numberOfDocuments')) {
    if (doc.getProperty('numberOfLayers')) {
        var targetLayers = doc.hasProperty('targetLayersIDs') ? doc.getProperty('targetLayersIDs') : [],
            pth = (doc.getProperty('fileReference')).path,
            selection = [];
        if (targetLayers) {
            for (var i = 0; i < targetLayers.count; i++) {
                var id = targetLayers.getReference(i).getIdentifier(stringIDToTypeID('layerID'))
                if (lr.getProperty('layerKind', id) == 7) selection.push(id)
            }
        }
        if (selection) {
            var digits = collectLayers(selection);
            for (var i = 153942; i <= 153950; i++) makeFile(i, digits, selection)
        }
    }
}
function collectLayers(s, o) {
    o = o ? o : {};
    for (var i = 0; i < s.length; i++) {
        o[Number(lr.getProperty('name', s[i]))] = getLayersList(s[i]);
    }
    return o;
    function getLayersList(id) {
        var idx = lr.getProperty('itemIndex', id),
            indexFrom = doc.getProperty('hasBackgroundLayer') ? --idx : idx,
            o = {};
        for (var i = indexFrom; i >= 1; i--) {
            var layerSection = lr.getProperty('layerSection', i, true).value
            if (layerSection == 'layerSectionStart') continue;
            if (layerSection == 'layerSectionEnd') break;
            o[Number(lr.getProperty('name', i, true))] = lr.getProperty('layerID', i, true);
        }
        return o
    }
}
function setDigits(o, digit) {
    var ids = []
    for (var a in o) ids.push(o[a])
    doc.visiblity(ids)
    doc.visiblity([o[digit]], true)
}
function makeFile(n, o, digits) {
    var fixed = '';
    for (var i = 0; i < digits.length; i++) fixed += '0'
    var num = (fixed + String(n)).substr(-digits.length),
        len = num.length - 1,
        div = 1;
    for (var i = len; i >= 0; i--) {
        var cur = Number(num.substr(i, 1))
        setDigits(o[div], cur)
        div = div * 10
    }
    doc.saveAsPDF(File(pth + '/' + num))
}
function AM(target, order) {
    var s2t = stringIDToTypeID,
        t2s = typeIDToStringID;
    target = target ? s2t(target) : null;
    this.getProperty = function (property, 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 getDescValue(executeActionGet(r), property)
    }
    this.hasProperty = function (property, id, idxMode) {
        property = s2t(property);
        (r = new ActionReference()).putProperty(s2t('property'), property);
        id ? (idxMode ? r.putIndex(target, id) : r.putIdentifier(target, id))
            : r.putEnumerated(target, s2t('ordinal'), order ? s2t(order) : s2t('targetEnum'));
        return executeActionGet(r).hasKey(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.selectLayerByIDList = function (IDList) {
        var ref = new ActionReference()
        for (var i = 0; i < IDList.length; i++) {
            ref.putIdentifier(s2t('layer'), IDList[i])
        }
        var desc = new ActionDescriptor()
        desc.putReference(s2t('target'), ref)
        desc.putBoolean(s2t('makeVisible'), false)
        executeAction(s2t('select'), desc, DialogModes.NO)
    }
    this.visiblity = function (ids, show) {
        var mode = show ? 'show' : 'hide',
            r = new ActionReference();
        do { r.putIdentifier(s2t('layer'), ids.shift()) } while (ids.length)
        (l = new ActionList()).putReference(r);
        (d = new ActionDescriptor()).putList(s2t("target"), l);
        executeAction(s2t(mode), d, DialogModes.NO);
    }
    this.saveAsPDF = function (fle) {
        (d = new ActionDescriptor()).putObject(s2t("as"), s2t("photoshopPDFFormat"), new ActionDescriptor());
        d.putPath(s2t("in"), fle);
        d.putBoolean(s2t("copy"), true);
        d.putBoolean(s2t("layers"), false);
        d.putEnumerated(s2t("saveStage"), s2t("saveStageType"), s2t("saveBegin"));
        executeAction(s2t("save"), d, DialogModes.NO);
    }
    function getDescValue(d, p) {
        switch (d.getType(p)) {
            case DescValueType.OBJECTTYPE: return { type: t2s(d.getObjectType(p)), value: 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 { type: t2s(d.getEnumerationType(p)), value: t2s(d.getEnumerationValue(p)) };
            default: break;
        };
    }
}

 

At the moment, you see in the script a loop that generates numbers from 153942 to 153950.

 

for (var i = 153942; i <= 153950; i++) makeFile(i, digits, selection)

 

Just change them to the values that you need. The file on which I tested this script (with an example of layering) is attached.

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
Explorer ,
Feb 24, 2022 Feb 24, 2022

Copy link to clipboard

Copied

  • You are the best, thank you. IT WORKS!

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
Explorer ,
Feb 24, 2022 Feb 24, 2022

Copy link to clipboard

Copied

Edit : Seems like it has some problems when using spesific numbers
For example if i change values to 000133 - 000143 it exports 

000091 - 000099

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 ,
Feb 24, 2022 Feb 24, 2022

Copy link to clipboard

Copied

LATEST

The loop uses numeric values in the decimal system.

The script itself determines which numbers to activate in the each selected group.

If you enter 000131 then it thinks it's octal, so you get the 91 in decimal (wrong result). In other words, you don't need to put zeros at the beginning of the number, just write:

 

for (var i = 133; i <= 143; i++) makeFile(i, digits, selection)

 

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