Batch scripting solution for illustrator?

Community Beginner ,
Jun 23, 2022 Jun 23, 2022

Copy link to clipboard

Copied

Hey there, I'm getting super frustrated as I'm desperetly looking for a solution to improve our workflow. We have a publication where a whole magazine must be layouted in a day (an investment newsletter) and it has many graphs. We receive the graphs in SVG format from DataStream (google services) and I need to make several changes in them. 

1. changing the font, size and color of text

2. changing the stroke sizes, but there are 2 different strokes, one dashed and one normal

3. changing the color as there are RGB when we receive them and we print in Duo tone (cyan + black)

 

The strokes we receive are always the same attributes (ex stroke 1 is always 1pt large and color is always 51/51/51 etc...) So i figured I could just "Ask illustrator" to search for any stroke that has 51/51/51 for color and change it for a cmyk 0/0/0/100 and while I'm at it, change it from 1pt to 3,5pt. 

 

It shouldn't be complicated, really, its the kind of search and replace query I know how to handle on indesign for example but I can't do at all in illustrator which is driving me nuts. I've tried actions, where I create an object with the same characteristics as what i'm gonna be looking for then use "select same" to find similar and items and apply the changes but it only allow me to select "same appearance" but it doesn't allow me to discriminate between the stroke with dash and the one without dash because they are the same color. I don't know illustrator as well as photoshop or indesing but it feels like illustrator actions are a lot more limited than photoshop ones for example.

 

Can anyone point me in the right direction? I feel like if illustrator had a find and replace OBJECTS like indesign has it would be done in no time: search x, y and z attribute and replace it by a, b and c. What am I missing here? I've been banging my head on a wall all week. Do i need to learn java script for this? 

 

I've added a before and after file to show what I'm trying to do. 

 

Thanks in advance. 

TOPICS
Draw and design , How to , Scripting , Third party plugins , Tools

Views

191

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , Jun 24, 2022 Jun 24, 2022
UPDATE: I've figured it out! Took me the whole day. The main issue was when I asked illustrator to select a color i had first to add an action converting the whole document from CMYK to RGB and vice versa. So if I wanted to select an RGB color, document had to first be put in RGB otherwise, like shown in screenshot here, everytime i tried recording "set color to 51/51/51" it would set random values. And I also had to give up using dashes in the stroke, for some reason it kept making the action f...

Likes

Translate

Translate
Adobe Community Professional ,
Jun 23, 2022 Jun 23, 2022

Copy link to clipboard

Copied

Select Same Appearance works fine here. It selects either the dashed strokes or the solid axis lines

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 23, 2022 Jun 23, 2022

Copy link to clipboard

Copied

Thank you for your response.

 

It does if I want to manually in each file select an existing path and do select same appearance, then it selects the others. But I have no way that I know of to automate this. I would still have to open each file, select the doted line>select>same appearance and apply all the changes i want (stroke size, stroke color etc...) then do the same with the other strokes (not dotted) etc... then save the file and repeat the process for each graphic. Its a mainly manual job and we have so many of these graphs its more or less 1h of doing that over and over again. I do not know how to automate this. Actions doesn't allow to lets select the stroke based on its attribute. What would you do if you had 100 of these to take from Before to After ? Thanks.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 23, 2022 Jun 23, 2022

Copy link to clipboard

Copied

As far as I understand your request, it can certainly be done with an action that you can then use in Batch mode.

 

If you can share at least 10 sample files , I or someone else may have a look at them.

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 24, 2022 Jun 24, 2022

Copy link to clipboard

Copied

Thanks Kurt for your help. If you can help me get what I do wrong that would be amazing. I'm attaching 9 before files, those are the files I receive. And 1 after file which is the desired styling. What is frustrating me in actions is that i can't set as an action "select all objects with a continuous stroke of that color (51/51/51)" and then apply changes x, y and z to those selected strokes. So what I tried was creating a stroke outside of the artboard with the same attributes as the one i'm trying to automatically select and then use select>same appearance. And then do the same thing again and again for every different object. The steps seem straight forward, like basic lego, but when I run them again it doesn't work and I can't figure out why. Maybe there are command that exist that would make it easier? but i can't find any good infos on actions in illustrator online. Thanks again for your time.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 24, 2022 Jun 24, 2022

