Skip to main content
Known Participant
June 7, 2017
質問

Script that adds a layer of text with the name of the selected layer to the document

  • June 7, 2017
  • 返信数 3.
  • 3876 ビュー

Hi friends! I'm looking for a script that adds to the document a layer of text written with the same characters as the selected layer.

Example:

1-Document with a layer named "Picture_3: Print" selected.

2-run Script:

3 - Add in the document a layer of text written "Picture_3: Print"

Thanks in advance:

このトピックへの返信は締め切られました。

返信数 3

Ps-Design作成者
Known Participant
June 9, 2017

Hello tokuredit thanks for the help! Great script, however it is critical that the added text layer contain the same characters as the last selected layer, without the need to use external .txt files.

tokuredit
Inspiring
June 8, 2017

Hi Ps-Design! this script is a bit like what you need, I believe there is a user exeto the JJMack that I can make a change in some lines of this script to meet your needs. Hope this helps, good luck.

The script will prompt for a text file containing the names.

  1. #target photoshop; 
  2. if(documents.length) main(); 
  3. function main(){ 
  4. var txtFile = File.openDialog("Please select TEXT.","TXT File:*.txt"); 
  5. var Names = []; 
  6. if(txtFile == null) return
  7. txtFile.open('r'); 
  8. var data = txtFile.read(); 
  9. txtFile.close(); 
  10. data = data.split('\n'); 
  11. for (var a in data){ 
  12.     var line = data.replace(/^\s+|\s+$/g); 
  13.     if(line.length >3) Names.push(line); 
  14.     } 
  15. for(var n in Names){ 
  16.     createTextLayer(Names); 
  17.     } 
  18. }; 
  19. function createTextLayer(layerName) {   
  20. var startRulerUnits = app.preferences.rulerUnits; 
  21. app.preferences.rulerUnits = Units.PIXELS; 
  22. var thisLayer = activeDocument.artLayers.add();  
  23. thisLayer.kind = LayerKind.TEXT;  
  24. thisLayer.name = layerName;  
  25. var textProperty = thisLayer.textItem;  
  26. textProperty.kind = TextType.POINTTEXT; 
  27. //Font Size 
  28. textProperty.size = 10;  
  29. textProperty.font = "Arial";  
  30. var newColor = new SolidColor();  
  31. //Font Colour 
  32. newColor.rgb.red = 0;  
  33. newColor.rgb.green = 0;  
  34. newColor.rgb.blue = 0;  
  35. textProperty.color = newColor;  
  36. textProperty.position = new Array( 100,100); 
  37. thisLayer.blendMode = BlendMode.NORMAL;  
  38. thisLayer.opacity = 100;  
  39. textProperty.contents = layerName;  
  40. app.preferences.rulerUnits=startRulerUnits; 
  41. };

JJMack
Community Expert
Community Expert
June 8, 2017

That script does add a text layer but it not a script the does whet  the op wants.  They also did not state they knew anything about the scripting knowledge.  If the do not know anything about Photoshop scripting the will not be able to understand the code you posted and will not be able to modify it.

JJMack
JJMack
Community Expert
Community Expert
June 8, 2017

It look like you actually want a lot more than you wrote to me.  I think you want the text to be some size, be some font, aligned to something, and fit. None of which you mentioned.

JJMack
c.pfaffenbichler
Community Expert
Community Expert
June 8, 2017

Good points.

What are the exact rules that should determine the position and orientation of the Type Layer?

Ps-Design作成者
Known Participant
June 8, 2017

As for position and orientation, you can add at the top, left, then I will edit the positions for each document.