Export/Save Photoshop analysis counts as a layer on the image

Dec 18, 2020

Copy link to clipboard

Copied

I have seen some posts about writing a script to export Photoshop analysis counts as a layer but scripting surpasses my level of expertise in Photoshop. Is there an easier way to save/export counts in Photoshop short of taking a screen shot?

 

I actually attempted to save and run the following script using File>Scripts>Scripts Event Manager but when I added the script and clicked done it didn't do anything.

 

// create text layers with numbers for count tool points;

// 2019, use it at your own risk;

#target photoshop

if (app.documents.length > 0) {

var ref = new ActionReference();

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

var docDesc = executeActionGet(ref);

if (docDesc.hasKey(stringIDToTypeID("countClass")) == true) {

// set to 72dpi and pixels;

var originalRulerUnits = preferences.rulerUnits;

preferences.rulerUnits = Units.PIXELS;

var myDocument = app.activeDocument;

var originalResolution = myDocument.resolution;

myDocument.resizeImage(undefined, undefined, 72, ResampleMethod.NONE);

// get coordinates;

var counter =docDesc.getList(stringIDToTypeID("countClass"));

var thePoints = new Array;

for (var c = 0; c < counter.count; c++) {

var thisOne = counter.getObjectValue(c);

thePoints.push([thisOne.getUnitDoubleValue(stringIDToTypeID("x")), thisOne.getUnitDoubleValue(stringIDToTypeID("y"))])

};

// create a smart object;

theArray = [[[[0,-3],[1.66,-3],[-1.66,-3],"SMOOTH"],

[[3,0],[3,1.66],[3,-1.66],"SMOOTH"],

[[0,3],[-1.66,3],[1.66,3],"SMOOTH"],

[[-3,0],[-3,-1.66],[-3,1.66],"SMOOTH"], true]];

var aPath = createPath10 (theArray, "circle");

aPath.select;

makeFillLayer ("circle", 0, 0, 0);

// convert to smart object ;

var id557 = charIDToTypeID( "slct" );

var desc108 = new ActionDescriptor();

var id558 = charIDToTypeID( "null" );

var ref77 = new ActionReference();

var id559 = charIDToTypeID( "Mn " );

var id560 = charIDToTypeID( "MnIt" );

var id561 = stringIDToTypeID( "newPlacedLayer" );

ref77.putEnumerated( id559, id560, id561 );

desc108.putReference( id558, ref77 );

executeAction( id557, desc108, DialogModes.NO );

var theSO = myDocument.activeLayer;

// remove path;

aPath.remove();

// create a set;

var theSet = myDocument.layerSets.add();

theSet.name = "connectTheDots";

// work through the path points;

for (var m = 0; m < thePoints.length; m++) {

var theArray = thePoints;

// make circle;

var theCircle = theSO.duplicate(theSet, ElementPlacement.PLACEATBEGINNING);

myDocument.activeLayer = theCircle;

theCircle.translate(theArray[0], theArray[1]);

theCircle.name = (m+1)+"_circle";

// make texts;

makeNumber (theSet, (m+1), theArray[0], theArray[1] - 12)

};

theSO.visible = false;

// reset image size;

myDocument.resizeImage(undefined, undefined, originalResolution, ResampleMethod.NONE);

preferences.rulerUnits = originalRulerUnits;

}

};

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

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

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

////// create number //////

function makeNumber (myDocument, theNumber, theX, theY) {

var textLayer = myDocument.artLayers.add();

textLayer.kind = LayerKind.TEXT;

textLayer.blendMode = BlendMode.NORMAL;

textLayer.opacity = 100;

var myTextRef = textLayer.textItem;

myTextRef.size = 24;

myTextRef.justification = Justification.CENTER;

myTextRef.font = "Courier";

var newColor = new SolidColor();

newColor.rgb.red = 0;

newColor.rgb.green = 0;

newColor.rgb.blue = 0;

myTextRef.color = newColor;

myTextRef.position = new Array(theX, theY);

myTextRef.contents = theNumber;

};

