Mobile app version of vmapp.org
Login or Join
Gloria351

: Get all text in layer by script in CS6 I'm using photoshop to support my job so I want to know how to get all text in layer and save it into a text file? I was using this script I found

@Gloria351

Posted in: #Cs6 #PhotoshopScripting #Script

I'm using photoshop to support my job so I want to know how to get all text in layer and save it into a text file?
I was using this script I found in github to get coordinates and layer:

// Enables double-click launching from the Mac Finder or Windows Explorer #target photoshop

// Bring application forward
app.bringToFront();

// Set active Document variable and decode name for output
var docRef = app.activeDocument;
var docName = decodeURI(activeDocument.name);

// Define pixels as unit of measurement
var defaultRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;

// Define variable for the number of layers in the active document
var layerNum = app.activeDocument.artLayers.length;

// Define variable for the active layer in the active document
var layerRef = app.activeDocument.activeLayer;

// Define varibles for x and y of layers
var x = layerRef.bounds[0].value;
var y = layerRef.bounds[1].value;
var coords = "";

// Loop to iterate through all layers
function recurseLayers(currLayers) {
for ( var i = 0; i < currLayers.layers.length; i++ ) {
layerRef = currLayers.layers[i];
x = layerRef.bounds[0].value;
y = layerRef.bounds[1].value;
coords += layerRef.name + "," + x + "," + y + "n";

//test if it's a layer set
if ( isLayerSet(currLayers.layers[i]) ) {
recurseLayers(currLayers.layers[i]);
}
}
}

//a test for a layer set
function isLayerSet(layer) {
try {
if ( layer.layers.length > 0 ) {
return true;
}
}

catch(err) {
return false;
}
}

// Ask the user for the folder to export to
var FPath = Folder.selectDialog("Save exported coordinates to");

// Detect line feed type
if ( $.os.search(/windows/i) !== -1 ) {
fileLineFeed = "Windows";
}
else {
fileLineFeed = "Macintosh";
}

// Export to txt file
function writeFile(info) {
try {
var f = new File(FPath + "/" + docName + ".txt");
f.remove();
f.open('a');
f.lineFeed = fileLineFeed;
f.write(info);
f.close();
}
catch(e){}
}

// Run the functions
recurseLayers(docRef);
preferences.rulerUnits = defaultRulerUnits; // Set preferences back to user 's defaults
writeFile(coords);

// Show results
if ( FPath == null ) {
alert("Export aborted", "Canceled");
}
else {
alert("Exported " + layerNum + " layer's coordinates to " + FPath + "/" + docName + ".txt " + "using " + fileLineFeed + " line feeds.", "Success!");
}


but with text layer I can't get full text of this layer. Can someone give me some solution?

10% popularity Vote Up Vote Down


Login to follow query

More posts by @Gloria351

0 Comments

Sorted by latest first Latest Oldest Best

Back to top | Use Dark Theme