Code below. Any help would be appreciated!
// destination is the name of the document var layer = destination.layers; var nametext = layer.textFrames.add(); nametext.contents = "Name LastName" var charStyle = destination.characterStyles.add("NameStyle"); var charAttr = charStyle.characterAttributes; charAttr.size = 55; charAttr.capitalization = FontCapsOption.ALLCAPS; charAttr.textFont = app.textFonts.getByName("CormorantGaramond-Bold"); charStyle.applyTo(nametext.textRange); nametext.position = [306, 368.9956]; // Does not seem to do anything
At first - do not use layer as variable name. This causes confusion.
Where should the text frame be moved to?
/* var layer = destination.layers;*/ var aLay = app.activeDocument.layers; // don't use layer as variable name var nametext = aLay.textFrames.add(); nametext.contents = "Name LastName" //var charStyle = destination.characterStyles.add("NameStyle"); //var charAttr = charStyle.characterAttributes; //charAttr.size = 55; //charAttr.capitalization = FontCapsOption.ALLCAPS; //charAttr.textFont = app.textFonts.getByName("CormorantGaramond-Bold"); //charStyle.applyTo(nametext.textRange); alert (newText.position); nametext.position = [306, 368.9956]; redraw(); alert ("position changed");
Thanks--I'm trying to move it to another xy position on the same layer. I ran your snippet and the text ends up with the right x coordinate but the wrong y coordinate (436.0488 measured at the bottom left corner of the frame). Any idea why this is happening?
Are we really talking about the top left position of your text frame?
Please explain a bit more (maybe with screenshots before/after)
The coordinate system has been changed in the last versions.
Illustrator version: 26.0.3
Document size: 792 x 612 px
I'm writing a script to essentially duplicate a document, but replace the name. In the document I am duplicating, the bottom left corner (yes, bottom left) of the text frame containing the name is at [75.7461, 398.9502] (new coordinates but the issue is the same).
So my assumption would be that putting those into the .position() method would result in the text frame appearing in the same place. But when I run the code, the result is this:
The workaround I found is to just put 453.3027 in as the y coord. Then it ends up at 398.9502, where I wanted it. I just have no idea why.
Data Type: Point
Adobe Illustrator 26 Type Library
The position of the top left corner of the art item.
nametext.position = [306, 368.9956+newText.height];
This should give you two "point text" textFrames, the first at the document's top left and the second at the document's centre. Note that y is negative.
var doc = app.activeDocument; var nametext1 = app.activeDocument.textFrames.add(); nametext1.contents = "Name LastName 1"; nametext1.position = [0, 0]; var nametext2 = app.activeDocument.textFrames.add(); nametext2.contents = "Name LastName 2"; nametext2.position = [doc.width / 2, - doc.height / 2];
Is this what you get? If so, you can work it out from there.