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

Photoshop script to invert curves

New Here ,
May 20, 2021 May 20, 2021

Copy link to clipboard

Copied

I want to create a script that will invert/swap the input and output values of all the points in each channel of a selected curves adjustment layer.

 

For example, the script should turn this curve:

 

before.png

 

into this:


after.png

 

This adjustment should be applied to all channels in the curves (RGB, Red, Green, Blue) and to all existing points. I don't have a lot of experience with photoshop scripting but i tried to write it myself and i couldn't figure out where photoshop stores the existing point input and output values. Any help would be appreciated.

TOPICS
Actions and scripting

Views

2.8K

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

People's Champ , May 20, 2021 May 20, 2021
var raw = get_prop_value("layer", null, "adjustment", 0, "legacyContentData");

var d = get_curves_desc(raw);

edit_adjustment_layer("curves", d, false);

////////////////////////////////////////////////////////////////////////////////////////////
function edit_adjustment_layer(type, data, dlg)
    {
    try { 
        if (type == null || type == undefined) type = get_prop_value("layer", null, "adjustment").getClass(0);

        if (typeof(type) == "string") type = (type.length==4)?charIDToTypeI
...

Votes

Translate

Translate
Adobe
People's Champ ,
May 20, 2021 May 20, 2021

Copy link to clipboard

Copied

var raw = get_prop_value("layer", null, "adjustment", 0, "legacyContentData");

var d = get_curves_desc(raw);

edit_adjustment_layer("curves", d, false);

////////////////////////////////////////////////////////////////////////////////////////////
function edit_adjustment_layer(type, data, dlg)
    {
    try { 
        if (type == null || type == undefined) type = get_prop_value("layer", null, "adjustment").getClass(0);

        if (typeof(type) == "string") type = (type.length==4)?charIDToTypeID(type):stringIDToTypeID(type);

        var d = new ActionDescriptor();
        var r = new ActionReference();
        r.putEnumerated(stringIDToTypeID("adjustmentLayer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
        d.putReference(stringIDToTypeID("null"), r);

        if (data == null || data == undefined) data = new ActionDescriptor();

        d.putObject(stringIDToTypeID("to"), type, data);
    
        var ret = executeAction(stringIDToTypeID("set"), d, dlg==false?DialogModes.NO:DialogModes.ALL);

        if (ret.hasKey(stringIDToTypeID("to"))) 
            ret = ret.getObjectValue(stringIDToTypeID("to"));
        else 
            ret = null;

        return ret;
        }
    catch (e) { alert(e); return null; }
    }

////////////////////////////////////////////////////////////////////////////////////////////
function get_prop_value(class_key, id, prop_key)
    {
    try
        {
        if (typeof(class_key) == "string") class_key = stringIDToTypeID(class_key);
        if (typeof(prop_key)  == "string") prop_key  = stringIDToTypeID(prop_key);

        var r = new ActionReference();    

        if (prop_key != undefined) r.putProperty(stringIDToTypeID("property"), prop_key);

        if (id == undefined || id == null) r.putEnumerated(class_key, stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
        else if (typeof(id) == "string")   r.putName(class_key, id);
        else                               r.putIdentifier(class_key, id);

        var desc;

        if (prop_key == undefined)
            {
            try { return executeActionGet(r); } catch (e) { return undefined; }
            }

        try { desc = executeActionGet(r); } catch (e) { return undefined; }     

        if (!desc.hasKey(prop_key)) return undefined;

        var ret = get_value(desc, prop_key);

        for (var i = 3; i < arguments.length; i++) 
            if (arguments[i] != undefined) ret = get_value(ret, arguments[i]);  

        return ret;

        function get_type(obj, key)
            {
            try 
                {
                if (obj == undefined) return undefined;            

                if (typeof(key) == "string") key = stringIDToTypeID(key);
        
                switch (obj.typename)
                    {
                    case "ActionDescriptor":  
                    case "ActionList"      : return obj.getType(key);
        
                    case "ActionReference" : return obj.getForm();
                    }
                }
            catch (e) { throw(e); }
            }
        
        function get_value(obj, key)
            {
            try 
                {
                if (obj == undefined) return undefined;            

                if (typeof(key) == "string") key = stringIDToTypeID(key);
        
                switch (obj.typename)
                    {
                    case "ActionDescriptor":  
                    case "ActionList"      : return get_desc_value(obj, key);
        
                    case "ActionReference" : return get_ref_value(obj);
                    }
                }
            catch (e) { throw(e); }
            }
        
        function get_desc_value(d, key)
            {
            try 
                {
                if (d == undefined) return undefined;            

                if (typeof(key) == "string") key = stringIDToTypeID(key);
        
                var val; 

                if (d instanceof ActionDescriptor && !d.hasKey(key)) return undefined;

                else if (d instanceof ActionList && key >= d.count) return undefined;

                var type = d.getType(key);
        
                switch (type) 
                    {
                    case DescValueType.ALIASTYPE:        val = d.getPath(key);             break;
                    case DescValueType.BOOLEANTYPE:      val = d.getBoolean(key);          break;
                    case DescValueType.CLASSTYPE:        val = d.getClass(key);            break;
                    case DescValueType.DOUBLETYPE:       val = d.getDouble(key);           break;  
                    case DescValueType.INTEGERTYPE:      val = d.getInteger(key);          break;
                    case DescValueType.LISTTYPE:         val = d.getList(key);             break;
                    case DescValueType.RAWTYPE:          val = d.getData(key);             break;
                    case DescValueType.STRINGTYPE:       val = d.getString(key);           break;
                    case DescValueType.LARGEINTEGERTYPE: val = d.getLargeInteger(key);     break;
                    case DescValueType.REFERENCETYPE:    val = d.getReference(key);        break;
                    case DescValueType.OBJECTTYPE:       val = d.getObjectValue(key);      break;
                    case DescValueType.UNITDOUBLE:       val = d.getUnitDoubleValue(key);  break;
                    case DescValueType.ENUMERATEDTYPE:   val = d.getEnumerationValue(key); break;
                    }
        
                return val;
                }
            catch (e) { throw(e); }
            }
        
        function get_ref_value(r)
            {
            try 
                {
                var val; 
        
                switch (r.getForm())
                    {
                    case ReferenceFormType.CLASSTYPE:  val = r.getDesiredClass();    break;
                    case ReferenceFormType.IDENTIFIER: val = r.getIdentifier();      break;
                    case ReferenceFormType.INDEX:      val = r.getIndex();           break;
                    case ReferenceFormType.NAME:       val = r.getName();            break;
                    case ReferenceFormType.OFFSET:     val = r.getOffset();          break;
                    case ReferenceFormType.ENUMERATED: val = r.getEnumeratedValue(); break;
                    case ReferenceFormType.PROPERTY:   val = r.getProperty();        break;  
                    }
        
                return val;
                }
            catch (e) { throw(e); }
            }
        }   
    catch (e) { throw(e); }
    }

////////////////////////////////////////////////////////////////////////////////////////////
function get_curves_desc(raw)
    {
    try {
        var channels = new Array();

        var type = raw.charCodeAt(0)?"mapping":"curve";

        var ch_bit = raw.charCodeAt(6);

        if (type == "curve")
            {
            var off = 7;

            for (var i = 0; i < 5; i++) 
                {
                if (ch_bit & (1<<i)) 
                    {
                    var len = get_short(raw.substr(off));                
                    channels[i] = get_short(raw.substr(off+2), len*2);
                    off += len*4 + 2;
                    }
                }
            }
        else
            {
            var off = 7;

            for (var i = 0; i < 5; i++) 
                {
                if (ch_bit & (1<<i)) 
                    {
                    channels[i] = new Array();
                    for (var n = 0; n < 256; n++) channels[i].push(raw.charCodeAt(off+n));
                    off += 256;
                    }
                }
            }

        var d = new ActionDescriptor();
        var list = new ActionList();

        function set_chnl(name, m, type)
            {
            if (m == undefined || m == null) return;

            var d = new ActionDescriptor();
            var r = new ActionReference();
            r.putEnumerated(stringIDToTypeID("channel"), stringIDToTypeID("channel"), stringIDToTypeID(name));
            d.putReference(stringIDToTypeID("channel"), r);

            var lst = new ActionList();

            if (type == "curve")
                {
                for (var i = 0; i < m.length; i+=2)
                    {
                    var d1 = new ActionDescriptor();

                    //d1.putDouble(stringIDToTypeID("horizontal"), m[i+1]);
                    //d1.putDouble(stringIDToTypeID("vertical"),   m[i]);

                    // SWAP X and Y for THIS CASE

                    d1.putDouble(stringIDToTypeID("horizontal"), m[i]);
                    d1.putDouble(stringIDToTypeID("vertical"),   m[i+1]);


                    lst.putObject(stringIDToTypeID("point"), d1);
                    }

                d.putList(stringIDToTypeID("curve"), lst);
                }
            else
                {
                for (var i = 0; i < m.length; i++)
                    {
                    lst.putInteger(m[i]); 
                    }

                d.putList(stringIDToTypeID("mapping"), lst);
                }

            list.putObject(stringIDToTypeID("curvesAdjustment"), d);
            }

        if (app.activeDocument.mode == DocumentMode.RGB)
            {         
            var ch_list = ["composite", "red", "green", "blue"];
    
            for (var i = 0; i < 4; i++) if (ch_bit & (1<<i)) set_chnl(ch_list[i], channels[i], type);    
            }
        else if (app.activeDocument.mode == DocumentMode.LAB)
            {               
            var ch_list = ["", "lightness", "a", "b"];

            for (var i = 0; i < 4; i++) if (ch_bit & (1<<i)) set_chnl(ch_list[i], channels[i], type);    
            }
        else if (app.activeDocument.mode == DocumentMode.CMYK)
            {               
            var ch_list = ["composite", "cyan", "magenta", "yellow", "black"];

            for (var i = 0; i < 5; i++) if (ch_bit & (1<<i)) set_chnl(ch_list[i], channels[i], type);    
            }
        else if (app.activeDocument.mode == DocumentMode.GRAYSCALE)
            {               
            if (ch_bit & 2) set_chnl("black", channels[1], type);
            }
        else if (app.activeDocument.mode == DocumentMode.DUOTONE)
            {               
            if (ch_bit & 2) set_chnl(app.activeDocument.componentChannels[0].name.toLowerCase(), channels[1], type);
            }
        else { alert("Unsupported color mode", "Error", true); return null; }

        d.putList(stringIDToTypeID("adjustment"), list);

        return d;
        } 
    catch (e) { throw(e); }
    }

////////////////////////////////////////////////////////////////////////////////////////////
function get_short(s, len)
    {
    try { 
        if (len == undefined) len = 1;

        var ret = [];

        for (var i = 0; i < 2*len; i += 2)
            {
            var c0 = s.charCodeAt(0+i);
            var c1 = s.charCodeAt(1+i);

            var val = c1 + 256*c0;
            
            if (c0 & 0x80) val = -(0xFFFF - val + 1);
            
            ret.push(val);
            }

        if (len == 1) return ret[0];

        return ret;
        }
    catch (e) { throw(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
New Here ,
May 20, 2021 May 20, 2021

Copy link to clipboard

Copied

This is exactly what i wanted, thank you very much for your fast reply.

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 ,
Jul 20, 2023 Jul 20, 2023

Copy link to clipboard

Copied

This script worked fine in Photoshop 2020, but now in Photoshop Beta it gives an error. Tell me, please, how can I fix it?

 

Screenshot_2.png

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 ,
Jul 20, 2023 Jul 20, 2023

Copy link to clipboard

Copied

The same happens in Photoshop 24.6.0 for me. 

 

 

I have no doubts in @r-bin â€™s Photoshop Scripting prowess, but suppose they might be busy (I have no idea whether or not this is the case!) – what have you done for trouble-shooting so far? Have you been able to pintpoint the issue? 

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 ,
Jul 20, 2023 Jul 20, 2023

Copy link to clipboard

Copied

I'm not good at programming. So I just looked at the code for a long time and in desperation decided to write to the author here.

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 ,
Jul 20, 2023 Jul 20, 2023

Copy link to clipboard

Copied

Do you need the Script’s full functionality or do you actually use the Script in a more limited scenario, for example only for RGB images or …? 

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 ,
Jul 20, 2023 Jul 20, 2023

Copy link to clipboard

Copied

I just need the inversion of the curve, as described by the author of the topic. I use it with tif and jpg RAW images in 8/16 bit RGB space.

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
People's Champ ,
Jul 20, 2023 Jul 20, 2023

Copy link to clipboard

Copied

Change the code on line 289
catch(e) { throw(e); }
with
catch (e) { alert(e.line + "\n\n" + e); throw(e); }
 
And show a screenshot of the error message. I have no way to test on newer versions.
 

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 ,
Jul 20, 2023 Jul 20, 2023

Copy link to clipboard

Copied

Screenshot_3.png

 

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
People's Champ ,
Jul 20, 2023 Jul 20, 2023

Copy link to clipboard

Copied

Create a new script.

 

var r = new ActionReference();    
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

var d = executeActionGet(r);

var file = new File("~/Desktop/desc.bin");

file.open("w");
file.encoding = "BINARY";
file.write(d.toStream());
file.close();

alert(file.fsName);

 

Open your document and make the curves layer active. Run this script.
A "desc.bin" file will appear on the desktop (for windows). Upload it to a file hosting site and give a link here.
 

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 ,
Jul 20, 2023 Jul 20, 2023

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
People's Champ ,
Jul 20, 2023 Jul 20, 2023

Copy link to clipboard

Copied

The script is written without verification, based on your data.
It looks like the properties available through the AM code have changed a lot in the new version.
 
Check how it works.
 

 

var adj = get_prop_value("layer", null, "adjustment", 0);

var adjustment = adj.getList(stringIDToTypeID("adjustment"));
var new_adjustment = new ActionList();

for (var i = 0; i < adjustment.count; i++)
    {
    var curvesAdjustment = adjustment.getObjectValue(i);
    var new_curvesAdjustment = new ActionDescriptor();

    var channel = curvesAdjustment.getReference(stringIDToTypeID("channel"));

    var curve = curvesAdjustment.getList(stringIDToTypeID("curve"));

    var new_curve = new ActionList();

    for (var n = 0; n < curve.count; n++)
        {
        var point = curve.getObjectValue(n);

        var new_point = new ActionDescriptor();

        var x = point.getDouble(stringIDToTypeID("horizontal"));
        var y = point.getDouble(stringIDToTypeID("vertical"));

        new_point.putDouble(stringIDToTypeID("horizontal"), y);
        new_point.putDouble(stringIDToTypeID("vertical"),   x);
    
        new_curve.putObject(stringIDToTypeID("point"), new_point);
        }

    new_curvesAdjustment.putReference(stringIDToTypeID("channel"), channel);
    new_curvesAdjustment.putList(stringIDToTypeID("curve"), new_curve);

    new_adjustment.putObject(stringIDToTypeID("curvesAdjustment"), new_curvesAdjustment);
    }

adj.erase(stringIDToTypeID("adjustment"));
adj.putList(stringIDToTypeID("adjustment"), new_adjustment);

edit_adjustment_layer("curves", adj, false);

////////////////////////////////////////////////////////////////////////////////////////////
function edit_adjustment_layer(type, data, dlg)
    {
    try { 
        if (type == null || type == undefined) type = get_prop_value("layer", null, "adjustment").getClass(0);

        if (typeof(type) == "string") type = (type.length==4)?charIDToTypeID(type):stringIDToTypeID(type);

        var d = new ActionDescriptor();
        var r = new ActionReference();
        r.putEnumerated(stringIDToTypeID("adjustmentLayer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
        d.putReference(stringIDToTypeID("null"), r);

        if (data == null || data == undefined) data = new ActionDescriptor();

        d.putObject(stringIDToTypeID("to"), type, data);

        var ret = executeAction(stringIDToTypeID("set"), d, dlg==false?DialogModes.NO:DialogModes.ALL);

        if (ret.hasKey(stringIDToTypeID("to"))) 
            ret = ret.getObjectValue(stringIDToTypeID("to"));
        else 
            ret = null;

        return ret;
        }
    catch (e) { alert(e); return null; }
    }

////////////////////////////////////////////////////////////////////////////////////////////
function get_prop_value(class_key, id, prop_key)
    {
    try
        {
        if (typeof(class_key) == "string") class_key = stringIDToTypeID(class_key);
        if (typeof(prop_key)  == "string") prop_key  = stringIDToTypeID(prop_key);

        var r = new ActionReference();    

        if (prop_key != undefined) r.putProperty(stringIDToTypeID("property"), prop_key);

        if (id == undefined || id == null) r.putEnumerated(class_key, stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
        else if (typeof(id) == "string")   r.putName(class_key, id);
        else                               r.putIdentifier(class_key, id);

        var desc;

        if (prop_key == undefined)
            {
            try { return executeActionGet(r); } catch (e) { return undefined; }
            }

        try { desc = executeActionGet(r); } catch (e) { return undefined; }     

        if (!desc.hasKey(prop_key)) return undefined;

        var ret = get_value(desc, prop_key);

        for (var i = 3; i < arguments.length; i++) 
            if (arguments[i] != undefined) ret = get_value(ret, arguments[i]);  

        return ret;

        function get_type(obj, key)
            {
            try 
                {
                if (obj == undefined) return undefined;            

                if (typeof(key) == "string") key = stringIDToTypeID(key);
        
                switch (obj.typename)
                    {
                    case "ActionDescriptor":  
                    case "ActionList"      : return obj.getType(key);
        
                    case "ActionReference" : return obj.getForm();
                    }
                }
            catch (e) { throw(e); }
            }
        
        function get_value(obj, key)
            {
            try 
                {
                if (obj == undefined) return undefined;            

                if (typeof(key) == "string") key = stringIDToTypeID(key);
        
                switch (obj.typename)
                    {
                    case "ActionDescriptor":  
                    case "ActionList"      : return get_desc_value(obj, key);
        
                    case "ActionReference" : return get_ref_value(obj);
                    }
                }
            catch (e) { throw(e); }
            }
        
        function get_desc_value(d, key)
            {
            try 
                {
                if (d == undefined) return undefined;            

                if (typeof(key) == "string") key = stringIDToTypeID(key);
        
                var val; 

                if (d instanceof ActionDescriptor && !d.hasKey(key)) return undefined;

                else if (d instanceof ActionList && key >= d.count) return undefined;

                var type = d.getType(key);
        
                switch (type) 
                    {
                    case DescValueType.ALIASTYPE:        val = d.getPath(key);             break;
                    case DescValueType.BOOLEANTYPE:      val = d.getBoolean(key);          break;
                    case DescValueType.CLASSTYPE:        val = d.getClass(key);            break;
                    case DescValueType.DOUBLETYPE:       val = d.getDouble(key);           break;  
                    case DescValueType.INTEGERTYPE:      val = d.getInteger(key);          break;
                    case DescValueType.LISTTYPE:         val = d.getList(key);             break;
                    case DescValueType.RAWTYPE:          val = d.getData(key);             break;
                    case DescValueType.STRINGTYPE:       val = d.getString(key);           break;
                    case DescValueType.LARGEINTEGERTYPE: val = d.getLargeInteger(key);     break;
                    case DescValueType.REFERENCETYPE:    val = d.getReference(key);        break;
                    case DescValueType.OBJECTTYPE:       val = d.getObjectValue(key);      break;
                    case DescValueType.UNITDOUBLE:       val = d.getUnitDoubleValue(key);  break;
                    case DescValueType.ENUMERATEDTYPE:   val = d.getEnumerationValue(key); break;
                    }
        
                return val;
                }
            catch (e) { throw(e); }
            }
        
        function get_ref_value(r)
            {
            try 
                {
                var val; 
        
                switch (r.getForm())
                    {
                    case ReferenceFormType.CLASSTYPE:  val = r.getDesiredClass();    break;
                    case ReferenceFormType.IDENTIFIER: val = r.getIdentifier();      break;
                    case ReferenceFormType.INDEX:      val = r.getIndex();           break;
                    case ReferenceFormType.NAME:       val = r.getName();            break;
                    case ReferenceFormType.OFFSET:     val = r.getOffset();          break;
                    case ReferenceFormType.ENUMERATED: val = r.getEnumeratedValue(); break;
                    case ReferenceFormType.PROPERTY:   val = r.getProperty();        break;  
                    }
        
                return val;
                }
            catch (e) { throw(e); }
            }
        }   
    catch (e) { throw(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
Explorer ,
Jul 20, 2023 Jul 20, 2023

Copy link to clipboard

Copied

Works with only one RGB brightness channel. If other color channels are affected, it gives an error.

UNFOTONY_0-1689878913936.png

 

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
People's Champ ,
Jul 20, 2023 Jul 20, 2023

Copy link to clipboard

Copied

Strange. Give the "desc.bin" file in which all channels are involved.
 

 

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 ,
Jul 20, 2023 Jul 20, 2023

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
Explorer ,
Jul 20, 2023 Jul 20, 2023

Copy link to clipboard

Copied

And then the same error

 

UNFOTONY_0-1689867019574.png

 

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
People's Champ ,
Jul 20, 2023 Jul 20, 2023

Copy link to clipboard

Copied

Very strange. Should work. Check this code. I can't check.
 

 

var r = new ActionReference();    
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
var adj = executeActionGet(r).getList(stringIDToTypeID("adjustment")).getObjectValue(0);

var adjustment = adj.getList(stringIDToTypeID("adjustment"));
var new_adjustment = new ActionList();

for (var i = 0; i < adjustment.count; i++)
    {
    var curvesAdjustment = adjustment.getObjectValue(i);
    var new_curvesAdjustment = new ActionDescriptor();

    var channel = curvesAdjustment.getReference(stringIDToTypeID("channel"));

    var curve = curvesAdjustment.getList(stringIDToTypeID("curve"));

    var new_curve = new ActionList();

    for (var n = 0; n < curve.count; n++)
        {
        var point = curve.getObjectValue(n);

        var new_point = new ActionDescriptor();

        var x = point.getDouble(stringIDToTypeID("horizontal"));
        var y = point.getDouble(stringIDToTypeID("vertical"));

        new_point.putDouble(stringIDToTypeID("horizontal"), y);
        new_point.putDouble(stringIDToTypeID("vertical"),   x);
    
        new_curve.putObject(stringIDToTypeID("point"), new_point);
        }

    new_curvesAdjustment.putReference(stringIDToTypeID("channel"), channel);
    new_curvesAdjustment.putList(stringIDToTypeID("curve"), new_curve);

    new_adjustment.putObject(stringIDToTypeID("curvesAdjustment"), new_curvesAdjustment);
    }

adj.erase(stringIDToTypeID("adjustment"));
adj.putList(stringIDToTypeID("adjustment"), new_adjustment);

edit_adjustment_layer("curves", adj, false);

////////////////////////////////////////////////////////////////////////////////////////////
function edit_adjustment_layer(type, data, dlg)
    {
    try { 
        if (type == null || type == undefined) type = get_prop_value("layer", null, "adjustment").getClass(0);

        if (typeof(type) == "string") type = (type.length==4)?charIDToTypeID(type):stringIDToTypeID(type);

        var d = new ActionDescriptor();
        var r = new ActionReference();
        r.putEnumerated(stringIDToTypeID("adjustmentLayer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
        d.putReference(stringIDToTypeID("null"), r);

        if (data == null || data == undefined) data = new ActionDescriptor();

        d.putObject(stringIDToTypeID("to"), type, data);

        var ret = executeAction(stringIDToTypeID("set"), d, dlg==false?DialogModes.NO:DialogModes.ALL);

        if (ret.hasKey(stringIDToTypeID("to"))) 
            ret = ret.getObjectValue(stringIDToTypeID("to"));
        else 
            ret = null;

        return ret;
        }
    catch (e) { alert(e); return null; }
    }

////////////////////////////////////////////////////////////////////////////////////////////
function get_prop_value(class_key, id, prop_key)
    {
    try
        {
        if (typeof(class_key) == "string") class_key = stringIDToTypeID(class_key);
        if (typeof(prop_key)  == "string") prop_key  = stringIDToTypeID(prop_key);

        var r = new ActionReference();    

        if (prop_key != undefined) r.putProperty(stringIDToTypeID("property"), prop_key);

        if (id == undefined || id == null) r.putEnumerated(class_key, stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
        else if (typeof(id) == "string")   r.putName(class_key, id);
        else                               r.putIdentifier(class_key, id);

        var desc;

        if (prop_key == undefined)
            {
            try { return executeActionGet(r); } catch (e) { return undefined; }
            }

        try { desc = executeActionGet(r); } catch (e) { return undefined; }     

        if (!desc.hasKey(prop_key)) return undefined;

        var ret = get_value(desc, prop_key);

        for (var i = 3; i < arguments.length; i++) 
            if (arguments[i] != undefined) ret = get_value(ret, arguments[i]);  

        return ret;

        function get_type(obj, key)
            {
            try 
                {
                if (obj == undefined) return undefined;            

                if (typeof(key) == "string") key = stringIDToTypeID(key);
        
                switch (obj.typename)
                    {
                    case "ActionDescriptor":  
                    case "ActionList"      : return obj.getType(key);
        
                    case "ActionReference" : return obj.getForm();
                    }
                }
            catch (e) { throw(e); }
            }
        
        function get_value(obj, key)
            {
            try 
                {
                if (obj == undefined) return undefined;            

                if (typeof(key) == "string") key = stringIDToTypeID(key);
        
                switch (obj.typename)
                    {
                    case "ActionDescriptor":  
                    case "ActionList"      : return get_desc_value(obj, key);
        
                    case "ActionReference" : return get_ref_value(obj);
                    }
                }
            catch (e) { throw(e); }
            }
        
        function get_desc_value(d, key)
            {
            try 
                {
                if (d == undefined) return undefined;            

                if (typeof(key) == "string") key = stringIDToTypeID(key);
        
                var val; 

                if (d instanceof ActionDescriptor && !d.hasKey(key)) return undefined;

                else if (d instanceof ActionList && key >= d.count) return undefined;

                var type = d.getType(key);
        
                switch (type) 
                    {
                    case DescValueType.ALIASTYPE:        val = d.getPath(key);             break;
                    case DescValueType.BOOLEANTYPE:      val = d.getBoolean(key);          break;
                    case DescValueType.CLASSTYPE:        val = d.getClass(key);            break;
                    case DescValueType.DOUBLETYPE:       val = d.getDouble(key);           break;  
                    case DescValueType.INTEGERTYPE:      val = d.getInteger(key);          break;
                    case DescValueType.LISTTYPE:         val = d.getList(key);             break;
                    case DescValueType.RAWTYPE:          val = d.getData(key);             break;
                    case DescValueType.STRINGTYPE:       val = d.getString(key);           break;
                    case DescValueType.LARGEINTEGERTYPE: val = d.getLargeInteger(key);     break;
                    case DescValueType.REFERENCETYPE:    val = d.getReference(key);        break;
                    case DescValueType.OBJECTTYPE:       val = d.getObjectValue(key);      break;
                    case DescValueType.UNITDOUBLE:       val = d.getUnitDoubleValue(key);  break;
                    case DescValueType.ENUMERATEDTYPE:   val = d.getEnumerationValue(key); break;
                    }
        
                return val;
                }
            catch (e) { throw(e); }
            }
        
        function get_ref_value(r)
            {
            try 
                {
                var val; 
        
                switch (r.getForm())
                    {
                    case ReferenceFormType.CLASSTYPE:  val = r.getDesiredClass();    break;
                    case ReferenceFormType.IDENTIFIER: val = r.getIdentifier();      break;
                    case ReferenceFormType.INDEX:      val = r.getIndex();           break;
                    case ReferenceFormType.NAME:       val = r.getName();            break;
                    case ReferenceFormType.OFFSET:     val = r.getOffset();          break;
                    case ReferenceFormType.ENUMERATED: val = r.getEnumeratedValue(); break;
                    case ReferenceFormType.PROPERTY:   val = r.getProperty();        break;  
                    }
        
                return val;
                }
            catch (e) { throw(e); }
            }
        }   
    catch (e) { throw(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
Explorer ,
Jul 20, 2023 Jul 20, 2023

Copy link to clipboard

Copied

It only works with the RGB curve, with color again an error:
UNFOTONY_0-1689882799349.png

Thank you very much for helping. I would never do it myself...

 

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 ,
Jul 20, 2023 Jul 20, 2023

Copy link to clipboard

Copied

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

 

Just in case, one more file with a different curve.

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
People's Champ ,
Jul 20, 2023 Jul 20, 2023

Copy link to clipboard

Copied

Run this debug script on the active layer that is causing the error. It will create two files "adj.bin" and "curvesAdjustment.bin". Give me them.
 

 

//////////////////////
function debug(fname, d)
    {
    var file = new File("~/Desktop/"+fname);

    file.open("w");
    file.encoding = "BINARY";
    file.write(d.toStream());
    file.close();    
    }
//////////////////////

var r = new ActionReference();    
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
var adj = executeActionGet(r).getList(stringIDToTypeID("adjustment")).getObjectValue(0);

debug("adj.bin", adj); /////////////

var adjustment = adj.getList(stringIDToTypeID("adjustment"));
var new_adjustment = new ActionList();

for (var i = 0; i < adjustment.count; i++)
    {
    var curvesAdjustment = adjustment.getObjectValue(i);
    var new_curvesAdjustment = new ActionDescriptor();

    debug("curvesAdjustment.bin", curvesAdjustment); /////////////

    var channel = curvesAdjustment.getReference(stringIDToTypeID("channel"));

    var curve = curvesAdjustment.getList(stringIDToTypeID("curve"));

    var new_curve = new ActionList();

    for (var n = 0; n < curve.count; n++)
        {
        var point = curve.getObjectValue(n);

        var new_point = new ActionDescriptor();

        var x = point.getDouble(stringIDToTypeID("horizontal"));
        var y = point.getDouble(stringIDToTypeID("vertical"));

        new_point.putDouble(stringIDToTypeID("horizontal"), y);
        new_point.putDouble(stringIDToTypeID("vertical"),   x);
    
        new_curve.putObject(stringIDToTypeID("point"), new_point);
        }

    new_curvesAdjustment.putReference(stringIDToTypeID("channel"), channel);
    new_curvesAdjustment.putList(stringIDToTypeID("curve"), new_curve);

    new_adjustment.putObject(stringIDToTypeID("curvesAdjustment"), new_curvesAdjustment);
    }

adj.erase(stringIDToTypeID("adjustment"));
adj.putList(stringIDToTypeID("adjustment"), new_adjustment);

edit_adjustment_layer("curves", adj, false);

////////////////////////////////////////////////////////////////////////////////////////////
function edit_adjustment_layer(type, data, dlg)
    {
    try { 
        if (type == null || type == undefined) type = get_prop_value("layer", null, "adjustment").getClass(0);

        if (typeof(type) == "string") type = (type.length==4)?charIDToTypeID(type):stringIDToTypeID(type);

        var d = new ActionDescriptor();
        var r = new ActionReference();
        r.putEnumerated(stringIDToTypeID("adjustmentLayer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
        d.putReference(stringIDToTypeID("null"), r);

        if (data == null || data == undefined) data = new ActionDescriptor();

        d.putObject(stringIDToTypeID("to"), type, data);

        var ret = executeAction(stringIDToTypeID("set"), d, dlg==false?DialogModes.NO:DialogModes.ALL);

        if (ret.hasKey(stringIDToTypeID("to"))) 
            ret = ret.getObjectValue(stringIDToTypeID("to"));
        else 
            ret = null;

        return ret;
        }
    catch (e) { alert(e); return null; }
    }

////////////////////////////////////////////////////////////////////////////////////////////
function get_prop_value(class_key, id, prop_key)
    {
    try
        {
        if (typeof(class_key) == "string") class_key = stringIDToTypeID(class_key);
        if (typeof(prop_key)  == "string") prop_key  = stringIDToTypeID(prop_key);

        var r = new ActionReference();    

        if (prop_key != undefined) r.putProperty(stringIDToTypeID("property"), prop_key);

        if (id == undefined || id == null) r.putEnumerated(class_key, stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
        else if (typeof(id) == "string")   r.putName(class_key, id);
        else                               r.putIdentifier(class_key, id);

        var desc;

        if (prop_key == undefined)
            {
            try { return executeActionGet(r); } catch (e) { return undefined; }
            }

        try { desc = executeActionGet(r); } catch (e) { return undefined; }     

        if (!desc.hasKey(prop_key)) return undefined;

        var ret = get_value(desc, prop_key);

        for (var i = 3; i < arguments.length; i++) 
            if (arguments[i] != undefined) ret = get_value(ret, arguments[i]);  

        return ret;

        function get_type(obj, key)
            {
            try 
                {
                if (obj == undefined) return undefined;            

                if (typeof(key) == "string") key = stringIDToTypeID(key);
        
                switch (obj.typename)
                    {
                    case "ActionDescriptor":  
                    case "ActionList"      : return obj.getType(key);
        
                    case "ActionReference" : return obj.getForm();
                    }
                }
            catch (e) { throw(e); }
            }
        
        function get_value(obj, key)
            {
            try 
                {
                if (obj == undefined) return undefined;            

                if (typeof(key) == "string") key = stringIDToTypeID(key);
        
                switch (obj.typename)
                    {
                    case "ActionDescriptor":  
                    case "ActionList"      : return get_desc_value(obj, key);
        
                    case "ActionReference" : return get_ref_value(obj);
                    }
                }
            catch (e) { throw(e); }
            }
        
        function get_desc_value(d, key)
            {
            try 
                {
                if (d == undefined) return undefined;            

                if (typeof(key) == "string") key = stringIDToTypeID(key);
        
                var val; 

                if (d instanceof ActionDescriptor && !d.hasKey(key)) return undefined;

                else if (d instanceof ActionList && key >= d.count) return undefined;

                var type = d.getType(key);
        
                switch (type) 
                    {
                    case DescValueType.ALIASTYPE:        val = d.getPath(key);             break;
                    case DescValueType.BOOLEANTYPE:      val = d.getBoolean(key);          break;
                    case DescValueType.CLASSTYPE:        val = d.getClass(key);            break;
                    case DescValueType.DOUBLETYPE:       val = d.getDouble(key);           break;  
                    case DescValueType.INTEGERTYPE:      val = d.getInteger(key);          break;
                    case DescValueType.LISTTYPE:         val = d.getList(key);             break;
                    case DescValueType.RAWTYPE:          val = d.getData(key);             break;
                    case DescValueType.STRINGTYPE:       val = d.getString(key);           break;
                    case DescValueType.LARGEINTEGERTYPE: val = d.getLargeInteger(key);     break;
                    case DescValueType.REFERENCETYPE:    val = d.getReference(key);        break;
                    case DescValueType.OBJECTTYPE:       val = d.getObjectValue(key);      break;
                    case DescValueType.UNITDOUBLE:       val = d.getUnitDoubleValue(key);  break;
                    case DescValueType.ENUMERATEDTYPE:   val = d.getEnumerationValue(key); break;
                    }
        
                return val;
                }
            catch (e) { throw(e); }
            }
        
        function get_ref_value(r)
            {
            try 
                {
                var val; 
        
                switch (r.getForm())
                    {
                    case ReferenceFormType.CLASSTYPE:  val = r.getDesiredClass();    break;
                    case ReferenceFormType.IDENTIFIER: val = r.getIdentifier();      break;
                    case ReferenceFormType.INDEX:      val = r.getIndex();           break;
                    case ReferenceFormType.NAME:       val = r.getName();            break;
                    case ReferenceFormType.OFFSET:     val = r.getOffset();          break;
                    case ReferenceFormType.ENUMERATED: val = r.getEnumeratedValue(); break;
                    case ReferenceFormType.PROPERTY:   val = r.getProperty();        break;  
                    }
        
                return val;
                }
            catch (e) { throw(e); }
            }
        }   
    catch (e) { throw(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
Explorer ,
Jul 20, 2023 Jul 20, 2023

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
People's Champ ,
Jul 20, 2023 Jul 20, 2023

Copy link to clipboard

Copied

You used the "Auto" button. This is recorded in the layer descriptor. In this case, there is no information about the real points of the curve. They removed the "legacyContentData" property, which was previously used to extract points, and inserted new information, but not the one that was needed, but the one that was used when creating the correction, which may not contain points if the "Auto" button was used.
I inserted a crutch in the first line - an idle layer edit. This should update the point information. Check.
 

 

////////////////////////////////
// False (idle) editing of the adjustment layer 
// in order to remove the "auto" property from the descriptor 
// and get real points.

edit_adjustment_layer("curves", new ActionDescriptor(), false);

////////////////////////////////

var adj = get_prop_value("layer", null, "adjustment", 0);

var adjustment = adj.getList(stringIDToTypeID("adjustment"));
var new_adjustment = new ActionList();

for (var i = 0; i < adjustment.count; i++)
    {
    var curvesAdjustment = adjustment.getObjectValue(i);
    var new_curvesAdjustment = new ActionDescriptor();

    var channel = curvesAdjustment.getReference(stringIDToTypeID("channel"));

    var curve = curvesAdjustment.getList(stringIDToTypeID("curve"));

    var new_curve = new ActionList();

    for (var n = 0; n < curve.count; n++)
        {
        var point = curve.getObjectValue(n);

        var new_point = new ActionDescriptor();

        var x = point.getDouble(stringIDToTypeID("horizontal"));
        var y = point.getDouble(stringIDToTypeID("vertical"));

        new_point.putDouble(stringIDToTypeID("horizontal"), y);
        new_point.putDouble(stringIDToTypeID("vertical"),   x);
    
        new_curve.putObject(stringIDToTypeID("point"), new_point);
        }

    new_curvesAdjustment.putReference(stringIDToTypeID("channel"), channel);
    new_curvesAdjustment.putList(stringIDToTypeID("curve"), new_curve);

    new_adjustment.putObject(stringIDToTypeID("curvesAdjustment"), new_curvesAdjustment);
    }

adj.erase(stringIDToTypeID("adjustment"));
adj.putList(stringIDToTypeID("adjustment"), new_adjustment);

edit_adjustment_layer("curves", adj, false);

////////////////////////////////////////////////////////////////////////////////////////////
function edit_adjustment_layer(type, data, dlg)
    {
    try { 
        if (type == null || type == undefined) type = get_prop_value("layer", null, "adjustment").getClass(0);

        if (typeof(type) == "string") type = (type.length==4)?charIDToTypeID(type):stringIDToTypeID(type);

        var d = new ActionDescriptor();
        var r = new ActionReference();
        r.putEnumerated(stringIDToTypeID("adjustmentLayer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
        d.putReference(stringIDToTypeID("null"), r);

        if (data == null || data == undefined) data = new ActionDescriptor();

        d.putObject(stringIDToTypeID("to"), type, data);

        var ret = executeAction(stringIDToTypeID("set"), d, dlg==false?DialogModes.NO:DialogModes.ALL);

        if (ret.hasKey(stringIDToTypeID("to"))) 
            ret = ret.getObjectValue(stringIDToTypeID("to"));
        else 
            ret = null;

        return ret;
        }
    catch (e) { alert(e); return null; }
    }

////////////////////////////////////////////////////////////////////////////////////////////
function get_prop_value(class_key, id, prop_key)
    {
    try
        {
        if (typeof(class_key) == "string") class_key = stringIDToTypeID(class_key);
        if (typeof(prop_key)  == "string") prop_key  = stringIDToTypeID(prop_key);

        var r = new ActionReference();    

        if (prop_key != undefined) r.putProperty(stringIDToTypeID("property"), prop_key);

        if (id == undefined || id == null) r.putEnumerated(class_key, stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
        else if (typeof(id) == "string")   r.putName(class_key, id);
        else                               r.putIdentifier(class_key, id);

        var desc;

        if (prop_key == undefined)
            {
            try { return executeActionGet(r); } catch (e) { return undefined; }
            }

        try { desc = executeActionGet(r); } catch (e) { return undefined; }     

        if (!desc.hasKey(prop_key)) return undefined;

        var ret = get_value(desc, prop_key);

        for (var i = 3; i < arguments.length; i++) 
            if (arguments[i] != undefined) ret = get_value(ret, arguments[i]);  

        return ret;

        function get_type(obj, key)
            {
            try 
                {
                if (obj == undefined) return undefined;            

                if (typeof(key) == "string") key = stringIDToTypeID(key);
        
                switch (obj.typename)
                    {
                    case "ActionDescriptor":  
                    case "ActionList"      : return obj.getType(key);
        
                    case "ActionReference" : return obj.getForm();
                    }
                }
            catch (e) { throw(e); }
            }
        
        function get_value(obj, key)
            {
            try 
                {
                if (obj == undefined) return undefined;            

                if (typeof(key) == "string") key = stringIDToTypeID(key);
        
                switch (obj.typename)
                    {
                    case "ActionDescriptor":  
                    case "ActionList"      : return get_desc_value(obj, key);
        
                    case "ActionReference" : return get_ref_value(obj);
                    }
                }
            catch (e) { throw(e); }
            }
        
        function get_desc_value(d, key)
            {
            try 
                {
                if (d == undefined) return undefined;            

                if (typeof(key) == "string") key = stringIDToTypeID(key);
        
                var val; 

                if (d instanceof ActionDescriptor && !d.hasKey(key)) return undefined;

                else if (d instanceof ActionList && key >= d.count) return undefined;

                var type = d.getType(key);
        
                switch (type) 
                    {
                    case DescValueType.ALIASTYPE:        val = d.getPath(key);             break;
                    case DescValueType.BOOLEANTYPE:      val = d.getBoolean(key);          break;
                    case DescValueType.CLASSTYPE:        val = d.getClass(key);            break;
                    case DescValueType.DOUBLETYPE:       val = d.getDouble(key);           break;  
                    case DescValueType.INTEGERTYPE:      val = d.getInteger(key);          break;
                    case DescValueType.LISTTYPE:         val = d.getList(key);             break;
                    case DescValueType.RAWTYPE:          val = d.getData(key);             break;
                    case DescValueType.STRINGTYPE:       val = d.getString(key);           break;
                    case DescValueType.LARGEINTEGERTYPE: val = d.getLargeInteger(key);     break;
                    case DescValueType.REFERENCETYPE:    val = d.getReference(key);        break;
                    case DescValueType.OBJECTTYPE:       val = d.getObjectValue(key);      break;
                    case DescValueType.UNITDOUBLE:       val = d.getUnitDoubleValue(key);  break;
                    case DescValueType.ENUMERATEDTYPE:   val = d.getEnumerationValue(key); break;
                    }
        
                return val;
                }
            catch (e) { throw(e); }
            }
        
        function get_ref_value(r)
            {
            try 
                {
                var val; 
        
                switch (r.getForm())
                    {
                    case ReferenceFormType.CLASSTYPE:  val = r.getDesiredClass();    break;
                    case ReferenceFormType.IDENTIFIER: val = r.getIdentifier();      break;
                    case ReferenceFormType.INDEX:      val = r.getIndex();           break;
                    case ReferenceFormType.NAME:       val = r.getName();            break;
                    case ReferenceFormType.OFFSET:     val = r.getOffset();          break;
                    case ReferenceFormType.ENUMERATED: val = r.getEnumeratedValue(); break;
                    case ReferenceFormType.PROPERTY:   val = r.getProperty();        break;  
                    }
        
                return val;
                }
            catch (e) { throw(e); }
            }
        }   
    catch (e) { throw(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
Explorer ,
Jul 20, 2023 Jul 20, 2023

Copy link to clipboard

Copied

Yes, I used autocurves. Didn't know there was a difference, sorry... 

Still the same error 8500, but on line 22.

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
People's Champ ,
Jul 20, 2023 Jul 20, 2023

Copy link to clipboard

Copied

This is what should help. If not, then you're out of luck.
 

 

////////////////////////////////
// False (idle) editing of the adjustment layer 
// in order to remove the "auto" property from the descriptor 
// and get real points.

var d = new ActionDescriptor();
var r = new ActionReference();
r.putEnumerated(stringIDToTypeID("adjustmentLayer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
d.putReference(stringIDToTypeID("null"), r);
var d1 = new ActionDescriptor();
d1.putEnumerated(stringIDToTypeID("presetKind"), stringIDToTypeID("presetKindType"), stringIDToTypeID("presetKindCustom"));
d.putObject(stringIDToTypeID("to"), stringIDToTypeID("curves"), d1);
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);

////////////////////////////////

var adj = get_prop_value("layer", null, "adjustment", 0);

var adjustment = adj.getList(stringIDToTypeID("adjustment"));
var new_adjustment = new ActionList();

for (var i = 0; i < adjustment.count; i++)
    {
    var curvesAdjustment = adjustment.getObjectValue(i);
    var new_curvesAdjustment = new ActionDescriptor();

    var channel = curvesAdjustment.getReference(stringIDToTypeID("channel"));

    var curve = curvesAdjustment.getList(stringIDToTypeID("curve"));

    var new_curve = new ActionList();

    for (var n = 0; n < curve.count; n++)
        {
        var point = curve.getObjectValue(n);

        var new_point = new ActionDescriptor();

        var x = point.getDouble(stringIDToTypeID("horizontal"));
        var y = point.getDouble(stringIDToTypeID("vertical"));

        new_point.putDouble(stringIDToTypeID("horizontal"), y);
        new_point.putDouble(stringIDToTypeID("vertical"),   x);
    
        new_curve.putObject(stringIDToTypeID("point"), new_point);
        }

    new_curvesAdjustment.putReference(stringIDToTypeID("channel"), channel);
    new_curvesAdjustment.putList(stringIDToTypeID("curve"), new_curve);

    new_adjustment.putObject(stringIDToTypeID("curvesAdjustment"), new_curvesAdjustment);
    }

adj.erase(stringIDToTypeID("adjustment"));
adj.putList(stringIDToTypeID("adjustment"), new_adjustment);

edit_adjustment_layer("curves", adj, false);

////////////////////////////////////////////////////////////////////////////////////////////
function edit_adjustment_layer(type, data, dlg)
    {
    try { 
        if (type == null || type == undefined) type = get_prop_value("layer", null, "adjustment").getClass(0);

        if (typeof(type) == "string") type = (type.length==4)?charIDToTypeID(type):stringIDToTypeID(type);

        var d = new ActionDescriptor();
        var r = new ActionReference();
        r.putEnumerated(stringIDToTypeID("adjustmentLayer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
        d.putReference(stringIDToTypeID("null"), r);

        if (data == null || data == undefined) d.putObject(stringIDToTypeID("to"), type, data);

        var ret = executeAction(stringIDToTypeID("set"), d, dlg==false?DialogModes.NO:DialogModes.ALL);

        if (ret.hasKey(stringIDToTypeID("to"))) 
            ret = ret.getObjectValue(stringIDToTypeID("to"));
        else 
            ret = null;

        return ret;
        }
    catch (e) { alert(e); return null; }
    }

////////////////////////////////////////////////////////////////////////////////////////////
function get_prop_value(class_key, id, prop_key)
    {
    try
        {
        if (typeof(class_key) == "string") class_key = stringIDToTypeID(class_key);
        if (typeof(prop_key)  == "string") prop_key  = stringIDToTypeID(prop_key);

        var r = new ActionReference();    

        if (prop_key != undefined) r.putProperty(stringIDToTypeID("property"), prop_key);

        if (id == undefined || id == null) r.putEnumerated(class_key, stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
        else if (typeof(id) == "string")   r.putName(class_key, id);
        else                               r.putIdentifier(class_key, id);

        var desc;

        if (prop_key == undefined)
            {
            try { return executeActionGet(r); } catch (e) { return undefined; }
            }

        try { desc = executeActionGet(r); } catch (e) { return undefined; }     

        if (!desc.hasKey(prop_key)) return undefined;

        var ret = get_value(desc, prop_key);

        for (var i = 3; i < arguments.length; i++) 
            if (arguments[i] != undefined) ret = get_value(ret, arguments[i]);  

        return ret;

        function get_type(obj, key)
            {
            try 
                {
                if (obj == undefined) return undefined;            

                if (typeof(key) == "string") key = stringIDToTypeID(key);
        
                switch (obj.typename)
                    {
                    case "ActionDescriptor":  
                    case "ActionList"      : return obj.getType(key);
        
                    case "ActionReference" : return obj.getForm();
                    }
                }
            catch (e) { throw(e); }
            }
        
        function get_value(obj, key)
            {
            try 
                {
                if (obj == undefined) return undefined;            

                if (typeof(key) == "string") key = stringIDToTypeID(key);
        
                switch (obj.typename)
                    {
                    case "ActionDescriptor":  
                    case "ActionList"      : return get_desc_value(obj, key);
        
                    case "ActionReference" : return get_ref_value(obj);
                    }
                }
            catch (e) { throw(e); }
            }
        
        function get_desc_value(d, key)
            {
            try 
                {
                if (d == undefined) return undefined;            

                if (typeof(key) == "string") key = stringIDToTypeID(key);
        
                var val; 

                if (d instanceof ActionDescriptor && !d.hasKey(key)) return undefined;

                else if (d instanceof ActionList && key >= d.count) return undefined;

                var type = d.getType(key);
        
                switch (type) 
                    {
                    case DescValueType.ALIASTYPE:        val = d.getPath(key);             break;
                    case DescValueType.BOOLEANTYPE:      val = d.getBoolean(key);          break;
                    case DescValueType.CLASSTYPE:        val = d.getClass(key);            break;
                    case DescValueType.DOUBLETYPE:       val = d.getDouble(key);           break;  
                    case DescValueType.INTEGERTYPE:      val = d.getInteger(key);          break;
                    case DescValueType.LISTTYPE:         val = d.getList(key);             break;
                    case DescValueType.RAWTYPE:          val = d.getData(key);             break;
                    case DescValueType.STRINGTYPE:       val = d.getString(key);           break;
                    case DescValueType.LARGEINTEGERTYPE: val = d.getLargeInteger(key);     break;
                    case DescValueType.REFERENCETYPE:    val = d.getReference(key);        break;
                    case DescValueType.OBJECTTYPE:       val = d.getObjectValue(key);      break;
                    case DescValueType.UNITDOUBLE:       val = d.getUnitDoubleValue(key);  break;
                    case DescValueType.ENUMERATEDTYPE:   val = d.getEnumerationValue(key); break;
                    }
        
                return val;
                }
            catch (e) { throw(e); }
            }
        
        function get_ref_value(r)
            {
            try 
                {
                var val; 
        
                switch (r.getForm())
                    {
                    case ReferenceFormType.CLASSTYPE:  val = r.getDesiredClass();    break;
                    case ReferenceFormType.IDENTIFIER: val = r.getIdentifier();      break;
                    case ReferenceFormType.INDEX:      val = r.getIndex();           break;
                    case ReferenceFormType.NAME:       val = r.getName();            break;
                    case ReferenceFormType.OFFSET:     val = r.getOffset();          break;
                    case ReferenceFormType.ENUMERATED: val = r.getEnumeratedValue(); break;
                    case ReferenceFormType.PROPERTY:   val = r.getProperty();        break;  
                    }
        
                return val;
                }
            catch (e) { throw(e); }
            }
        }   
    catch (e) { throw(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