Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

Save the selected frame data to a separate json file

Return to Member Forum

  • Author
    Posts
    • #115840
      Anonymous
      Inactive

      I guess this should be a simple matter for someone who knows about indesign scripting.
      I need to create a right-click submenu, which could on right-clicking the frame save frame data to a separate .json file named after the document name.
      The frame data I mean includes:
      – the linked file name
      – the frame’s position, scale and rotation
      – the frame’s content position, scale and rotation.
      Any tips?

    • #115946
      Brian Pifer
      Participant

      This is not quite a trivial matter. You’ll be dealing with the application’s menu objects, script menu objects as well as event listeners, along with the code to provide the export you seek. The following article may be helpful to start wrapping your brain around it, but it would be a somewhat complex script.

      https://www.indiscripts.com/post/2010/02/how-to-create-your-own-indesign-menus

    • #115954
      Anonymous
      Inactive

      Thank you.
      In the meantime I have found another way to go.
      https://creativepro.com/customizing-links-panel.php
      If that worked I could copy the data from the links panel and paste it in a text editor.
      But unfortunately the panel customization options are limited and do not include the frame and frame content transform data in the document coordinate system.

    • #115968
      Brian Pifer
      Participant

      There might be other ways to approach without getting so complicated, ie, does it have to be a menu command, or could you just run a script on a given document if there were some unique characteristics about the frames you wanted to export the data on. For instance, some pseudocode would be:

      For the frames in a doc,
      If the frame has a linked file name,
      Append that frame’s data to the json doc

      Would something like that work, or do you only want to export some specific linked files. Are there any commonalities between them that could be identified?

    • #115980
      Anonymous
      Inactive

      I would just like to compose documents and then publish them on the website.
      But I would like to keep one of the linked files variable, so user could upload its update.
      Imagine this variable file is a kind of map or plan background.

      So I could end up with 2 files on the server for a document; say a png file without this updatable component and some json or txt file
      with the transform data. Then I would like to – after the upload of updated component – recompose the document into a jpg or png format using imagick/imagemagick php server script.

      So I am basically looking for a way to collect the frame transform and frame content transform data, some way other than manually copying field by field or rewriting from indesign transform panels.

    • #115987
      Brian Pifer
      Participant

      Something like this might work for images in a given active document. Note, I’m a bit rusty and don’t have access to ID currently to check. For more info on the properties you can write to the file, check: https://jongware.mit.edu/idcs6js/pc_Graphic.html

      /////////////////////////

      var graphicsArr = app.activeDocument.allGraphics;
      var path = ‘~/Documents/’;
      var filename = app.activeDocument.name.split()[0] + ‘.json’;
      var file = new File(path + filename);

      file.encoding = ‘UTF-8’;
      file.open(‘w’);

      for (var i = 0; i < graphicsArr.length; i++) {
      var g = graphics.Arr[i];
      if (g.itemLink.isValid) {
      file.write(g.itemLink.name + “\r”);
      }

      //the graphic’s info
      file.write(g.horizontalScale.toString() + “\r”);
      file.write(g.verticalScale.toString() + “\r”);
      file.write(g.geometricBounds.toString() + “\r”); //this comes in as an array of four numbers
      file.write(g.rotationAngle.toString() + “\r”); //second return mark to separate different graphics

      //the parent’s info (rectangle object, most likely)
      file.write(g.parent.horizontalScale.toString() + “\r”);
      file.write(g.parent.verticalScale.toString() + “\r”);
      file.write(g.parent.geometricBounds.toString() + “\r”); //this comes in as an array of four numbers
      file.write(g.parent.rotationAngle.toString() + “\r”); //second return mark to separate different graphics

      }

      file.close();

    • #115950
      Anonymous
      Inactive

      Thank you.
      The article looks very promising.

      In the meantime I have also found another way to go, which is:
      https://creativepro.com/customizing-links-panel.php
      So if that worked I could copy the links panel data and then paste it in a text editor.
      But unfortunately the customization options are limited and long as they can include image pixel size, but not the size and transforms in the document units and the document coordinate system.

    • #116001
      Anonymous
      Inactive

      Something strange has happened here. Because I have posted the above post on the 8th and it did not show up then, so I have posted something else. I have no idea why it has shown up now.

      Thank you very much. The links look very relevant and I think they should guide me to the goal.

    • #116283
      Anonymous
      Inactive

      Hi, Brian,
      You are great.
      I got your scripts working after some tiny cosmetic changes.
      This was really easy and just what I was looking for.

      Thank you.

    • #116347
      Brian Pifer
      Participant

      Great! Glad I was able to help.

Viewing 9 reply threads
  • You must be logged in to reply to this topic.
Forum Ads