Copy link to clipboard
Copied
Hi I'd like to know if it's possible to have a csv file to import as Data sets containing a string value with a CR/LF code (as it is a text value)
Example:
image,bodyText,image2
violet.jpg,"Origin country:
Spain and North of Italy", myImage2.jpg
I know I just can press enter to break the line of the text. Problem with this is that I'm parsing this file via FileObject.readln method and whenever it finds the Enter Press it takes it as the end of line1 of values instead of coing on.
So I'd like to escape the Cr+Lf with in just one line, like:
image,bodyText,image2
violet.jpg,"Origin country:\nSpain and North of Italy", myImage2.jpg <---this is not working aqs Photoshop renders the layer as:"Origin country\nSpain" instead of:
"Origin country:
Spain and North of Italy"
Any idea??
Copy link to clipboard
Copied
One way would be to use escape to write your data and unescape when you load the data.
alert(escape("Origin country:\nSpain and North of Italy"));
alert(unescape("Origin%20country%3A%0ASpain%20and%20North"));
EDIT:-
My bad, you are using datasets so this won't work.
Copy link to clipboard
Copied
I think that Paul is right, what you need to do is unescape the \n and you can't do that with datasets. What you could do is after the dataset has been applied replace the escaped code in the text layer's textItem contents.
Something like this.
// apply dataset
// select the text layer
myLayer.textItem.contents = myLayer.textItem.contents.replace(/\\n/g,'\n');
Copy link to clipboard
Copied
Hi Michael. Your answer was half useful to me:
I used replace(/whatever/,'\r\n); (nothe the \r as only \n won't work
Only problem is: this method removes completely any style applied to text (for example: "Spain and Northern Italy" becomes: "Spain and Northern Italy".
Is there anyway to avoid this?
Thanks in advance for your help
Copy link to clipboard
Copied
The answer is yes but not really.The text is stored in text ranges. If all the text is the same font, size, color, etc there is only one range. The the text changes there is a range for each style.
So what you have to do is get the descriptor for the textItem. Search each text range in that descirptor for what ever you want to replace. If found, edit that range and update the descriptor. When you have finished searching/replacing you write the descirptor back to the textItem.
It is not easy to do and I just change the document design to avoid multi-ranges.
But if you want to give it a try I can post some code to help you get started and Xbytor's xtools also has some text range scripts you might want to look at. But working with text ranges uses Action Manager API (scriptlistner ) and is not documented by Adobe.
Copy link to clipboard
Copied
I heard about that, and find it not complicated but "boring". So I think what I'll do is to use your replace method and then create an action in the Photsohop UI that sets every font with proper size, color, bold and so on, and afterwards load tha action from the script
Copy link to clipboard
Copied
I guess that I don't understand what you are trying to do. If you are going to set the text with an action, why bother with the dataset and replace? The action will override all of that and change the text to what ever was recorded.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now