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?
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') );
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?
Copy link to clipboard
Copied
Thank you very much!!!
Copy link to clipboard
Copied
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
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
Copy link to clipboard
Copied
The line
is responsible for a 1pt Stroke, but if 1px is intended one merely needs to change the unit.
Copy link to clipboard
Copied
Thank you very much!!!