Copy link to clipboard
Copied
I have JavaScript code that is supposed to change the font size for all text boxes. I want to resize the font to size 13. The text boxes range from size 4.76 to size 10.49. Right now, the script only changes them to size 12 or 14 (or anything that isn't 13).
- var myDocument = app.activeDocument;
- var tfs = myDocument.textFrames;
- var n = tfs.length;
- for ( i = 0 ; i < n ; i++ ) {
- tfs.textRange.characterAttributes.textFont = app.textFonts.getByName("BebasNeue");
- tfs.textRange.characterAttributes.size = 13; //nothing happens during this stage unless I change 13 to 14
- }
Thanks in advance for any help.
Weird indeed! By the way, how do you import the XML files into your pie charts? Is there one chart per document, or multiple ones?
Well, can you try to set their font to be another font, and set that to 13 and then change back to Bebas?
Copy link to clipboard
Copied
I wonder what's going on, because this does work for me- except I do not have this font.
Copy link to clipboard
Copied
Wow, weird. You're right. It works with every font other than Bebas Neue...
Maybe this will help. Background: all the text boxes are attached to pie charts, which have been made into variables. I update the variables routinely by importing an XML file (which updates the data in the pie charts). Whenever I import the XML, though, the font size changes to 10.9. Even though the document's default font is set to Bebas Neue 13 pt.
So I then manually ungroup everything in the document, which turns the variables into text boxes that I can call with this script.
Copy link to clipboard
Copied
Weird indeed! By the way, how do you import the XML files into your pie charts? Is there one chart per document, or multiple ones?
Well, can you try to set their font to be another font, and set that to 13 and then change back to Bebas?
Copy link to clipboard
Copied
Silly-V wrote:
Weird indeed! By the way, how do you import the XML files into your pie charts? Is there one chart per document, or multiple ones?
Multiple ones...I have a base document with all the charts I need. I put sample data into there, capture all the variables, and save the variable library. Then I run a separate script that updates all the data. Then, in a copy of my base document, I load the variable library. It mostly works, except that all the text resizes itself (and resets itself back to the default font, Myriad Pro) when I reload it. It's very strange.
Silly-V wrote:
Well, can you try to set their font to be another font, and set that to 13 and then change back to Bebas?
Yeah, that works!
I actually suspect this problem might have stemmed from my default font for the document. I had set the default font to be Bebas Neue, size 13, in an attempt to stop the font resizing itself and re-setting to Myriad Pro after importing the XML. But for some reason that messed up this script and prevented it from changing the font when I told it to set everything to Bebas Neue, size 13. When I changed the default font back to Myriad Pro, I was able to run the script successfully.
¯\_(ツ)_/¯
Copy link to clipboard
Copied
Well, glad that works. Did you know you can use my VariableImporter script to import many graph states at one time? Maybe it could be useful to you potentially. It works off different text files, each of which is to contain a single graph state.
VariableImporter.jsx now supports Graph Variables! | Vasily Hall | LinkedIn
Copy link to clipboard
Copied
Your script was actually one of the first things I looked at. When I started, I didn't know anything about Illustrator, so I was hesitant to use outside sources at first. Then I thought it would be better to keep our process in-house because a) the pie charts have to match a very specific format (numbers need to be inside the pies, colors and slices need to be aligned a certain way, etc.)., and b) I've had so much trouble tracking down any kind of documentation or answers to my questions for Adobe's pie charts that I was afraid I'd have the same problem with the VariableImporter script, so I didn't want to spend time on it. Whereas our current script was developed by a programmer who works here, so I can just talk to them when I have questions.
But I'll take another look at it. Plus, I see your name crop up so much around these forums that I'm not as worried about not being able to find documentation because clearly you are very active
Does your script work on pie chart data as well? I have found the chart tool to be incredibly finicky and frustrating. The guides that I saw for your script seemed to focus primarily on images and text. It would be great if I could speed up the creation of these pie charts.
Edit: I ran your script using two pie charts and this dataset:
%graph |
pie1.csv |
pie2.csv |
where pie1.csv and pie2.csv are CSV files (that contain data like 7.82,24.5,35.5, etc.) and are stored in the same location as the dataset file (on my desktop at the moment).
I just get a window like this, which doesn't look like any of the guides I've found...
Copy link to clipboard
Copied
Well, the 'different text-file' thing is not going to be superior to having your own go-to resource, but it could be an additional method in your arsenal.
The new guides for this version of it are in video format pretty much- although the functionality is the same, with added extras, as the old readable guides. (Good idea if I made a Readme file for the git place!)
And I believe you would be right when you say the effects will be the same with the font changing, etc.
All the script does is import variables, so the chart styling, etc is still up to you.
Copy link to clipboard
Copied
The resources are here:
Illustrator Variable Data - The EASY way! - YouTube
Adobe Illustrator Variable Data | Lynda.com
I'm sure you have already looked at the legacy format documentation on Stephen Marsh's website.
Copy link to clipboard
Copied
Thanks for your replies! I'm sorry-- I've looked at those resources and none of them match what I'm seeing in front of me, on my screen at this very moment. I don't know if the resources are outdated or I'm just not doing something right. But I can't get beyond this weird menu. Am I supposed to format my CSV in a different way? Did I not save it in the right location? I don't get what I'm doing wrong and although I'm sure these resources are great, they don't really help when I can't get beyond the first step of the process. T
Copy link to clipboard
Copied
Your stuff looks correct, after you import the variables, if your graph is named "graph", you can use auto-binding to have it bind automatically. What isn't working?
Copy link to clipboard
Copied
Thanks for the reply. When I run it, I get a pop-up window saying Lost Items: The current import contains 2 missing Graphs. Proceed?
When I click yes, it tells me "Your variable data has been imported. It contains 2 variables and 2 records. 2 Missing Graph(s)"
I have 1 layer with 2 pie charts. The layer is called Graph, the two charts that I want to update are pie1 and pie2. My dataset (that I posted earlier) is on my desktop, along with the two CSVs for the pie charts. The CSVs are called pie1.csv and pie2.csv. pie1.csv looks like this:
78.3,13.3,3.9,2.1,0.4,1.1,0.2,0.6
Hope that makes sense.
Copy link to clipboard
Copied
Okay great, I'm replying to your PM regarding this. I am afraid the user-base for graphers in Illustrator, especially ones who use the XML files has got to be one of the most niche subcultures in the world, so it's great to be able to conference on this obscure feature!