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

Circle in new Layer Javascript

Community Beginner ,
Jan 12, 2017 Jan 12, 2017

Copy link to clipboard

Copied

Hello, i´m using photoshop CS6, i need a javascript code to create a 6mm circle with a white fill color and a 1px black stroke, all this aligned to center in a new layer.

Is it possible?

Captura.PNG

TOPICS
Actions and scripting

Views

508

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Jan 16, 2017 Jan 16, 2017

Hi Ballestero​,

do you mean pixel? Or vector?

I prefer vector. Here is an example:

createCircle (3);

function createCircle(dia) {

  function cTID(s) { return app.charIDToTypeID(s); };

  function sTID(s) { return app.stringIDToTypeID(s); };

    dia = new UnitValue( dia, 'mm' ).as( 'px' );

    aDoc = activeDocument;

    w2 = aDoc.width.as( 'px' )/2;

    h2 = aDoc.height.as( 'px' )/2;

    var desc2 = new ActionDescriptor();

        var ref2 = new ActionReference();

        ref2.putClass( sTID('contentLayer') );

...

Votes

Translate

Translate
Adobe
Community Expert ,
Jan 12, 2017 Jan 12, 2017

Copy link to clipboard

Copied

Why not simply record a action it would be easy and faster than a script. And recorded in a couple of minuets?

Capture.jpg

JJMack

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 Beginner ,
Jan 17, 2017 Jan 17, 2017

Copy link to clipboard

Copied

Thank you very much!!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 17, 2017 Jan 17, 2017

Copy link to clipboard

Copied

LATEST

Ballestero

You're welcome.

Here is a little more better code - now you can insert diameter instead of radius and I've implemented suggestion of c.pfaffenbichler

createCircle (6); // insert diameter value

function createCircle(dia) {

  function cTID(s) { return app.charIDToTypeID(s); };

  function sTID(s) { return app.stringIDToTypeID(s); };

    rad = new UnitValue( dia, 'mm' ).as( 'px' )/2;

    aDoc = activeDocument;

    w2 = aDoc.width.as( 'px' )/2;

    h2 = aDoc.height.as( 'px' )/2;

    var desc2 = new ActionDescriptor();

        var ref2 = new ActionReference();

        ref2.putClass( sTID('contentLayer') );

    desc2.putReference( cTID('null'), ref2 );

        var desc3 = new ActionDescriptor();

            var desc4 = new ActionDescriptor();

                var desc5 = new ActionDescriptor();

                desc5.putDouble( cTID('Rd  '), 255 );

                desc5.putDouble( cTID('Grn '), 0 );

                desc5.putDouble( cTID('Bl  '), 0 );

            desc4.putObject( cTID('Clr '), cTID('RGBC'), desc5 );

        desc3.putObject( cTID('Type'), sTID('solidColorLayer'), desc4 );

            var desc6 = new ActionDescriptor();

            desc6.putInteger( sTID('unitValueQuadVersion'), 1 );

            desc6.putUnitDouble( cTID('Top '), cTID('#Pxl'), h2-rad );

            desc6.putUnitDouble( cTID('Left'), cTID('#Pxl'), w2-rad );

            desc6.putUnitDouble( cTID('Btom'), cTID('#Pxl'), h2+rad );

            desc6.putUnitDouble( cTID('Rght'), cTID('#Pxl'), h2+rad );

        desc3.putObject( cTID('Shp '), cTID('Elps'), desc6 );

            var desc7 = new ActionDescriptor();

            desc7.putInteger( sTID('strokeStyleVersion'), 2 );

            desc7.putBoolean( sTID('strokeEnabled'), true );

            desc7.putBoolean( sTID('fillEnabled'), true );

            desc7.putUnitDouble( sTID('strokeStyleLineWidth'), cTID('#Pxl'), 1 );

            desc7.putUnitDouble( sTID('strokeStyleLineDashOffset'), cTID('#Pnt'), 0 );

            desc7.putDouble( sTID('strokeStyleMiterLimit'), 100 );

            desc7.putEnumerated( sTID('strokeStyleLineCapType'), sTID('strokeStyleLineCapType'), sTID('strokeStyleButtCap') );

            desc7.putEnumerated( sTID('strokeStyleLineJoinType'), sTID('strokeStyleLineJoinType'), sTID('strokeStyleMiterJoin') );

            desc7.putEnumerated( sTID('strokeStyleLineAlignment'), sTID('strokeStyleLineAlignment'), sTID('strokeStyleAlignInside') );

            desc7.putBoolean( sTID('strokeStyleScaleLock'), false );

            desc7.putBoolean( sTID('strokeStyleStrokeAdjust'), false );

                var list1 = new ActionList();

            desc7.putList( sTID('strokeStyleLineDashSet'), list1 );

            desc7.putEnumerated( sTID('strokeStyleBlendMode'), cTID('BlnM'), cTID('Nrml') );

            desc7.putUnitDouble( sTID('strokeStyleOpacity'), cTID('#Prc'), 100 );

                var desc8 = new ActionDescriptor();

                    var desc9 = new ActionDescriptor();

                    desc9.putDouble( cTID('Rd  '), 0 );

                    desc9.putDouble( cTID('Grn '), 0 );

                    desc9.putDouble( cTID('Bl  '), 0 );

                desc8.putObject( cTID('Clr '), cTID('RGBC'), desc9 );

            desc7.putObject( sTID('strokeStyleContent'), sTID('solidColorLayer'), desc8 );

            desc7.putDouble( sTID('strokeStyleResolution'), 72 );

        desc3.putObject( sTID('strokeStyle'), sTID('strokeStyle'), desc7 );

    desc2.putObject( cTID('Usng'), sTID('contentLayer'), desc3 );

    desc2.putInteger( cTID('LyrI'), 2 );

    executeAction( cTID('Mk  '), desc2, DialogModes.NO );

};

Have fun

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 16, 2017 Jan 16, 2017

Copy link to clipboard

Copied

Hi Ballestero​,

do you mean pixel? Or vector?

I prefer vector. Here is an example:

createCircle (3);

function createCircle(dia) {

  function cTID(s) { return app.charIDToTypeID(s); };

  function sTID(s) { return app.stringIDToTypeID(s); };

    dia = new UnitValue( dia, 'mm' ).as( 'px' );

    aDoc = activeDocument;

    w2 = aDoc.width.as( 'px' )/2;

    h2 = aDoc.height.as( 'px' )/2;

    var desc2 = new ActionDescriptor();

        var ref2 = new ActionReference();

        ref2.putClass( sTID('contentLayer') );

    desc2.putReference( cTID('null'), ref2 );

        var desc3 = new ActionDescriptor();

            var desc4 = new ActionDescriptor();

                var desc5 = new ActionDescriptor();

                desc5.putDouble( cTID('Rd  '), 255 );

                desc5.putDouble( cTID('Grn '), 0 );

                desc5.putDouble( cTID('Bl  '), 0 );

            desc4.putObject( cTID('Clr '), cTID('RGBC'), desc5 );

        desc3.putObject( cTID('Type'), sTID('solidColorLayer'), desc4 );

            var desc6 = new ActionDescriptor();

            desc6.putInteger( sTID('unitValueQuadVersion'), 1 );

            desc6.putUnitDouble( cTID('Top '), cTID('#Pxl'), h2-dia );

            desc6.putUnitDouble( cTID('Left'), cTID('#Pxl'), w2-dia );

            desc6.putUnitDouble( cTID('Btom'), cTID('#Pxl'), h2+dia );

            desc6.putUnitDouble( cTID('Rght'), cTID('#Pxl'), h2+dia );

        desc3.putObject( cTID('Shp '), cTID('Elps'), desc6 );

            var desc7 = new ActionDescriptor();

            desc7.putInteger( sTID('strokeStyleVersion'), 2 );

            desc7.putBoolean( sTID('strokeEnabled'), true );

            desc7.putBoolean( sTID('fillEnabled'), true );

            desc7.putUnitDouble( sTID('strokeStyleLineWidth'), cTID('#Pnt'), 1 );

            desc7.putUnitDouble( sTID('strokeStyleLineDashOffset'), cTID('#Pnt'), 0 );

            desc7.putDouble( sTID('strokeStyleMiterLimit'), 100 );

            desc7.putEnumerated( sTID('strokeStyleLineCapType'), sTID('strokeStyleLineCapType'), sTID('strokeStyleButtCap') );

            desc7.putEnumerated( sTID('strokeStyleLineJoinType'), sTID('strokeStyleLineJoinType'), sTID('strokeStyleMiterJoin') );

            desc7.putEnumerated( sTID('strokeStyleLineAlignment'), sTID('strokeStyleLineAlignment'), sTID('strokeStyleAlignInside') );

            desc7.putBoolean( sTID('strokeStyleScaleLock'), false );

            desc7.putBoolean( sTID('strokeStyleStrokeAdjust'), false );

                var list1 = new ActionList();

            desc7.putList( sTID('strokeStyleLineDashSet'), list1 );

            desc7.putEnumerated( sTID('strokeStyleBlendMode'), cTID('BlnM'), cTID('Nrml') );

            desc7.putUnitDouble( sTID('strokeStyleOpacity'), cTID('#Prc'), 100 );

                var desc8 = new ActionDescriptor();

                    var desc9 = new ActionDescriptor();

                    desc9.putDouble( cTID('Rd  '), 0 );

                    desc9.putDouble( cTID('Grn '), 0 );

                    desc9.putDouble( cTID('Bl  '), 0 );

                desc8.putObject( cTID('Clr '), cTID('RGBC'), desc9 );

            desc7.putObject( sTID('strokeStyleContent'), sTID('solidColorLayer'), desc8 );

            desc7.putDouble( sTID('strokeStyleResolution'), 72 );

        desc3.putObject( sTID('strokeStyle'), sTID('strokeStyle'), desc7 );

    desc2.putObject( cTID('Usng'), sTID('contentLayer'), desc3 );

    desc2.putInteger( cTID('LyrI'), 2 );

    executeAction( cTID('Mk  '), desc2, DialogModes.NO );

};

Have fun

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 17, 2017 Jan 17, 2017

Copy link to clipboard

Copied

The line

  1.             desc7.putUnitDouble( sTID('strokeStyleLineWidth'), cTID('#Pnt'), 1 ); 

is responsible for a 1pt Stroke, but if 1px is intended one merely needs to change the unit.

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 Beginner ,
Jan 17, 2017 Jan 17, 2017

Copy link to clipboard

Copied

Thank you very much!!!

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