Copy link to clipboard
Copied
Hello:
How to divide all textFrames in one-character-per-textFrame?
Example: the textFrame "Letters" will be divided in 7 textFrames: "L", "e", "t", "t", "e", "r", "s".
Help, please.
Hi Victor, here's the JS version, sorry for the delay
#target Illustrator
// script.description = splits selected texFrame into separate characters;
// script.required = select a point text textFrame before running;
// script.parent = CarlosCanto; // 3/5/11
// script.elegant = false;
var idoc = app.activeDocument;
var tWord = idoc.selection[0];
var xpos = tWord.position[0];
var ypos = tWord.position[1];
var charCount = tWord.characters.length;
for (i=charCount-1 ; i>=0 ; i--)
{
var ichar
...Copy link to clipboard
Copied
here's how to do it with VBA, a copy in blue shown underneath.
Sub oneCharacterPerTFrame()
Dim Iapp As New Illustrator.Application
Dim Idoc As Illustrator.Document
Dim tWord As Illustrator.TextFrame
Dim tCharacter As Illustrator.TextFrame
Dim a As Integer
Dim b As Integer
Set Idoc = Iapp.ActiveDocument
Set tWord = Idoc.TextFrames(1)
x = tWord.Position(0)
y = tWord.Position(1)
a = tWord.Characters.Count
For b = a To 1 Step -1
Set tCharacter = Idoc.TextFrames.Add
tCharacter.Contents = tWord.Characters(b).Contents
tWord.Characters(b).Delete
w = tWord.Width
tCharacter.Position = Array(x + w, y)
Next
tWord.Delete
Set tCharacter = Nothing
Set tWord = Nothing
Set Idoc = Nothing
Set Iapp = Nothing
End Sub
Copy link to clipboard
Copied
Thanks, Carlos, for your solution, but I have a Mac and Microsoft Visual Basic for Applications does not run on Mac.
Please, do you can translate your code to JavaScript (or AppleScript)?
Best regards.
Copy link to clipboard
Copied
you're welcome, I have a hard time doing JS, it doesn't seem to stick to my brain....but I'll try.
Copy link to clipboard
Copied
Hi Victor, here's the JS version, sorry for the delay
#target Illustrator
// script.description = splits selected texFrame into separate characters;
// script.required = select a point text textFrame before running;
// script.parent = CarlosCanto; // 3/5/11
// script.elegant = false;
var idoc = app.activeDocument;
var tWord = idoc.selection[0];
var xpos = tWord.position[0];
var ypos = tWord.position[1];
var charCount = tWord.characters.length;
for (i=charCount-1 ; i>=0 ; i--)
{
var ichar = tWord.duplicate();
ichar.contents = tWord.characters.contents;
tWord.characters.remove();
var width = tWord.width;
ichar.position = [xpos+width,ypos];
}
tWord.remove();
Copy link to clipboard
Copied
Thanks, Carlos. Your script works perfectly! I am very happy.
Copy link to clipboard
Copied
Hi Victor, here's your request, it works on multiple text Frames
#target Illustrator
// script.name = splitSelectedWordsIntoCharacters.jsx;
// script.description = splits selected texFrames into separate characters;
// script.required = select point text textFrames before running;
// script.parent = CarlosCanto; // 4/13/11
// script.elegant = false;
var idoc = app.activeDocument;
var sel = idoc.selection; // get selection
var selCount = sel.length; // count items
var tWord = []; // to hold the textFrames
for (j=selCount ; j>0 ; j--) // loop thru selection & get textFrames backwards
{
tWord[j-1] = sel[j-1];
}
for (k = 0 ; k<tWord.length ; k++) // loop thru textFrames
{
var xpos = tWord
var ypos = tWord
var charCount = tWord
for (i=charCount-1 ; i>=0 ; i--) // loop thru characters backwards
{
var ichar = tWord
ichar.contents = tWord
tWord
var width = tWord
ichar.position = [xpos+width,ypos]; // position the character = original position + new width
}
tWord
}
Copy link to clipboard
Copied
Superb, Carlos! Thanks again.
Copy link to clipboard
Copied
Nice, Carlos. Thanks.
Copy link to clipboard
Copied
Hi Peter, you're welcome
thanks
Copy link to clipboard
Copied
What an amazing script! Carlos, would you be able to modify this so that instead of breaking apart all characters, it breaks apart all words at any spaces, like "\s"?
Your script is so close to what I need! Apparently it was called the break apart feature in Corel Draw, if I have read about it correctly.
Thank you for the wonderful feature above and anything you can do for me.
Copy link to clipboard
Copied
Hi Paul, no problem
#target Illustrator
// script.name = splitSelectedFramesIntoWords.jsx;
// script.description = splits selected texFrames into separate words;
// script.required = select point text textFrames before running;
// script.parent = CarlosCanto; // 9/28/11
// script.elegant = false;
var idoc = app.activeDocument;
var sel = idoc.selection; // get selection
var selCount = sel.length; // count items
var tWord = []; // to hold the textFrames
for (j=selCount ; j>0 ; j--) // loop thru selection & get textFrames backwards
{
tWord[j-1] = sel[j-1];
}
for (k = 0 ; k<tWord.length ; k++) // loop thru textFrames
{
var xpos = tWord
.position[0]; // get x var ypos = tWord
.position[1]; // get y var wordCount = tWord
.words.length; // count words for (i=wordCount-1 ; i>=0 ; i--) // loop thru words backwards
{
var iword = tWord
.duplicate(); // duplicate textFrame iword.contents = tWord
.words.contents; // get last word tWord
.words.remove(); // remove last character from original word var width = tWord
.width; // get the new width (without the last character) iword.position = [xpos+width,ypos]; // position the character = original position + new width
}
tWord
.remove(); // remove textFrame (it is empty by now) }
Copy link to clipboard
Copied
Carlos, it is so close! My first attempt resulted with this problem, where spacing is lost between some objects and in one case a word lost both a period and a letter, the string "page. They" became "pag They"
Thank you so much! You are so fast, dude! See the archive linked below.
Copy link to clipboard
Copied
Carlos, is there any update to fix the problem I saw in the first word, in the punctuation and in the characters/spaces at the end of lines?
Copy link to clipboard
Copied
Hi Paul, try this one
#target Illustrator
// script.name = splitSelectedFramesIntoWords2.0.jsx;
// script.description = splits selected texFrames into separate words;
// script.required = select point text textFrames before running;
// script.parent = CarlosCanto; // 10/14/11
// script.elegant = false;
var idoc = app.activeDocument;
var sel = idoc.selection; // get selection
var selCount = sel.length; // count items
var tFrames = []; // to hold the textFrames
for (j=selCount ; j>0 ; j--) // loop thru selection & get textFrames backwards
{
tFrames[j-1] = sel[j-1];
}
for (k = 0 ; k<tFrames.length ; k++) // loop thru textFrames
{
var xpos = tFrames
.position[0]; // get x var ypos = tFrames
.position[1]; // get y var words = tFrames
.contents.split(/\s/g); // get all words into an array //$.writeln(words);
var space = tFrames
.duplicate(); // dup to get width of a space space.contents = " ";
var sw = space.width;
space.contents = words[0]; // replace space with first word
var w = space.width;
var wordCount = words.length; // count words
for (i=1; i<wordCount ; i++) // loop thru words
{
xpos2 = xpos+w+sw; // next words position = previous word pos+width+space
var iword = space.duplicate(); // duplicate previous word
iword.contents = words; // add next word
iword.position = [xpos2,ypos]; // position the character = original position + new width
w = iword.width; // get words width
xpos = iword.position[0]; // get words position
}
tFrames
.remove(); // remove textFrame }
Copy link to clipboard
Copied
It really works fantastically, Carlos. Thank you so much for your attention on this very specific Illustrator inquiry!
Copy link to clipboard
Copied
How do I install your code??
Copy link to clipboard
Copied
Copy the above. Open a text editor or the Adobe ESTK utility and paste. Save making sure that is in plain text. Run it in AI by File>Scripts>Other scripts and navigate to the saved script. You must have a file open in AI and some text selected.
Copy link to clipboard
Copied
I tried that in a few different ways, but I keep getting this error when I run the script:
Any ideas how to fix that?
Copy link to clipboard
Copied
Just kidding--I used DreamWeaver this time and found the error. It works!!!! I will be using this script almost every day! THANK YOUUUUU!!!
Copy link to clipboard
Copied
Hi Carlos. I used your script and it worked. But, I don't want each individual letter broken apart. Is there a script to break apart a text string by whole words? Thanks
Copy link to clipboard
Copied
Hi, use the script in post # 14, that one works with whole words.
Copy link to clipboard
Copied
Thank you so much Carlos. Awesome. Saving me tons of time.
Copy link to clipboard
Copied
Carlos saves me on a project way back. He is the king of the forums IMHO.
Stereo thank you to Carlos Canto.
Sent from my iPhone
Copy link to clipboard
Copied
thanks Paul/kaswid I appreciate the feedback