Skip to main content
lperegrine
Participant
February 7, 2020
Answered

SVG source code access via InDesign scripting

  • February 7, 2020
  • 2 replies
  • 1072 views

Hello!

 

I'm trying to script an action that places an SVG file, but then does some manual manipulation to that SVG's code (changing some curves, new styles, updating fills, etc.).  Is such a thing possible or do I have to make any changes to the SVG code prior to placing it in InDesign?

 

Thank you!

Lukas

This topic has been closed for replies.
Correct answer Laubender

Since an SVG file is simply a text file with XML contents you should be able to change the code from that file.

With ExtendScript's File object you could use open, read, write and close methods:

https://www.indesignjs.de/extendscriptAPI/indesign14/#File.html

 

And yes, it would be good to make that changes before you place and link the file.

But of course you could also look into the methods of the Link object in InDesign. E.g. into method update():

https://www.indesignjs.de/extendscriptAPI/indesign14/#Link.html#d1e294199__d1e295194

 

Regards,
Uwe Laubender

( ACP )

2 replies

LaubenderCommunity ExpertCorrect answer
Community Expert
February 10, 2020

Since an SVG file is simply a text file with XML contents you should be able to change the code from that file.

With ExtendScript's File object you could use open, read, write and close methods:

https://www.indesignjs.de/extendscriptAPI/indesign14/#File.html

 

And yes, it would be good to make that changes before you place and link the file.

But of course you could also look into the methods of the Link object in InDesign. E.g. into method update():

https://www.indesignjs.de/extendscriptAPI/indesign14/#Link.html#d1e294199__d1e295194

 

Regards,
Uwe Laubender

( ACP )

David Popham
Participating Frequently
February 10, 2020

Uwe, I should've realized that the File object allowed access to an SVG in JavaScript as it's essentially a text file. Thanks for correcting me.

David Popham
Participating Frequently
February 7, 2020

As a placed SVG is only linked to the InDesign document, you wouldn't have access to the SVG code from InDesign's scripting interface.

Using either Visual Basic or AppleScript as your language, depending on your OS platform, you could develop a script that could process linked SVGs in Illustrator (or in a text editor, since SVGs are XML). You're much more limited interacting with multiple applications using JavaScript.