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

SVG source code access via InDesign scripting

New Here ,
Feb 07, 2020 Feb 07, 2020

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

TOPICS
Scripting
1.1K
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 Expert , Feb 10, 2020 Feb 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

...
Translate
Enthusiast ,
Feb 07, 2020 Feb 07, 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.

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 ,
Feb 10, 2020 Feb 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 )

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
Enthusiast ,
Feb 10, 2020 Feb 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.

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
New Here ,
Feb 10, 2020 Feb 10, 2020
LATEST

Ah yeh, of course! 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