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

rotating brushes using file stream of saved brushes in javascript

Community Expert ,
Sep 06, 2009 Sep 06, 2009

Once again I’m fascinated by a query in the MacIntosh-forum which’s solution I suspect is within JavaScript’s reach but out of my depth – namely:

Can one rotate a brush by Keyboard Shortcut, like in- or decreasing its size or softness?

I mostly use the round brushes myself, so it’s not like I even miss the capability …

I suspect by saving a Brush Preset, then saving that one alone as an abr-file, deleting the Brush Preset, reading and editing the abr.file, loading it, selecting the single Brush Preset contained and deleting it, too, one might achieve it.

Of course editing the abr-file with a Script seems a bit risky to me.

On xbytor’s advice I downloaded HexEditor, but the Brush Tip Shape-Angle-setting mystifies me … »AnglUntF#Ang@« seems to be the one but I fail to understand the angle-value …

Furthermore the total number of brushes (for indexing purposes) eludes me.

Anyway, the procedure may be too complicated or time-consuming to make any practical sense (apart from inserting numerous steps in the history, which might be a further drawback in real working conditions), but I guess some of You like exploring theoretical applications of Scripting-techniques, so maybe You could give me Your opinions/advice on the whole matter.

TOPICS
Actions and scripting
10.9K
Translate
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 ,
Sep 06, 2009 Sep 06, 2009

There may be something here that might help Christoph..

http://www.ps-scripts.com/bb/viewtopic.php?t=2801

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 06, 2009 Sep 06, 2009

Wow, thanks!

I didn’t seem to get any ScriptingListener-code from changing Brush-settings, so I kind of wandered off …

Great stuff!

Edit: Sorry I ranked Your post as helpful, because now I can’t seem to rank it as the correct answer.

Translate
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 Beginner ,
Sep 08, 2009 Sep 08, 2009

This is a function (the ability to rotate the angle of a brush on the fly, with key commands) that I would love! I'm a digital illustrator and I work primarily in Photoshop CS3, but if it would be necessary to buy CS 4 in order to access such a function, it would be worth it to me.

Another feature I would flip for would be to be able to pop open the Color Picker box with a key command. Perhaps I should post a question about that here?

Translate
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
Valorous Hero ,
Sep 08, 2009 Sep 08, 2009

You can get a limited Colour Picker using..

$.colorPicker( -1 );

Translate
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 Beginner ,
Sep 08, 2009 Sep 08, 2009

Paul, I'm very grateful for your response! It would be wonderful to have the ability to get the color picker to pop open while I paint. But I am utterly unfamiliar with how to utilize that (I know nothing of scripting and came to this forum through a search about rotating the angle of my brush on the fly). Would you point me to where I could learn how to use what you suggest?

Translate
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
Guru ,
Sep 08, 2009 Sep 08, 2009

Here is an example of the color picker Paul suggested. It doesn't use the Photoshop color picker. It uses the OS version.

var result = $.colorPicker( -1 ).toString(16);
if( result != -1 ){
    var pad = '00000';
    var fillColour = new SolidColor;
    fillColour.rgb.hexValue = result.length < 6 ? pad.substring( 0, 6 - result.length ) + result : result;
    app.foregroundColor= fillColour;
}

Translate
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
Valorous Hero ,
Sep 08, 2009 Sep 08, 2009

Open ExtendScript Toolkit, this gets installed with Photoshop and can be found...
PC: C:\Program Files\Adobe\Adobe Utilities
MAC: <hard drive>/Applications/Utilities/Adobe Utilities

Copy and paste in the code and save it to...

PC:- C:/Program Files/Adobe/Adobe Photoshop CS3/Presets/Scripts/
Mac:- [hard drive]/Applications/Adobe Photoshop CS3/Presets/Scripts/