////// the fill-layer-function //////

function makeFillLayer (theName, theHue, theSat, theBright) {

// =======================================================

var idsetd = charIDToTypeID( "setd" );

var desc4 = new ActionDescriptor();

var idnull = charIDToTypeID( "null" );

var ref2 = new ActionReference();

var idClr = charIDToTypeID( "Clr " );

var idFrgC = charIDToTypeID( "FrgC" );

ref2.putProperty( idClr, idFrgC );

desc4.putReference( idnull, ref2 );

var idT = charIDToTypeID( "T " );

var desc5 = new ActionDescriptor();

var idH = charIDToTypeID( "H " );

var idAng = charIDToTypeID( "#Ang" );

desc5.putUnitDouble( idH, idAng, theHue );

var idStrt = charIDToTypeID( "Strt" );

desc5.putDouble( idStrt, theSat );

var idBrgh = charIDToTypeID( "Brgh" );

desc5.putDouble( idBrgh, theBright );

var idHSBC = charIDToTypeID( "HSBC" );

desc4.putObject( idT, idHSBC, desc5 );

executeAction( idsetd, desc4, DialogModes.NO );

// =======================================================

var id212 = charIDToTypeID( "Mk " );

var desc39 = new ActionDescriptor();

var id213 = charIDToTypeID( "null" );

var ref27 = new ActionReference();

var id214 = stringIDToTypeID( "contentLayer" );

ref27.putClass( id214 ); desc39.putReference( id213, ref27 );

var id215 = charIDToTypeID( "Usng" );

var desc40 = new ActionDescriptor();

var id216 = charIDToTypeID( "Type" );

var id217 = stringIDToTypeID( "solidColorLayer" );

desc40.putClass( id216, id217 );

var id218 = stringIDToTypeID( "contentLayer" );

desc39.putObject( id215, id218, desc40 );

executeAction( id212, desc39, DialogModes.NO );

app.activeDocument.activeLayer.name = theName;

return app.activeDocument.activeLayer

};

////// function to create path from array with one array per point that holds anchor, leftdirection, etc, 2010 //////

function createPath10 (theArray, thePathName) {

var originalRulerUnits = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.POINTS;

lineSubPathArray = new Array ();

if (theArray[theArray.length - 1].constructor != Array) {var numberOfPaths = theArray.length - 1}

else {var numberOfPaths = theArray.length};

for (var b = 0; b < numberOfPaths; b++) {

var lineArray = new Array ();

lineSubPathArray = new SubPathInfo();

if (theArray[theArray.length - 1].constructor == Array) {

lineSubPathArray.closed = true;

var numberOfPoints = theArray.length

}

else {

lineSubPathArray.closed = theArray[theArray.length - 1]

var numberOfPoints = theArray.length - 1

};

for (c = 0; c < numberOfPoints; c++) {

lineArray = new PathPointInfo;

switch (theArray[3]) {

case "CORNER":

lineArray.kind = PointKind.CORNERPOINT;

break;

case "SMOOTH":

lineArray.kind = PointKind.SMOOTHPOINT;

break;

default:

lineArray.kind = PointKind.CORNERPOINT;

break

};

lineArray.anchor = theArray[0];

if (theArray[1].length == 2) {lineArray.leftDirection = theArray[1]}

else {lineArray.leftDirection = theArray[0]};

if (theArray[2].length == 2) {lineArray.rightDirection = theArray[2]}

else {lineArray.rightDirection = theArray[0]};

};

lineSubPathArray.operation = ShapeOperation.SHAPEXOR;

lineSubPathArray.entireSubPath = lineArray;

};

var myPathItem = app.activeDocument.pathItems.add(thePathName, lineSubPathArray);

app.preferences.rulerUnits = originalRulerUnits;

return myPathItem

};

TOPICS
Actions and scripting, How to

Views

16

Likes

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

Export/Save Photoshop analysis counts as a layer on the image

