Metadata into text layers

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

Andrew

Metadata into text layers

Post by Andrew »

So what you would like is to be able to take this long line of meta text and have it do a word-wrap after x characters - within the text field. I'm not immediately sure how this can be done but I think it can.

It requires a way of inserting PS-text line-feeds into the text string. Alternatively a quick look in the JS Ref Doc shows

TextItem.width, R/W, - the width of paragraph text (Unit Value).

When I get a chance I will have a look at this but in the meantime perhaps someone else has already got a solution?

Andrew
Andrew

Metadata into text layers

Post by Andrew »

This is one solution using paragraph text.

I suspect it can be done using actions, which would probably be better, but I haven't managed to do it. You would need, after the script has run, to convert the parrticular layer to paragraph text and then to specify the bounding box.

Anyway, the script method of doing the same involves replacing your function addTextLayer:

Code: Select all   function addTextLayer(layerName,text)
   {
      var thisLayer = activeDocument.artLayers.add();
      thisLayer.kind = LayerKind.TEXT;
      thisLayer.name = layerName;
      var textProperty = thisLayer.textItem;
      if (text.length > 100)
      {
         textProperty.kind = TextType.PARAGRAPHTEXT;
         textProperty.width = 200;
         textProperty.height = 120;
      }
      else textProperty.kind = TextType.POINTTEXT;
      textProperty.size = 10;
      textProperty.font = "Arial";
      var newColor = new SolidColor();
      newColor.rgb.red = 0;
      newColor.rgb.green = 0;
      newColor.rgb.blue = 0;
      textProperty.color = newColor;
      textProperty.position = new Array( 0,0);
      thisLayer.blendMode = BlendMode.NORMAL;
      thisLayer.opacity = 100;
      textProperty.contents = text;
   }

Alter the trigger text length in the 'if' and the desired width and height as you wish. The width and height are not percentage unit values despite that being the preference setting when the script is running.

One side effect of this is that subsequent text layers are placed at 0,0 but with the text above the 0,0 point, so it is invisible until repositioned. One way of dealing with that might be to make the problem long text layer the last one created.

Regards

Andrew
Andrew

Metadata into text layers

Post by Andrew »

There is new version:

bb/download.php?id=23

For unique fields it is no better than the original but it can also deal with different field types, eg multi-value fields (keywords) and fields with multi-level identifiers eg:

Code: Select all<dc:subject>
 <rdf:Bag>
  <rdf:li>test4</rdf:li>
  <rdf:li>test5</rdf:li>
  <rdf:li>test6</rdf:li>
  <rdf:li>new</rdf:li>
 </rdf:Bag>
</dc:subject>

and

<exif:Flash rdf:parseType='Resource'>
 <exif:Fired>False</exif:Fired>
 <exif:Return>0</exif:Return>
 <exif:Mode>2</exif:Mode>
 <exif:Function>False</exif:Function>
 <exif:RedEyeMode>False</exif:RedEyeMode>
</exif:Flash>


Andrew
Larry Ligon

Metadata into text layers

Post by Larry Ligon »

Try this: bb/viewtopic.php?t=34

Larry
mrankin

Metadata into text layers

Post by mrankin »

Thanks Andrew and Larry. I think that will fix the problem. I think putting it in the script will do the trick so that is doesn't replace the inserted text. Moving the special notes field down to the last line won't be a problem at all, I think it's the last one pulled anyway. The script stops after that part and the action picks it back up.

I've had another project dumped in my lap right now so I've been told to put this on hold for now. I think I'll end up taking this stuff home with me and working on it there while all this is still fresh on my mind. I've come too far to shelf this project for the next two months. I'll do it on my time just to get this done and implemented.

You guys are the best, I wish I could write javascript like this, there so many other things we could do here to improve workflow and turnaround time. I'm surprised every graphics company isn't moving in this direction right now. I can see the potential of this as being almost limitless.