Skip to main content
Known Participant
November 22, 2023
Answered

Convert back to area text failed by jsx?

  • November 22, 2023
  • 1 reply
  • 533 views

I have to convert textframe type: area text => point text => area text
here is my jsx code:

function convert(name, contentNew) {
    var textFrameList = app.activeDocument.textFrames;
    for (var i = 0; i < textFrameList.length; i++) {
        var text = textFrameList[i]
        text.convertAreaObjectToPointObject();
        text.convertPointObjectToAreaObject();
    }
}

however, I found convertPointObjectToAreaObject failed. The final textframe is point text.

convert.ai 

 

 

This topic has been closed for replies.
Correct answer m1b

Hi @LoveYou阿逗逼6666, there are two problems

 

(a) the convertAreaObjectToPointObject and convertPointObjectToAreaObject methods destroy the text frame and create a new (converted) one, so your reference "text" will be invalid after the first convert, and

 

(b) the convertAreaObjectToPointObject and convertPointObjectToAreaObject methods should, according to the docs (and common sense!) return a reference to the new converted text frame—but they don't; they return null.

 

A workaround is something like the following:

 

 

function convert(name, contentNew) {
    var textFrameList = app.activeDocument.textFrames;
    for (var i = 0; i < textFrameList.length; i++) {
        var text = textFrameList[i];
        var group = text.parent.groupItems.add();
        group.move(text, ElementPlacement.PLACEBEFORE);
        text.move(group, ElementPlacement.PLACEATEND);
        text.convertAreaObjectToPointObject();
        text = group.pageItems[0];
        text.convertPointObjectToAreaObject();
        text = group.pageItems[0];
        text.move(group, ElementPlacement.PLACEBEFORE);
        group.remove();
    }
};

 

I put the text frame into a group, so that after it is converted, and the old item is gone, it is simple to get a reference to the new item.

- Mark

 

Edit 2023-11-22: removed the first example because it was bad.

1 reply

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
November 22, 2023

Hi @LoveYou阿逗逼6666, there are two problems

 

(a) the convertAreaObjectToPointObject and convertPointObjectToAreaObject methods destroy the text frame and create a new (converted) one, so your reference "text" will be invalid after the first convert, and

 

(b) the convertAreaObjectToPointObject and convertPointObjectToAreaObject methods should, according to the docs (and common sense!) return a reference to the new converted text frame—but they don't; they return null.

 

A workaround is something like the following:

 

 

function convert(name, contentNew) {
    var textFrameList = app.activeDocument.textFrames;
    for (var i = 0; i < textFrameList.length; i++) {
        var text = textFrameList[i];
        var group = text.parent.groupItems.add();
        group.move(text, ElementPlacement.PLACEBEFORE);
        text.move(group, ElementPlacement.PLACEATEND);
        text.convertAreaObjectToPointObject();
        text = group.pageItems[0];
        text.convertPointObjectToAreaObject();
        text = group.pageItems[0];
        text.move(group, ElementPlacement.PLACEBEFORE);
        group.remove();
    }
};

 

I put the text frame into a group, so that after it is converted, and the old item is gone, it is simple to get a reference to the new item.

- Mark

 

Edit 2023-11-22: removed the first example because it was bad.

Known Participant
November 22, 2023

thks, you are right.