Dec 18, 2020

Copy link to clipboard

Copied

I have seen some posts about writing a script to export Photoshop analysis counts as a layer but scripting surpasses my level of expertise in Photoshop. Is there an easier way to save/export counts in Photoshop short of taking a screen shot?

 

I actually attempted to save and run the following script using File>Scripts>Scripts Event Manager but when I added the script and clicked done it didn't do anything.

 

// create text layers with numbers for count tool points;

// 2019, use it at your own risk;

#target photoshop

if (app.documents.length > 0) {

var ref = new ActionReference();

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

var docDesc = executeActionGet(ref);

if (docDesc.hasKey(stringIDToTypeID("countClass")) == true) {

// set to 72dpi and pixels;

var originalRulerUnits = preferences.rulerUnits;

preferences.rulerUnits = Units.PIXELS;

var myDocument = app.activeDocument;

var originalResolution = myDocument.resolution;

myDocument.resizeImage(undefined, undefined, 72, ResampleMethod.NONE);

// get coordinates;

var counter =docDesc.getList(stringIDToTypeID("countClass"));

var thePoints = new Array;

for (var c = 0; c < counter.count; c++) {

var thisOne = counter.getObjectValue(c);

thePoints.push([thisOne.getUnitDoubleValue(stringIDToTypeID("x")), thisOne.getUnitDoubleValue(stringIDToTypeID("y"))])

};

// create a smart object;

theArray = [[[[0,-3],[1.66,-3],[-1.66,-3],"SMOOTH"],

[[3,0],[3,1.66],[3,-1.66],"SMOOTH"],

[[0,3],[-1.66,3],[1.66,3],"SMOOTH"],

[[-3,0],[-3,-1.66],[-3,1.66],"SMOOTH"], true]];

var aPath = createPath10 (theArray, "circle");

aPath.select;

makeFillLayer ("circle", 0, 0, 0);

// convert to smart object ;

var id557 = charIDToTypeID( "slct" );

var desc108 = new ActionDescriptor();

var id558 = charIDToTypeID( "null" );

var ref77 = new ActionReference();

var id559 = charIDToTypeID( "Mn " );

var id560 = charIDToTypeID( "MnIt" );

var id561 = stringIDToTypeID( "newPlacedLayer" );

ref77.putEnumerated( id559, id560, id561 );

desc108.putReference( id558, ref77 );

executeAction( id557, desc108, DialogModes.NO );

var theSO = myDocument.activeLayer;

// remove path;

aPath.remove();

// create a set;

var theSet = myDocument.layerSets.add();

theSet.name = "connectTheDots";

// work through the path points;

for (var m = 0; m < thePoints.length; m++) {

var theArray = thePoints;

// make circle;

var theCircle = theSO.duplicate(theSet, ElementPlacement.PLACEATBEGINNING);

myDocument.activeLayer = theCircle;

theCircle.translate(theArray[0], theArray[1]);

theCircle.name = (m+1)+"_circle";

// make texts;

makeNumber (theSet, (m+1), theArray[0], theArray[1] - 12)

};

theSO.visible = false;

// reset image size;

myDocument.resizeImage(undefined, undefined, originalResolution, ResampleMethod.NONE);

preferences.rulerUnits = originalRulerUnits;

}

};

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

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

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

////// create number //////

function makeNumber (myDocument, theNumber, theX, theY) {

var textLayer = myDocument.artLayers.add();

textLayer.kind = LayerKind.TEXT;

textLayer.blendMode = BlendMode.NORMAL;

textLayer.opacity = 100;

var myTextRef = textLayer.textItem;

myTextRef.size = 24;

myTextRef.justification = Justification.CENTER;

myTextRef.font = "Courier";

var newColor = new SolidColor();

newColor.rgb.red = 0;

newColor.rgb.green = 0;

newColor.rgb.blue = 0;

myTextRef.color = newColor;

myTextRef.position = new Array(theX, theY);

myTextRef.contents = theNumber;

};