If you had Photoshop open, close and re-start Photoshop.
You can now create an action to call the script, start the recording (allocating a Function Key), (in the action palette) select Insert Menu Item...
Now select the script by. File - Scripts and select the script, stop the recording.
You can now use the Function key to open the Colour Picker.

Hope this helps.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 08, 2009 Sep 08, 2009

Wouldn’t it be more convenient to assign the Script a shortcut in Keyboard Shortcuts instead of recording it into an Action?

Translate
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
Valorous Hero ,
Sep 08, 2009 Sep 08, 2009

Yes that would work just as good Christoph

Edit - Keyboard Shortcuts - File , down to scripts and create your own shortcut for the script.

The script could be called from the help or filter menu using a Resource string as well.

Translate
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 Beginner ,
Sep 08, 2009 Sep 08, 2009

Fantastic! Thank you so much! I did it and it works great.

What I'd really like is for the Photoshop Color Picker to be always open, so I could use it as a floating palette and select colors as I'm painting, moving the spectrum side bar and all that. That would be so wonderful.

Thank you so very much, again, to all of you for your help and insights. I think I'll go to Lynda.com and see if they offer classes in Photoshop scripting.

Translate
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
Guru ,
Sep 08, 2009 Sep 08, 2009

Even with CS4 I think you would only be able to step the angle by a set amount.

There are keyboard shortcuts in CS4 to change size and hardness on the fly.

I have never seen anyone come up with a way to have a popup color picker via scripting.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 08, 2009 Sep 08, 2009

How about a crude workaround: setting the historyState, creating a Solid Fill-Layer with measurements of something like 0,0,1,1 (making it unobtrusive) without dialog, then editing that via ScriptingListener-code and DialogModes.ALL thus invoking the color picker, retrieving the chosen values with xbytor’s getAdjustmentLayerColor-function, returning to the historyState and setting the foregroundColor to the resulting value?

The results are not number-perfect, though …

Translate
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
Guru ,
Sep 08, 2009 Sep 08, 2009

That is a good idea Christoph,

Below is a slightly different approach that use the same idea. Make a solid fill adjustment layer and name it 'script color picker'. It does not matter what color you choose. Turn the layer off. Now with the script below attached to a keyboard shortcut every time the script is run it remembers the current active layer, selects the fill layer, turns it on and pops up the Adobe color picker. It then sets the selected color to the foreground, turns off the layer and returns to the layer that was active.

Note that this is just a concept script. There is no error checking and it only been tested with CS4 WinXP. It should work with other vesions.

