Skip to main content
Participant
October 24, 2023
Answered

Trying to convert text to outline via duplicated text layer

  • October 24, 2023
  • 1 reply
  • 265 views

New to illustrator scripting, and right now i have a script that will take a data, map values into text inputs, then export pdfs.  

 

What i'm trying now is to take each of the text inputs and convert them to outlines. My thought here is I could take and duplicate the textFrame, hide the initial one, create the outline to the new one, export the pdf, then remove out those items, and finally toggle back on the original.

 

```

function exportDataSets(allModifiedTextFrames) {
  try {
    for (var i = 0; i < doc.dataSets.length; i++) {
      alert('exportDataSets' + i)
      doc.dataSets[i].display();
      redraw();

      var duplicateTextFrames = [];
      allModifiedTextFrames[i].forEach(function (textFrame) {
        textFrame.hidden = true;
        var duplicateTextFrame = textFrame.duplicate();
        duplicateTextFrame.createOutline();
        duplicateTextFrames.push(duplicateTextFrame);
      });

      var pdfSaveOptions = new PDFSaveOptions();
      var destFile = getPDFFileNameFromDoc(doc.dataSets[i].name);
      doc.saveAs(new File(destFile), pdfSaveOptions);

      duplicateTextFrames.forEach(function (textFrame) {
        textFrame.remove();
      });

      // Restore original text frame visibility
      allModifiedTextFrames[i].forEach(function(textFrame) {
        textFrame.hidden = false;
      });
      alert('Unhide frames');
    }
  } catch (e) {
    alert('error exportDataSets')
    alert(e);
  }
}

 

What I keep hitting is  Object invalid when doing the .remove();


What am I missing here?

This topic has been closed for replies.
Correct answer PeteKreinto

Bah finally figured it out.

 

I needed to return the createOutline() group into my array,  as it appears the duplicated item does not persist once createOutline is used.

 

Once I returned the createOutline() and got the Group returned, all was good.

1 reply

PeteKreintoAuthorCorrect answer
Participant
October 24, 2023

Bah finally figured it out.

 

I needed to return the createOutline() group into my array,  as it appears the duplicated item does not persist once createOutline is used.

 

Once I returned the createOutline() and got the Group returned, all was good.

Sergey Osokin
Inspiring
October 24, 2023

Because createOutline() is destructive, it creates a new object that is written to a variable. The same is true if you have an object with an effect and you do Expand. For example, if you have an object selected, after the destructive action you can retrieve it by accessing app.selection[0]. These are the nuances of working with scripts in Illustrator.