Copy link to clipboard

Copied

My mistake sorry. Here is the proper AFTER document because i spotted an error in color in the one I sent. Its supposed to be only using cyan and black as we print in duotone.

 

Another idea i had was to set as an action importing objects styles or stroke styles and apply them but I can't seem to be able to record that either. Most problems i encounter is about creating swatches because it doesn't seem to record properly the creationg of new swatch.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 24, 2022 Jun 24, 2022

Copy link to clipboard

Copied

UPDATE: I've figured it out! Took me the whole day. The main issue was when I asked illustrator to select a color i had first to add an action converting the whole document from CMYK to RGB and vice versa. So if I wanted to select an RGB color, document had to first be put in RGB otherwise, like shown in screenshot here, everytime i tried recording "set color to 51/51/51" it would set random values. And I also had to give up using dashes in the stroke, for some reason it kept making the action fail and gave an error message. 

So if anyone is interested, the actions I made are the following :

1. create square block outside of the artboard

2. set the fill and stroke to none using the APPEARANCE window and NOT the SWATCH window

 3. Only THEN, can i set a new stroke or/and fill color. Always set to none first.

4. switch to RGB color mode if stroke color is RGB. 

5. Select same > appearance or stroke color or stroke and fill

6. Switch document to CMYK mode

7. input new color in CMYK

8. input desired stroke sizes etc....

9. repeat over and over for each type of element/stroke that you have

 

Also, everytime you input a value like 22/155/14 in rgb, its gonna create 3 actions in rgb and 4 in cmyk. I would stop the recording and delete the extra 2 or 3 and only keep the last one with proper values.

 

PRO TIP : if you hit control Z with the action panel open, there is a chance it deletes your recorded action. 

 

In conclusion : The main problem with actions is the color profile. But even after figuring out the problem (at around 10am this morning) it still took me around 5h to record this action by doing trial and error and pretty much testing it every 2 steps on a new clean file. So i would say actions can be usefull but the tool is really limited and presents serious problems. 

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 24, 2022 Jun 24, 2022

Copy link to clipboard

Copied

Congratulations. That means you were able to create a practical action to automate your initial task, right?

 

Just a side note: Using the [None] swatch will currently break the action if it is run in a non-English international version of Illustrator. That's because its name gets written "hard-wired" into the action code which means that it is an unknown swatch in non-English Illustrator versions. However, there are workarounds to prevent it.

 

Would you mind to share your action? Just out of curiosity.

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 27, 2022 Jun 27, 2022

Copy link to clipboard

Copied

LATEST

I habe tried sharing it in the answer but the forum told me its not a supported format when I tried uploading it. I've also tried just now to zip it but same result. For the None swatch, thank you for the warning, i'll keep that in mind when sharing the action with co-workers, i'll need to make sure they are in the same language, but if i didn't do that, illustrator didn't seem to record properly a new swatch. Illustrator doesn't seem to have any other way to record a non value swatch. If I record with no value any other way, it marks it in the action but when i test it doesn't do switch to transparent fill or stroke. Like i said, the color setting/picking in illustrator actions is really troublesome. And I kept getting problems. I think the illustrator action tool really doesn't work as well as the photoshop one.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 23, 2022 Jun 23, 2022

Copy link to clipboard

Copied

if you want to do anything robust, you'll need javascript (or potentially applescript or VBScript... but both of these are very limiting too IMO). Actions are good for quick and dirty fixes.. they're horrible for any kind of robust automation, especially if any comparisons or conditionals are required. actions can't do either of these.

 

fortunately, what you're trying to do here is relatively straightforward. here's some pseudo-code:

//1. changing the font, size and color of text

//2. changing the stroke sizes, but there are 2 different strokes, one dashed and one normal

//3. changing the color as there are RGB when we receive them and we print in Duo tone (cyan + black)

var doc = app.activeDocument;
var swatches = doc.swatches;

var myBlackSwatch = swatches.add();
myBlackSwatch.color = new CMYKColor();
myBlackSwatch.color.cyan = 0;