function f(){

// make a reference to activeLayer

var currLayerName = app.activeDocument.activeLayer.name;
var currLayer = app.activeDocument.layers.getByName(currLayerName);
// select the solid fill layer
app.activeDocument.activeLayer = app.activeDocument.layers.getByName('script color picker');
// make visible
app.activeDocument.activeLayer.visible = true;

// set starting color
var startCOlor = [ 127,127,127 ];
// call the color picker
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( stringIDToTypeID( "contentLayer" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
desc.putReference( charIDToTypeID( "null" ), ref );
var modeDesc = new ActionDescriptor();
var colorDesc = new ActionDescriptor();
colorDesc.putDouble( charIDToTypeID( "Rd  " ), startCOlor[ 0 ] );
colorDesc.putDouble( charIDToTypeID( "Grn " ), startCOlor[ 1 ] );
colorDesc.putDouble( charIDToTypeID( "Bl  " ), startCOlor[ 2 ] );
modeDesc.putObject( charIDToTypeID( "Clr " ), charIDToTypeID( "RGBC" ), colorDesc );
desc.putObject( charIDToTypeID( "T   " ), stringIDToTypeID( "solidColorLayer" ), modeDesc );
executeAction( charIDToTypeID( "setd" ), desc, DialogModes.ALL )

// get user's color and set to forground color
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet(ref)
var adjList = desc.getList(stringIDToTypeID('adjustment'));
var adjDesc = adjList.getObjectValue(0);
var colorDesc = adjDesc.getObjectValue(stringIDToTypeID('color'));

var color = new SolidColor();
color.rgb.red = colorDesc.getDouble(charIDToTypeID('Rd  '));
color.rgb.green = colorDesc.getDouble(charIDToTypeID('Grn '));
color.rgb.blue = colorDesc.getDouble(charIDToTypeID('Bl  '));
app.foregroundColor = color;

// restore
app.activeDocument.activeLayer.visible = false;
app.activeDocument.activeLayer = currLayer;

}

edit: sorry for the typos - my mind runs faster than my fingers

Translate
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 Beginner ,
Sep 08, 2009 Sep 08, 2009

I tried it (I'm using PS CS3 on a Mac) and it isn't working. It's entirely possible I'm doing something wrong. I tried naming the solid fill adjustment layer with and without the single quotes; made no difference. Nothing happens.

It would be so amazing if I could get this to work. I am over-the-moon-grateful for your efforts in this. Should I start a new thread about this so that the subject line is pertinent?

Translate
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
Guru ,
Sep 08, 2009 Sep 08, 2009

Sorry, I set it up as a function with the simple name of 'f'. To use add a line at the bottom to call the function...

f();

Then follow Paul's instructions above. Make sure you use a plain text editor if you use a different editor to pasted and save. You could also edit the layer name if you like. No quotes in the layer's name in the panel.

Translate
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
Valorous Hero ,
Sep 08, 2009 Sep 08, 2009

Just found that as is it didn't work with CS3.

But moving ..

app.foregroundColor = color;

to the last line it all worked fine.

Translate
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 Beginner ,
Sep 08, 2009 Sep 08, 2009

I tried it, but it's still not working for me. I must be doing something wrong. Let me know if I've got something mixed up in the way that I've tried to fix the code per your suggestions--a million thanks in advance:

function f(){

// make a reference to activeLayer

var currLayerName = app.activeDocument.activeLayer.name;

var currLayer = app.activeDocument.layers.getByName(currLayerName);

// select the solid fill layer

app.activeDocument.activeLayer = app.activeDocument.layers.getByName('script color picker');

// make visible

app.activeDocument.activeLayer.visible = true;

// set starting color

var startCOlor = [ 127,127,127 ];

// call the color picker

var desc = new ActionDescriptor();

var ref = new ActionReference();

ref.putEnumerated( stringIDToTypeID( "contentLayer" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );

desc.putReference( charIDToTypeID( "null" ), ref );

var modeDesc = new ActionDescriptor();

var colorDesc = new ActionDescriptor();

colorDesc.putDouble( charIDToTypeID( "Rd  " ), startCOlor[ 0 ] );

colorDesc.putDouble( charIDToTypeID( "Grn " ), startCOlor[ 1 ] );

colorDesc.putDouble( charIDToTypeID( "Bl  " ), startCOlor[ 2 ] );

modeDesc.putObject( charIDToTypeID( "Clr " ), charIDToTypeID( "RGBC" ), colorDesc );

desc.putObject( charIDToTypeID( "T   " ), stringIDToTypeID( "solidColorLayer" ), modeDesc );

executeAction( charIDToTypeID( "setd" ), desc, DialogModes.ALL )

// get user's color and set to forground color

var ref = new ActionReference();

ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

var desc = executeActionGet(ref)

var adjList = desc.getList(stringIDToTypeID('adjustment'));

var adjDesc = adjList.getObjectValue(0);

var colorDesc = adjDesc.getObjectValue(stringIDToTypeID('color'));

var color = new SolidColor();

color.rgb.red = colorDesc.getDouble(charIDToTypeID('Rd  '));

color.rgb.green = colorDesc.getDouble(charIDToTypeID('Grn '));

color.rgb.blue = colorDesc.getDouble(charIDToTypeID('Bl  '));

// restore

app.activeDocument.activeLayer.visible = false;

app.activeDocument.activeLayer = currLayer;

app.foregroundColor = color;

f();

}

Translate
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
Valorous Hero ,
Sep 08, 2009 Sep 08, 2009

The f(); should be after the brace ie:

}

f();

Translate
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 Beginner ,
Sep 08, 2009 Sep 08, 2009

It's getting there, I think! Now, when I try to run the script witht eh keyboard command, I get this message:

Error 1302: No such element

Line: 6

-> var currLayer =

app.activeDocument.layers.getByName(currLayerName)

I tried it with various layers in the document (there are about 25 layers), but it comes up no matter what.

Then I tried creating a new document, and it worked fine,and continued to, on each new layer as I created layers. But as soon as I made a group of layers into a layer set, it gave me that error. I wonder if there's a workaround for dealing with layer sets?

Whether there is or isn't, this is very cool! Scripting is magic! I want to learn. But it looks pretty complicated.

Again, thank you all so much for your amazing help with this. I'm bowled over by your generosity and smarts.

Translate
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
Valorous Hero ,
Sep 08, 2009 Sep 08, 2009

You could try this..

This creates its own colour layer and then removes it when finished...

f();
function f(){
// create colour layer
CreateSolidLayer();
// set starting color
var startCOlor = [ 127,127,127 ];
// call the color picker
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( stringIDToTypeID( "contentLayer" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
desc.putReference( charIDToTypeID( "null" ), ref );
var modeDesc = new ActionDescriptor();
var colorDesc = new ActionDescriptor();
colorDesc.putDouble( charIDToTypeID( "Rd  " ), startCOlor[ 0 ] );
colorDesc.putDouble( charIDToTypeID( "Grn " ), startCOlor[ 1 ] );
colorDesc.putDouble( charIDToTypeID( "Bl  " ), startCOlor[ 2 ] );
modeDesc.putObject( charIDToTypeID( "Clr " ), charIDToTypeID( "RGBC" ), colorDesc );
desc.putObject( charIDToTypeID( "T   " ), stringIDToTypeID( "solidColorLayer" ), modeDesc );
executeAction( charIDToTypeID( "setd" ), desc, DialogModes.ALL )
// get user's color and set to forground color
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet(ref)
var adjList = desc.getList(stringIDToTypeID('adjustment'));
var adjDesc = adjList.getObjectValue(0);
var colorDesc = adjDesc.getObjectValue(stringIDToTypeID('color'));
var Colour = new SolidColor();
Colour.rgb.red = colorDesc.getDouble(charIDToTypeID('Rd  '));
Colour.rgb.green = colorDesc.getDouble(charIDToTypeID('Grn '));
Colour.rgb.blue = colorDesc.getDouble(charIDToTypeID('Bl  '));
// restore
activeDocument.activeLayer.remove();
app.foregroundColor = Colour;
}

function CreateSolidLayer() {
    var desc121 = new ActionDescriptor();
        var ref71 = new ActionReference();
        ref71.putClass( stringIDToTypeID('contentLayer') );
    desc121.putReference( charIDToTypeID('null'), ref71 );
        var desc122 = new ActionDescriptor();
            var desc123 = new ActionDescriptor();
                var desc124 = new ActionDescriptor();
                desc124.putDouble( charIDToTypeID('Rd  '), 0.000000 );
                desc124.putDouble( charIDToTypeID('Grn '), 0.000000 );
                desc124.putDouble( charIDToTypeID('Bl  '), 0.000000 );
            desc123.putObject( charIDToTypeID('Clr '), charIDToTypeID('RGBC'), desc124 );
        desc122.putObject( charIDToTypeID('Type'), stringIDToTypeID('solidColorLayer'), desc123 );
    desc121.putObject( charIDToTypeID('Usng'), stringIDToTypeID('contentLayer'), desc122 );
    executeAction( charIDToTypeID('Mk  '), desc121, DialogModes.NO );
};

Translate
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 Beginner ,
Sep 08, 2009 Sep 08, 2009

Whoa!! It worked! Soooo cool!

You guys are great.

Translate
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
Guru ,
Sep 08, 2009 Sep 08, 2009

I thought that it might be nice if it started with the color you were using at the time the script runs. That way if you are doing shading, to would already be at the current color. So here is a cleaned up commented version that does that.

colorPicker();
/////////////////////////////////////////////////////////////////
// Function: colorPicker
// Description: Creates a temp solidcolor adjustment layer to
//                let the user set the forground color then
//                removes the temp layer.  
// Usage: colorpicker()
// Input: None
// Return: None
// Dependencies: None
// Notes:             
//////////////////////////////////////////////////////////////////
function colorPicker(){
    // create colour layer
    CreateSolidLayer();
    // set starting color
    var startColor = app.foregroundColor;
    // call the color picker
    var desc = new ActionDescriptor();
        var ref = new ActionReference();
        ref.putEnumerated( stringIDToTypeID( "contentLayer" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
    desc.putReference( charIDToTypeID( "null" ), ref );
    var modeDesc = new ActionDescriptor();
        var colorDesc = new ActionDescriptor();
            colorDesc.putDouble( charIDToTypeID( "Rd  " ), startColor.rgb.red );
            colorDesc.putDouble( charIDToTypeID( "Grn " ), startColor.rgb.green );
            colorDesc.putDouble( charIDToTypeID( "Bl  " ), startColor.rgb.blue );
        modeDesc.putObject( charIDToTypeID( "Clr " ), charIDToTypeID( "RGBC" ), colorDesc );
    desc.putObject( charIDToTypeID( "T   " ), stringIDToTypeID( "solidColorLayer" ), modeDesc );
    executeAction( charIDToTypeID( "setd" ), desc, DialogModes.ALL )
    // get user's color and set to forground color
    var ref = new ActionReference();
        ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
    var desc = executeActionGet(ref)
    var adjList = desc.getList(stringIDToTypeID('adjustment'));
    var adjDesc = adjList.getObjectValue(0);
    var colorDesc = adjDesc.getObjectValue(stringIDToTypeID('color'));
    var Colour = new SolidColor();
        Colour.rgb.red = colorDesc.getDouble(charIDToTypeID('Rd  '));
        Colour.rgb.green = colorDesc.getDouble(charIDToTypeID('Grn '));
        Colour.rgb.blue = colorDesc.getDouble(charIDToTypeID('Bl  '));
    // restore
    activeDocument.activeLayer.remove();
    app.foregroundColor = Colour;
    }

    function CreateSolidLayer() {
        var desc = new ActionDescriptor();
            var ref = new ActionReference();
            ref.putClass( stringIDToTypeID('contentLayer') );
        desc.putReference( charIDToTypeID('null'), ref );
            var desc1 = new ActionDescriptor();
                var desc2 = new ActionDescriptor();
                    var desc3 = new ActionDescriptor();
                    desc3.putDouble( charIDToTypeID('Rd  '), 0.000000 );
                    desc3.putDouble( charIDToTypeID('Grn '), 0.000000 );
                    desc3.putDouble( charIDToTypeID('Bl  '), 0.000000 );
                desc2.putObject( charIDToTypeID('Clr '), charIDToTypeID('RGBC'), desc3 );
            desc1.putObject( charIDToTypeID('Type'), stringIDToTypeID('solidColorLayer'), desc2 );
        desc.putObject( charIDToTypeID('Usng'), stringIDToTypeID('contentLayer'), desc1 );
        executeAction( charIDToTypeID('Mk  '), desc, DialogModes.NO );
};

Translate
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 Beginner ,
Sep 08, 2009 Sep 08, 2009

That's a totally great idea! The only thing is, when I run it (I'm on PS CS3, if that makes a difference), it pops up the color picker with black selected in the color picker window...if I eyedropper the foreground color in the color box at the bottom of the toolbar, then it moves the selector circle in the color picker window to the proper place...but the layer you (briefely) create and the color chosen in the color picker window is black (R=0, G=0, B=0)

Am I explaining that OK? And am I doing something wrong?

Translate
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
Guru ,
Sep 08, 2009 Sep 08, 2009

Strange it works in CS4 and I can't understand why it wouldn't work in CS3 but if you are seeing black I would think this should fix it.

colorPicker();
/////////////////////////////////////////////////////////////////
// Function: colorPicker
// Description: Creates a temp solidcolor adjustment layer to
//                let the user set the forground color
//                  
// Usage: colorpicker()
// Input: None
// Return: None
// Dependencies: None
// Notes:             
//////////////////////////////////////////////////////////////////
function colorPicker(){
    // set starting color
    var startColor = app.foregroundColor;
    // create colour layer
    CreateSolidLayer();
    // call the color picker
    var desc = new ActionDescriptor();
        var ref = new ActionReference();
        ref.putEnumerated( stringIDToTypeID( "contentLayer" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
    desc.putReference( charIDToTypeID( "null" ), ref );
    var modeDesc = new ActionDescriptor();
        var colorDesc = new ActionDescriptor();
            colorDesc.putDouble( charIDToTypeID( "Rd  " ), startColor.rgb.red );
            colorDesc.putDouble( charIDToTypeID( "Grn " ), startColor.rgb.green );
            colorDesc.putDouble( charIDToTypeID( "Bl  " ), startColor.rgb.blue );
        modeDesc.putObject( charIDToTypeID( "Clr " ), charIDToTypeID( "RGBC" ), colorDesc );
    desc.putObject( charIDToTypeID( "T   " ), stringIDToTypeID( "solidColorLayer" ), modeDesc );
    executeAction( charIDToTypeID( "setd" ), desc, DialogModes.ALL )
    // get user's color and set to forground color
    var ref = new ActionReference();
        ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
    var desc = executeActionGet(ref)
    var adjList = desc.getList(stringIDToTypeID('adjustment'));
    var adjDesc = adjList.getObjectValue(0);
    var colorDesc = adjDesc.getObjectValue(stringIDToTypeID('color'));
    var Colour = new SolidColor();
        Colour.rgb.red = colorDesc.getDouble(charIDToTypeID('Rd  '));
        Colour.rgb.green = colorDesc.getDouble(charIDToTypeID('Grn '));
        Colour.rgb.blue = colorDesc.getDouble(charIDToTypeID('Bl  '));
    // restore
    activeDocument.activeLayer.remove();
    app.foregroundColor = Colour;
    }

    function CreateSolidLayer() {
        var startColor = app.foregroundColor;
        var desc = new ActionDescriptor();
            var ref = new ActionReference();
            ref.putClass( stringIDToTypeID('contentLayer') );
        desc.putReference( charIDToTypeID('null'), ref );
            var desc1 = new ActionDescriptor();
                var desc2 = new ActionDescriptor();
                    var desc3 = new ActionDescriptor();
                    desc3.putDouble( charIDToTypeID('Rd  '), startColor.rgb.red );
                    desc3.putDouble( charIDToTypeID('Grn '), startColor.rgb.green );
                    desc3.putDouble( charIDToTypeID('Bl  '), startColor.rgb.blue );
                desc2.putObject( charIDToTypeID('Clr '), charIDToTypeID('RGBC'), desc3 );
            desc1.putObject( charIDToTypeID('Type'), stringIDToTypeID('solidColorLayer'), desc2 );
        desc.putObject( charIDToTypeID('Usng'), stringIDToTypeID('contentLayer'), desc1 );
        executeAction( charIDToTypeID('Mk  '), desc, DialogModes.NO );
};

Translate
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