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

23.2K

Likes

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

Adobe Community Professional , 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 ...

Likes

Translate

Translate
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.

Likes

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
Adobe Community Professional ,
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

Likes

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

Likes

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.

Likes

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

Copy link to clipboard

Copied

Good to hear

Likes

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?

Likes

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!

Likes

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
Adobe Community Professional ,
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

Likes

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

Likes

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
Adobe Community Professional ,
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

	}

 

Likes

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.

Likes

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? 

Likes

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
Adobe Community Professional ,
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.

Likes

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
Adobe Community Professional ,
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)

	}

Likes

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

Likes

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
Adobe Community Professional ,
Nov 10, 2019 Nov 10, 2019

Copy link to clipboard

Copied

Hi ahablett, did you use the latest script I posted yesterday? can you show a screen shot of you selected text including your layers expanded?

Likes

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

I would have sworn on a bible that I did, but going back and redoing the process to take screenshots for you, I must have followed directions right this time, and splitSelectedFramesIntoWords2.0.jsx works like a charm. Thank you for your script and patience, I am so stoked to use this tool!

Likes

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
Adobe Community Professional ,
Nov 10, 2019 Nov 10, 2019

Copy link to clipboard

Copied

you're welcome, I'm happy to hear that...you know, almost 9 years later, this script is still rocking.

Likes

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