• 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 Beginner ,
Aug 02, 2021 Aug 02, 2021

Copy link to clipboard

Copied

Hey carlos tried this script in illustrator2021 doesnt work.

can you make a new one for 2021 🙂

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 Beginner ,
Aug 01, 2024 Aug 01, 2024

Copy link to clipboard

Copied

Hi @CarlosCanto, just wondering whether you've published an update to this script which is compatible with the latest version of Illustrator? 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 ,
Aug 02, 2024 Aug 02, 2024

Copy link to clipboard

Copied

Hi @Mattymattster , scripts usually don't need to be updated to work on future releases. Is the script not working on your end?

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 Beginner ,
Aug 02, 2024 Aug 02, 2024

Copy link to clipboard

Copied

Hi @CarlosCanto, sadly not. I'll just run you through what I'm doing incase anything jumps out to you as wrong – I created plain text file in TextEdit (I'm on a Mac) containing the script in your Mar 05, 2011 comment. I then amended the file extension to .jsx . I then created some dummy text in illustrator (both 'text at a point' and 'text in a container'). I then select the text container using the selection tool and run the script, however I get the below warning:

Screenshot 2024-08-02 at 13.39.08.png

If I select the text within the container and then run the script I get this warning:

Screenshot 2024-08-02 at 13.40.39.png

Am I doing something wrong? As a test I followed the above steps to and was able to create the 'Hello World' script from this page https://ai-scripting.docsforadobe.dev/scriptingJavascript/yourFirstScript.html. Thanks for your help!

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 ,
Aug 02, 2024 Aug 02, 2024

Copy link to clipboard

Copied

Hi @Mattymattster , I posted a new version of that old script. Check my post on Nov 08, 2019, on page 3

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 Beginner ,
Aug 03, 2024 Aug 03, 2024

Copy link to clipboard

Copied

LATEST

Hi @CarlosCanto that's phenomenal! Thanks for your help and sorry I missed your 2019 post.

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 16, 2015 Jul 16, 2015

Copy link to clipboard

Copied

Hola. Trato de hacer una macro Excel que hace el contrario de oneCharacterPerTFrame(). Quiero fusionar unos textFrames en solo uno. Me puede ayudar por favor? Gracias por su respuesta.

Hello. I'm trying to make an Excel macro that does the opposite . I mean I want to merge textFrames into only one.

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 16, 2015 Jul 16, 2015

Copy link to clipboard

Copied

Hola guyp

- loop through your text frames,

- get their contents,

- concatenate them into one string

- add a new frame

- write the concatenated string

- remove individual frames (optional)

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 16, 2015 Jul 16, 2015

Copy link to clipboard

Copied

Thanks for your fast answer.

I’m not accustomed at all to work with Illustrator. I do it for a friend of mine who is a graphic designer. She has to paste pie charts from Excel to Illustrator.

When in Excel, the data label associated with a piece of the chart, for example, “Québec – 1 235 – 12%” ,  is one string but when pasted into Illustrator, it becomes 4 textframes: Quebec, 1, 235 and 12%.

I’ll do some research over Internet to learn more about the VBA object model and try to get something out of it.

Gracias otra vez por haber contestado tan rapido a mi pregunta.

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 16, 2015 Jul 16, 2015

Copy link to clipboard

Copied

You're welcome, most of what you need is done in my first post in this thread.

Look at this post, it covers the basics

https://forums.adobe.com/message/7652442#7652442

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 22, 2015 Jul 22, 2015

Copy link to clipboard

Copied

Good morning Sir,

The code I did to merge individual textFrames into one works fine when the textFrames are located on the same line. I mean with a separator being a point, a comma, a semicolon or a space.

Ex: Quebec; 3064; 25%

But when the separator is a new line, VBA raises a "Mismatch type" error because it doesn't see each line as a textFrame anymore but as a groupItem containing textFrames, each line being Item1 of the textFrames collection from wich I can see the contents.

Ex: Québec

      3064

      25%

This part of the code works fine.

However, the error is raised at this part highlighted in blue.

I hope you can give me a hint in order to fix it.

Thanks.

Here is the complete code I used

' ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Sub MergeTextFramesTest()
    Dim IApp As New Illustrator.Application
    Dim IDoc As Illustrator.Document
    Dim IFrame As Illustrator.TextFrame
    Dim IFrameNew As Illustrator.TextFrame

    Dim i As Integer

    Dim dblLeft As Double
    Dim dblTop As Double

    Dim StartIndex As Long
    Dim EndIndex As Long

    Dim strTextFrame As String

    Dim selectedObjects  'Array

    Set IDoc = IApp.ActiveDocument

    strTextFrame = ""

    For Each IFrame In IDoc.TextFrames
      Debug.Print IFrame.Contents
    Next

    If Not IsEmpty(IDoc.selection) Then

        selectedObjects = IDoc.selection
        StartIndex = UBound(selectedObjects)
        EndIndex = LBound(selectedObjects)
        Set IFrame = selectedObjects(StartIndex)

    ' Get the location of the first textFrame
    ' Later the new textFrame will be located at this position
        dblLeft = IFrame.Left
        dblTop = IFrame.Top

        For i = StartIndex To EndIndex Step -1  ' Step - 1 pour que la lecture se fasse de droite à gauche sinon c'est l'inverse

            strTextFrame = strTextFrame & selectedObjects(i).Contents
            'selectedObjects(i).Delete           
        Next

        ' Add a new textFrame with the string concaneted
        Set IFrameNew = IDoc.TextFrames.Add
        IFrameNew.Contents = strTextFrame
        ' Place the textframe at the position of the first individual textFrame
        IFrameNew.Top = dblTop
        IFrameNew.Left = dblLeft
        ' Assign original police and size
        IFrameNew.TextRange.CharacterAttributes.TextFont = IApp.TextFonts.Item(IFrame.TextRange.CharacterAttributes.TextFont.Name)
        IFrameNew.TextRange.CharacterAttributes.Size = IFrame.TextRange.CharacterAttributes.Size

        ' Delete individual textFrames
        For i = StartIndex To EndIndex Step -1

            selectedObjects(i).Delete

        Next

    Else

        MsgBox "You must select textFrames you want to merge"

    End If

    Set IFrame = Nothing
    Set IFrameNew = 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
New Here ,
Jul 23, 2015 Jul 23, 2015

Copy link to clipboard

Copied

Everything is Ok. I loop through the items selected, these objects were previously stored in an array, then I check the TypeName property.

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, 2015 Jul 23, 2015

Copy link to clipboard

Copied

Good to hear

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 ,
Apr 25, 2016 Apr 25, 2016

Copy link to clipboard

Copied

Hello CarlosCanto

If I make change in this line

     var words = tFrames.contents.split(/\r/g)

the script that splits selected texFrames into separate words works, but arranges split paragraphs horizontally.

Can you please modify the script to split correctly a block of selected text to paragraphs?

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 ,
Mar 26, 2018 Mar 26, 2018

Copy link to clipboard

Copied

Hi,

This is nice code but here are some problems you should modify it. This code is not able to break the Multi text line it is working only single line text. but if it apply on multi line text (means on paragraph) then the second line text break but make a cluster in the end of first line. because here the position of y should be change for multi line could you please modify it...

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 ,
Mar 26, 2018 Mar 26, 2018

Copy link to clipboard

Copied

use the Wundes script linked in post # 51 to break paragraphs into lines then use my script to break each line into 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 ,
Apr 02, 2018 Apr 02, 2018

Copy link to clipboard

Copied

I use that script but that is working like this (2nd, 3rd, 4th..... nth line break in words and add in first line continuously) but the requirement is break words should be in that position in which the paragraph were before breaking the text. If is it possible then help me please.. Thanks a lot.......

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 29, 2019 Oct 29, 2019

Copy link to clipboard

Copied

Hi neilb69570407 and ahablett, something happened to the script when it was migrated to the new platform. 

 

try this version

 

#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[k].position[0]; // get x
		var ypos = tFrames[k].position[1]; // get y
		var words = tFrames[k].contents.split(/\s/g); // get all words into an array
		//$.writeln(words);
		var space = tFrames[k].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[i]; // 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[k].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
Explorer ,
Nov 06, 2019 Nov 06, 2019

Copy link to clipboard

Copied

Thanks Carlos!

Could you amend the 'split by characters' script as well?  It gives the same error.

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 Beginner ,
Nov 06, 2019 Nov 06, 2019

Copy link to clipboard

Copied

Carlos, I tried the updated script, and got the error below. Thank you for the time you're putting into this, I can't believe you've been answering this question for eight years. That's some serious patience and tenacity.

Screen Shot 2019-11-06 at 12.08.52 PM.png
@neilb69570407, Were you able to get the script to run successfully? 

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 ,
Nov 08, 2019 Nov 08, 2019

Copy link to clipboard

Copied

Hi ahablett, 8 years and counting 🙂

the new forum migration really messed up with the arrays. I'll re-post the original script in a separate response so it doesn't get buried in this thread.

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 ,
Nov 08, 2019 Nov 08, 2019

Copy link to clipboard

Copied

here's the re-post of the Split Words into Characters script

 

#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[k].position[0]; // get x
		var ypos = tWord[k].position[1]; // get y
		var charCount = tWord[k].characters.length; // count characters
 
		for (i=charCount-1 ; i>=0 ; i--) // loop thru characters backwards
			{
				var ichar = tWord[k].duplicate(); // duplicate textFrame
				ichar.contents = tWord[k].characters[i].contents; // get last character
				tWord[k].characters[i].remove(); // remove last character from original word
				var width = tWord[k].width; // get the new width (without the last character)
				ichar.position = [xpos+width,ypos]; // position the character = original position + new width
			}
		
		tWord[k].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
Community Beginner ,
Nov 10, 2019 Nov 10, 2019

Copy link to clipboard

Copied

Hey Carlos, 

This is the message I get with this script running Adobe CC (2019) on a mac. Let me know if there's any other info you need or resources I can research to figure out how to get the scripts to work—the word separation one specifically would save days of work. I'm grateful for this thread to show it's even a possibility. 🙂 

 

Screen Shot 2019-11-10 at 4.11.33 PM.png

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
Participant ,
Mar 12, 2023 Mar 12, 2023

Copy link to clipboard

Copied

Hey, @CarlosCanto! Any chance this kind of logic would work for dividing multi-line text into separate lines, row by row? Couldn't find anything on the forums to help me in that regard...

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 12, 2023 Mar 12, 2023

Copy link to clipboard

Copied

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