@thomasm14148215
You can try this script:
/*
Plot Count Tool Co-ordinates From CSV.jsx
v1.0 2nd July 2024, Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/script-to-convert-x-y-coordinates-to-photoshop-counts/td-p/14713755
Note: There should be no header row - only X,Y pixel coordinates per row!
Based on:
https://community.adobe.com/t5/photoshop-ecosystem-discussions/csv-data-to-colour-pixels/m-p/14358713
*/
#target photoshop
app.activeDocument.suspendHistory ("Count from CSV...", "main()");
function main() {
if (app.documents.length) {
// Get and set the ruler units
var origRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
// Select and validate the CSV file
var csvFile = File.openDialog("Select the CSV file:");
if (csvFile.exists) {
if (csvFile.length > 0) {
// Hide panels
app.togglePalettes();
// CSV open, read & close
csvFile.open("r");
var theData = csvFile.read();
csvFile.close();
// CSV to array
var theDataArray = parseCSV(theData);
// Loop over the CSV data
for (var i = 0; i < theDataArray.length; i++) {
var csvValueX = theDataArray[i].toString().split(',')[0];
var csvValueY = theDataArray[i].toString().split(',')[1];
csvValueXcleaned = parseInt(csvValueX);
csvValueYcleaned = parseInt(csvValueY);
// Debugger
$.writeln(csvValueXcleaned);
$.writeln(csvValueYcleaned);
// Plot the count tool from the CSV coordinates
theCountTool(csvValueXcleaned, csvValueYcleaned)
}
// Restore the original ruler units
app.preferences.rulerUnits = origRulerUnits;
// End of script
app.togglePalettes();
app.beep();
// Select the count tool
(r = new ActionReference()).putClass(stringIDToTypeID('countTool'));
(d = new ActionDescriptor()).putReference(stringIDToTypeID('target'), r);
executeAction(stringIDToTypeID('select'), d, DialogModes.NO);
} else {
app.beep();
alert('The CSV file is blank!');
}
}
} else {
alert('You must have a document open!');
}
}
///// FUNCTIONS /////
function theCountTool(theX, theY) {
var s2t = function (s) {
return app.stringIDToTypeID(s);
};
var descriptor = new ActionDescriptor();
descriptor.putDouble(s2t("x"), theX);
descriptor.putDouble(s2t("y"), theY);
executeAction(s2t("countAdd"), descriptor, DialogModes.NO);
}
function parseCSV(theData, delimiter) {
/*
Courtesy of William Campbell
https://community.adobe.com/t5/photoshop-ecosystem-discussions/does-any\.$one-have-a-script-that-utilizes-a-csv-to-create-text-layers/m-p/13117458
*/
// theData: String = contents of a CSV csvFile
// delimiter: character that separates columns
// undefined defaults to comma
// Returns: Array [[String row, String column]]
var c = ""; // Character at index
var d = delimiter || ","; // Default to comma
var endIndex = theData.length;
var index = 0;
var maxIndex = endIndex - 1;
var q = false; // "Are we in quotes?"
var result = []; // Array of rows (array of column arrays)
var row = []; // Array of columns
var v = ""; // Column value
while (index < endIndex) {
c = theData[index];
if (q) { // In quotes
if (c == "\"") {
// Found quote; look ahead for another
if (index < maxIndex && theData[index + 1] == "\"") {
// Found another quote means escaped
// Increment and add to column value
index++;
v += c;
} else {
// Next character not a quote; last quote not escaped
q = !q; // Toggle "Are we in quotes?"
}
} else {
// Add character to column value
v += c;
}
} else { // Not in quotes
if (c == "\"") {
// Found quote
q = !q; // Toggle "Are we in quotes?"
} else if (c == "\n" || c == "\r") {
// Reached end of line
// Test for CRLF
if (c == "\r" && index < maxIndex) {
if (theData[index + 1] == "\n") {
// Skip trailing newline
index++;
}
}
// Column and row complete
row.push(v);
v = "";
// Add row to result if first row or length matches first row
if (result.length === 0 || row.length == result[0].length) {
result.push(row);
}
row = [];
} else if (c == d) {
// Found comma; column complete
row.push(v);
v = "";
} else {
// Add character to column value
v += c;
}
}
if (index == maxIndex) {
// Reached end of theData; flush
if (v.length || c == d) {
row.push(v);
}
// Add row to result if length matches first row
if (row.length == result[0].length) {
result.push(row);
}
break;
}
index++;
}
return result;
}
https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html