Copy link to clipboard
Copied
I am trying to read a variable and then set a font of another item accordingly. I can set the font okay, but don't understand how to get the variable value for compariston. In this case I want the text value of sfont which is "arial".
Script
1 Correct answer
Yes, it's because your variable isn't actually bound to an object, it is just an empty variable. If you compare your variables palette to mine attached, you can see that you have nothing listed for "Object". That "object" is the page item the variable is linked to. So when you try to access 'sgreg.pageItems[0]' you are getting an error because there are no page items actually bound to that variable.
Explore related tutorials & articles
Copy link to clipboard
Copied
The below works for me. I created a single text variable with the text "arial" and this returns exactly that. The first item in the 'sgreg.pageItems' should be a TextFrame so you could dig deeper for more info if you needed to.
sgreg.pageItems[0].contents
Copy link to clipboard
Copied
Makes sense, but I'm getting this error. Trying a few things to get string value. toString, and some others. I'm on windows. CC illustrator.
Copy link to clipboard
Copied
Yes, it's because your variable isn't actually bound to an object, it is just an empty variable. If you compare your variables palette to mine attached, you can see that you have nothing listed for "Object". That "object" is the page item the variable is linked to. So when you try to access 'sgreg.pageItems[0]' you are getting an error because there are no page items actually bound to that variable.
Copy link to clipboard
Copied
That's it! Thanks. Now will try with the datasets.
Copy link to clipboard
Copied
Hi @gstewartjr
Does the following helps a little?
alert (app.activeDocument.textFrames[0].textRange.characterAttributes.textFont.name);
var aTF = app.activeDocument.textFrames.add();
aTF.contents = "test";
aTF.textRange.characterAttributes.textFont = app.textFonts.getByName("MyriadPro-Regular");

