• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to divide all textFrames in one-character-per-textFrame?

Explorer ,
Jan 24, 2011 Jan 24, 2011

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.

TOPICS
Scripting

Views

36.7K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 05, 2011 Mar 05, 2011

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

...

Votes

Translate

Translate
Adobe
Community Expert ,
Jan 30, 2011 Jan 30, 2011

Copy link to clipboard

Copied

here's how to do it with VBA, a copy in blue shown underneath.

oneCharPerFrame.PNG

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 30, 2011 Jan 30, 2011

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 30, 2011 Jan 30, 2011

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 05, 2011 Mar 05, 2011

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();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 06, 2011 Mar 06, 2011

Copy link to clipboard

Copied

Thanks, Carlos. Your script works perfectly! I am very happy.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 13, 2011 Apr 13, 2011

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.position[0]; // get x

          var ypos = tWord.position[1]; // get y

          var charCount = tWord.characters.length; // count characters

          for (i=charCount-1 ; i>=0 ; i--) // loop thru characters backwards

               {

                    var ichar = tWord.duplicate(); // duplicate textFrame

                    ichar.contents = tWord.characters.contents; // get last character

                    tWord.characters.remove(); // remove last character from original word

                    var width = tWord.width; // get the new width (without the last character)

                    ichar.position = [xpos+width,ypos]; // position the character = original position + new width

               }

          

          tWord.remove(); // remove textFrame (it is empty by now)

     }

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 13, 2011 Apr 13, 2011

Copy link to clipboard

Copied

Superb, Carlos! Thanks again.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 11, 2011 Jul 11, 2011

Copy link to clipboard

Copied

Nice, Carlos. Thanks.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 11, 2011 Jul 11, 2011

Copy link to clipboard

Copied

Hi Peter, you're welcome

thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 28, 2011 Sep 28, 2011

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 28, 2011 Sep 28, 2011

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)

          }

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 29, 2011 Sep 29, 2011

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.

https://files.me.com/oneillhome/36dtn8

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 13, 2011 Oct 13, 2011

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 14, 2011 Oct 14, 2011

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

          }

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 01, 2011 Nov 01, 2011

Copy link to clipboard

Copied

It really works fantastically, Carlos. Thank you so much for your attention on this very specific Illustrator inquiry!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 17, 2013 Jun 17, 2013

Copy link to clipboard

Copied

How do I install your code??

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 17, 2013 Jun 17, 2013

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 18, 2013 Jun 18, 2013

Copy link to clipboard

Copied

I tried that in a few different ways, but I keep getting this error when I run the script:

Screen shot 2013-06-18 at 12.55.02 PM.png

Any ideas how to fix that?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 18, 2013 Jun 18, 2013

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!!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 23, 2013 Jul 23, 2013

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 23, 2013 Jul 23, 2013

Copy link to clipboard

Copied

Hi, use the script in post # 14, that one works with whole words.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 23, 2013 Jul 23, 2013

Copy link to clipboard

Copied

Thank you so much Carlos. Awesome. Saving me tons of time.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 23, 2013 Jul 23, 2013

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 23, 2013 Jul 23, 2013

Copy link to clipboard

Copied

thanks Paul/kaswid I appreciate the feedback

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines