Skip to main content
Inspiring
June 23, 2016
Question

Script running in toolkit but fails in Illustartor

  • June 23, 2016
  • 2 replies
  • 1253 views

I have a script that loops through items on the page, then depending if they are a textFrame or a pathItem calls a seperate function. All seems to work well whilst I'm in the ExtendScript Toolkit environment, but when I put the script into illustrator and run it directly I get the following error. Can anyone tell me what I'm doing wrong

It seems to be refering to the code    'if (item instanceof TextFrame) {'

for (var i = doc.pageItems.length -1; i > -1; i--) {

    var item=doc.pageItems;

    if (item instanceof TextFrame) {

            changeText(item)

        }

     if (item instanceof PathItem) {

            changePath(item)

        }

    }

function changeText(item) {

    item.textRange.characterAttributes.figureStyle=FigureStyleType.TABULAR

    item.textRange.characterAttributes.fillColor=spotBlack;

    item.textRange.characterAttributes.ligature.true

    }

function changePath(item) {

    if (Math.round(item.strokeColor.cyan) == crowbarBlack.cyan &&

        Math.round(item.strokeColor.magenta)== crowbarBlack.magenta &&

        Math.round(item.strokeColor.yellow) == crowbarBlack.yellow &&

        Math.round(item.strokeColor.black) == crowbarBlack.black) {

            item.strokeColor=spotBlack;

            }

    if (Math.round(item.fillColor.cyan) == crowbarBlack.cyan &&

        Math.round(item.fillColor.magenta)== crowbarBlack.magenta &&

        Math.round(item.fillColor.yellow) == crowbarBlack.yellow &&

        Math.round(item.fillColor.black) == crowbarBlack.black) {

            item.fillColor=spotBlack;

            }

    }

This topic has been closed for replies.

2 replies

pixxxelschubser
Community Expert
Community Expert
June 23, 2016

Hi Bob Haslett

you better use:

if (item.typename == "TextFrame") {

instead of:

if (item instanceof TextFrame) {

Have fun

Silly-V
Legend
June 23, 2016

but pixxxel schubser​ , but why?? I want to know the mystery.

Silly-V
Legend
June 23, 2016

Because of …

… it works.


I still want to know his constructor name!

But more often than not, I do settle for "it works". Exhibit 1: all of my code ever.

Silly-V
Legend
June 23, 2016

Weird, I was gonna post all kinds of answers, but then I examined it a little more closely and I'm not sure why this would be. TextFrame is something that should be part of Illustrator anyhow.

I guess try to alert this on a selection which is just a text frame?

alert(app.activeDocument.selection[0].constructor);

See what it says in ESTK and in AI