////// the fill-layer-function //////

function makeFillLayer (theName, theHue, theSat, theBright) {

// =======================================================

var idsetd = charIDToTypeID( "setd" );

var desc4 = new ActionDescriptor();

var idnull = charIDToTypeID( "null" );

var ref2 = new ActionReference();

var idClr = charIDToTypeID( "Clr " );

var idFrgC = charIDToTypeID( "FrgC" );

ref2.putProperty( idClr, idFrgC );

desc4.putReference( idnull, ref2 );

var idT = charIDToTypeID( "T " );

var desc5 = new ActionDescriptor();

var idH = charIDToTypeID( "H " );

var idAng = charIDToTypeID( "#Ang" );

desc5.putUnitDouble( idH, idAng, theHue );

var idStrt = charIDToTypeID( "Strt" );

desc5.putDouble( idStrt, theSat );

var idBrgh = charIDToTypeID( "Brgh" );

desc5.putDouble( idBrgh, theBright );

var idHSBC = charIDToTypeID( "HSBC" );

desc4.putObject( idT, idHSBC, desc5 );

executeAction( idsetd, desc4, DialogModes.NO );

// =======================================================

var id212 = charIDToTypeID( "Mk " );

var desc39 = new ActionDescriptor();

var id213 = charIDToTypeID( "null" );

var ref27 = new ActionReference();

var id214 = stringIDToTypeID( "contentLayer" );

ref27.putClass( id214 ); desc39.putReference( id213, ref27 );

var id215 = charIDToTypeID( "Usng" );

var desc40 = new ActionDescriptor();

var id216 = charIDToTypeID( "Type" );

var id217 = stringIDToTypeID( "solidColorLayer" );

desc40.putClass( id216, id217 );

var id218 = stringIDToTypeID( "contentLayer" );

desc39.putObject( id215, id218, desc40 );

executeAction( id212, desc39, DialogModes.NO );

app.activeDocument.activeLayer.name = theName;

return app.activeDocument.activeLayer

};

////// function to create path from array with one array per point that holds anchor, leftdirection, etc, 2010 //////

function createPath10 (theArray, thePathName) {

var originalRulerUnits = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.POINTS;

lineSubPathArray = new Array ();

if (theArray[theArray.length - 1].constructor != Array) {var numberOfPaths = theArray.length - 1}

else {var numberOfPaths = theArray.length};

for (var b = 0; b < numberOfPaths; b++) {

var lineArray = new Array ();

lineSubPathArray = new SubPathInfo();

if (theArray[theArray.length - 1].constructor == Array) {

lineSubPathArray.closed = true;

var numberOfPoints = theArray.length

}

else {

lineSubPathArray.closed = theArray[theArray.length - 1]

var numberOfPoints = theArray.length - 1

};

for (c = 0; c < numberOfPoints; c++) {

lineArray = new PathPointInfo;

switch (theArray[3]) {

case "CORNER":

lineArray.kind = PointKind.CORNERPOINT;

break;

case "SMOOTH":

lineArray.kind = PointKind.SMOOTHPOINT;

break;

default:

lineArray.kind = PointKind.CORNERPOINT;

break

};

lineArray.anchor = theArray[0];

if (theArray[1].length == 2) {lineArray.leftDirection = theArray[1]}

else {lineArray.leftDirection = theArray[0]};

if (theArray[2].length == 2) {lineArray.rightDirection = theArray[2]}

else {lineArray.rightDirection = theArray[0]};

};

lineSubPathArray.operation = ShapeOperation.SHAPEXOR;

lineSubPathArray.entireSubPath = lineArray;

};

var myPathItem = app.activeDocument.pathItems.add(thePathName, lineSubPathArray);

app.preferences.rulerUnits = originalRulerUnits;

return myPathItem

};

TOPICS
Actions and scripting, How to

Views

17

Likes

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
Dec 18, 2020 0

Have something to add?

Join the conversation