//create a new character style with the attributes you want for the text
myCharacterStyle = doc.characterStyles.add();
myCharacterStyle.characterAttributes.size = 10;
myCharacterStyle.characterAttributes.color = swatches["Black"];
myCharacterStyle.characterAttributes.textFont = app.textFonts["Times-Roman"];

//loop all text frames in the document, and if they match a certain style
//apply myCharacterStyle to the frame
for each textFrame in doc
	var curColor textFrame.textRange.characterAttributes.color;
	if(curColor.red === 51 && curColor.green === 51 && curColor.blue === 51)
		myCharacterStyle.applyTo(textFrame)

//loop all the pathItems in the document and determine whether it's stroked
for each pathItem in doc
	if(pathItem.stroked && pathItem.strokeDashes < 1)
		pathItem.strokeColor = swatches["Black"].color;
		pathItem.strokeWidth = 3.5


//convert the doc to cmyk
app.executeMenuCommand('doc-color-cmyk');

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 23, 2022 Jun 23, 2022

Copy link to clipboard

Copied

That may be true, Dilliam, specifically if one does not know much about creating "robust" actions.

 

In this case, however, I think it may be properly automated with an action. Not just some quick and dirty sleights of hand.

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 23, 2022 Jun 23, 2022

Copy link to clipboard

Copied

it's difficult to know exactly what OP needs to do.. so, in light of that, i'm inclined to recommend a script instead because i KNOW a script can do it, and it's at least possible that an action cannot. I pretty much gave up on actions all together years ago.. occasionally i have to use one in a script.. but even then i'm creating and destroying it dynamically with the script.

 

I'm not trying to sh*t on actions all together.. They are useful for sure.. But i've simply become so frustrated with the limitations and quirks of actions... And with the help of github copilot, I can usually knock out a script to perform the same task as an action in about half the time it would take me to fiddle around with the actions panel.

 

To each their own. I'll take a script any day because then i can debug and step through the process if something isn't working right. actions are just kind of a black box and that doesn't appeal to me. I want to be able to see step by step what's happening and what the appropriate values are. 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 23, 2022 Jun 23, 2022

Copy link to clipboard

Copied

No worries, Dilliam. I certainly understand your point of view and you may be sure that I do know the limitations of actions. Therefore I usually call all of my actions as bumpy.

 

I certainly don't like imbalanced statements, nonetheless.

 

It's obvious that scripts may be way more powerful to automate things in Illustrator. Though they may also be bumpy more often than not.

 

In this case, however, I just took a look at the two sample files Youn provided above and read his instructions. As far as I can see, it's just doable with an action. And it wouldn't be a dirty one, but of course a bumpy one, as always.

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 24, 2022 Jun 24, 2022

Copy link to clipboard

Copied

Hi Kurt, thanks for your help.

I tried actions, and couldn't get anywhere. Basically what i did is trying to record creating a block outside of the artboard  with the same stroke than the ones in the document i receive and then "select same appearance" as a way to select all the dotes lines for example, then I record setting those dotted line to 3pt instead of 1 (+adjust the dashs etc....). When I stick to 1 action like this, most of the time it works. But when I make an action with several of this type of series of command, then things go horribly wrong or nothing happen at all. Its as if illustrator runs the actions too fast or skip some steps, I don't know. For example, in my Before document, there is a big dark grey box that I want to delete. So here is the action I thought off  to delete it :

1. create a square outside of the artboard

2. make this square 192/192/192 

3. select > same fill color (the box i create AND the one that was previously there are now both selected)

4. delete the selected objects. 

> that works. 

But then I try running just this action in another file where the grey is exactly the same and the result is that my action creates sometime a greenish block, sometime blue. It seems completly random. Thats the kind of bugs I've been having with actions and its frustrating.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 24, 2022 Jun 24, 2022

Copy link to clipboard

Copied

Thank you for your time and your response. Its what I was afraid of, that the problem lies in the limits of the actions in illustrator and not just that I didn't know how to use them properly. From the start it felt like it wasn't working properly. Having no knowledge at all in java script, I think our best chance will be to hire a programmer to design a custom script. I'll try and play with what you've given me, but one must know their limitations. Thanks a lot for your help. 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines