Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
3

Bug with script for inserting multiple SVGs and editing them one by one

Community Beginner ,
Jun 13, 2023 Jun 13, 2023

Hello, I have a script that does the following steps on Illustrator:

 

  1. asks the user to select an array of .svg files
  2. for each .svg it does the following:
  3. it edits a specific portion of the .svg (it's a QR code so it removes some black squares from the bottom right to add some white padding for 2-3 characters)
  4. copies a template layer from my current .ai file
  5. places the .svg to the correct position on the duplicated layer
  6. moves the duplicated layer with the .svg at the "print" layer in a specific column/row
  7. moves on to the next .svg and repeat until finished

 

It takes about 5-8 seconds per file.

 

Everything works, the script finishes, no errors with it etc. The problem comes when you give it an array of 20+ or 50+ .svg files to loop through. After the 2nd or 3rd edit, illustrator freezes and will sometimes finish the script after 3-5 minutes and sometimes it will never finish. It doesn't give any errors, it just freezes. I have no way to automate this process completely because of this.

 

This issue has appeared to other script users and I can't find any solutions on the forum or StackOverflow. Can someone tell me if there is any alternative solutions to this? Am I importing the files incorrectly? Is Illustrator not the correct program for this kind of automation? I've figured for licensing reasons I can't spawn multiple Illustrator instances to do 1 thing, instead of 1 instance doing 50 things, correct? When I check task manager, it doesn't matter how many tabs/documents I have open on Illustrator, it's the same sub-processes. (Chrome for example has 1 sub-process for every open tab)

 

What I was thinking as a solution is the following, if a new tab/document was a new thread: Write a script that writes smaller versions of my script to do 1 thing (copy layer to new tab, open 1 .svg, do edits, copy to main tab, close new tab).

 

Since I don't think every new tab is a new process (and I don't want to spend the next 12 hours testing that), I've ran out of ideas so I am asking for solutions - even if it's out of Illustrator - like another Adobe product that I didn't know it could do some of the automation that I need.

 

I hope my post makes sense, otherwise please ask me anything 🙂

TOPICS
Bug , Experiment , Feature request , Performance , Scripting
617
Translate
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 15, 2023 Jun 15, 2023

Solved it by running a node-js script that runs illustrator with my updated script. Basically instead of having 1 script open ~50 .svg files, edit them and save the document, I have my node-js script that takes 50 file paths, loops over them and for each iteration it injects a script that loads that svg, edits it, places it in the correct template layer, saves it as .pdf. The node-js script checks every half a second if that file exists in a specific folder and if it does (timeout 10s), it moves

...
Translate
Adobe
Community Expert ,
Jun 13, 2023 Jun 13, 2023

Illustrator does struggle processing multiple files, it gets slower and slower after each run. But 20-50 should be ok unless your files are complex.

 

can you share the script and a test file? 

Translate
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 13, 2023 Jun 13, 2023

Hey thanks for the quick response!

I wanted to upload here a .zip that contained a few .svg files to test, my .ai workspace and of course the .js file. I have to use a google drive link for now. If it feels unsafe I can post the .js code here (it's about 256 lines though) but I won't be able to post 25 .svg files.

 

https://drive.google.com/drive/folders/1xEv5Gc0lqGxcfgdgmb_jEBAh6Z9X5HHo

Note that the .js is not the one I am actually writing. I am writing in typescript and converting to ES3 via webpack/babel etc so it might be a bit unreadable. I can provide a more readable (but also stripped down) version later if you need it. This way I can use the latest js features, types, modules etc and avoid getting a headache every time I want to implement something new to the script 😅

Translate
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 Expert ,
Jun 13, 2023 Jun 13, 2023

Thanks for the files, I takes about 2 min to process the 25 files. I ran it a couple of times without issues. The progress bar didn't update but that's kind of normal. I could see each QR as it was being generated though.

 

About debugging the script, it will be kind of difficult in that version.

 

 

Translate
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 14, 2023 Jun 14, 2023

It runs and finishes with ~20-30 .svg files, correct. You can try duplicating those .svg files and make them 50 or 60 or more. There is a chance for it to freeze completely and never finish. I usually leave it do its thing and come back 15-20 minutes later, I've seen it multiple times frozen and had to restart and continue with smaller batches.

 

I need to make it more robust so I know whether it finished running or not. I can't have the UI of Illustrator freezing if I want to automate this for production.

 

I assume it runs everything on its main thread, that's why the UI gets locked while the script is running. If that's the case, the devs need to fix this and have scripts run on a different thread. Maybe even give us an async promise for when the script finished or an exception after no computation after a certain time? Doing this probably means they need to move away from ES3 - which is a longshot as I believe they don't care much about scripting since "it works, why fix it?".

 

Another solution I can try: run a wrapper script that commands Windows to open Illustrator with ths script for 1 .svg, do the edits, finish running the script so UI doesn't hang, move on to next .svg etc. The only issue will be that I won't know when it has finished running each edit so I'll put a 10 sec delay between files to make sure.

Translate
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
Guide ,
Jun 14, 2023 Jun 14, 2023

You are correct in that an asynchronous setTimeout is not possible with regular scripting.  

Translate
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 15, 2023 Jun 15, 2023

Solved it by running a node-js script that runs illustrator with my updated script. Basically instead of having 1 script open ~50 .svg files, edit them and save the document, I have my node-js script that takes 50 file paths, loops over them and for each iteration it injects a script that loads that svg, edits it, places it in the correct template layer, saves it as .pdf. The node-js script checks every half a second if that file exists in a specific folder and if it does (timeout 10s), it moves on to the next .svg path in my array.

It's far from a clean solution, but, no more freezing!

Translate
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
Guide ,
Jun 15, 2023 Jun 15, 2023

Are you able to share your script?  I've not tried running Illustrator through node.js. 

Translate
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 16, 2023 Jun 16, 2023

Here you go:
https://stackblitz.com/edit/typescript-xqipvf

 

You run it with: ts-node ./index.ts


It won't work out of the box, but you can see 90% of what I'm currently using to make it work! This writes 2 .json files on C:/temp and then runs Illustrator with a compiled script that reads those 2 .json files, telling it what to do next. You have to have Illustrator open already for this to work properly, on a specific document, etc.

I can't share the .jsx script that runs on Illustrator itself.

Translate
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
Guide ,
Jun 19, 2023 Jun 19, 2023
LATEST

Thank you. 

Translate
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