Skip to main content
Øyvind235243823c6v
Known Participant
June 7, 2023
Question

UXP: list json for document contents / structure

  • June 7, 2023
  • 2 replies
  • 915 views

I've made a script in CEP/jsx that lists the document structure of a given node in the document. E.g. I can ask for "app.activeDocument.graphicLines" and get back a JSON for all lines in the document (se screenshot "CEP_getJson_graphicLines.png"), or if I want the whole document I ask for "app.activeDocument.pageItems" (see screenshot "CEP_getJson_pageItems.png")

 

I want to do the same in UXP, i.e. get back every item / node in the document structure in JSON, but no luck so far

 

Has anyone done this?

 

 

This topic has been closed for replies.

2 replies

Community Expert
July 10, 2023

Hi @Øyvind235243823c6v,

Where exactly do you fail in UXP script? Can you share some examples, what does the method getObjectFromInDesign require as an input and what do you get instead when you run the DOM API call in UXP?

-Manan

-Manan
Øyvind235243823c6v
Known Participant
July 18, 2023

The screenshot is from a CEP plugin I made. With the new (beta) release of UXP scripting for InDesign we're scrapping CEP and moving to UXP

 

The problem now is to get a JSON object I can serialize and push to the server, i.e. the previous comment I made further up in this thread

Adobe Employee
July 10, 2023

Could you tell me which InDesign DOM API is exactly not working as expected in UXP scripting?

Øyvind235243823c6v
Known Participant
July 18, 2023

I was hoping to be able to do something like this

 

<script> 
    const id = require("indesign");
    const app = id.app;  
    console.log(app.activeDocument);
    console.log(JSON.stringify(app.activeDocument));
</script>​

 

But I can't stringify the object, I only get this in the console

 

Document {}
{}

 

I.e. stringify doesn't work. It seems like everything in the object is functions (+ it is recursive), so I had to make a workaround that loops through the whole object up to a certain level and generate a new object.

Is there any way of getting the document as a "normal JSON object"?

Adobe Employee
July 18, 2023

These InDesign DOM APIs in UXP mimic the exact behaviour as in ExtendScript/CEP. I see the same behaviour in ExtendScript and UXP on executing alert(app.activeDocument).

So, I wonder how you were able to generate the JSON string from app.activeDocument in CEP.