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

Script to take selected frame (artwork @ 10%), open new document with 100% scale

Return to Member Forum

  • Author
    Posts
    • #115701

      I want to know if it’s possible to create a script for InDesign that will take the selected frame within an existing artwork proof (with artwork placed inside the frame at 10% scale), copy it, open a new InDesign document at the 100% print size and paste the artwork into the new document & scale by 1000%. (So it’s the correct size) if possible… Then save the document using the High quality print file PDF profile.

      Would any of this be possible, or is it a pipe dream? ?

    • #115702
      Jeremy Howard
      Participant

      This could absolutely be done! What scripting language are you most familiar with?

      Also, what OS are you running, OS X or Windows?

    • #115747

      I’m pretty much a newbie when it comes to scripting. I’ve looked through other InDesign scripts to get my head around certain commands etc. But I’d tend to do a lot of googling when trying to work out how to customise something for my needs.

      I’m working on InDesign CC v14.0.1 x64 on Windows 10 Pro

    • #115754
      Jeremy Howard
      Participant

      Hey there,

      Try this script out, I think that it accomplishes what you are trying to accomplish. It scales an image dynamically to ensure that it gets scaled up to 100% in the new document (rather than scaling based on the static 1000%).

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

      //set selection as variable
      var thisItem = app.selection[0];

      //create new document
      var myNewDocument = app.documents.add();

      //duplicate selected item to new document
      var myDuplicatedItem = thisItem.duplicate(myNewDocument.pages.item(-1));

      //get image within the frame
      var myLinkedItem = myDuplicatedItem.pageItems[0];

      //find the horizontal and vertical scale integers
      var myHscale = 100 / myLinkedItem.horizontalScale;
      var myVscale = 100 / myLinkedItem.verticalScale;

      //Scale the image around its center point
      var myScaleMatrix = app.transformationMatrices.add();
      myScaleMatrix = myScaleMatrix.scaleMatrix(myHscale, myVscale);
      myLinkedItem.transform(CoordinateSpaces.PASTEBOARD_COORDINATES, AnchorPoint.centerAnchor, myScaleMatrix);

      //fit frame to content
      myDuplicatedItem.fit(FitOptions.frameToContent);

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

    • #115756
      Jeremy Howard
      Participant

      Here is a better version that copies the selected image to a new document, dynamically sizes it to 100%, centers it on the page and exports the page to a PDF that is named using the original image name.

      // Begin Script ////////////////////////////////////////////////////////////////////////////////////

      //set selection as variable
      var thisItem = app.selection[0];

      //create new document
      var myNewDocument = app.documents.add();

      //duplicate selected item to new document
      var myDuplicatedItem = thisItem.duplicate(myNewDocument.pages.item(-1));

      //get image within the frame
      var myLinkedItem = myDuplicatedItem.pageItems[0];
      //get name of the linked image
      var myLinkName = myLinkedItem.itemLink.name;

      //strip extension from linked image name
      var myLinkName = myLinkName.split(“.”)[0];

      //find the horizontal and vertical scale integers
      var myHscale = 100 / myLinkedItem.horizontalScale;
      var myVscale = 100 / myLinkedItem.verticalScale;

      //Scale the image around its center point
      var myScaleMatrix = app.transformationMatrices.add();
      myScaleMatrix = myScaleMatrix.scaleMatrix(myHscale, myVscale);
      myLinkedItem.transform(CoordinateSpaces.PASTEBOARD_COORDINATES, AnchorPoint.centerAnchor, myScaleMatrix);

      //fit frame to content
      myDuplicatedItem.fit(FitOptions.frameToContent);

      //get width of the full-sized item
      var dupedItemWidth = myDuplicatedItem.geometricBounds[3] – myDuplicatedItem.geometricBounds[1];
      //get height of the full-sized item
      var dupedItemHeight = myDuplicatedItem.geometricBounds[2] – myDuplicatedItem.geometricBounds[0];

      //get the x coords we need to center the item on the page
      var xCoordsCalc = (myNewDocument.documentPreferences.pageWidth – dupedItemWidth) / 2;
      //get the y coords we need to center the item on the page
      var yCoordsCalc = (myNewDocument.documentPreferences.pageHeight – dupedItemHeight) / 2;

      //set frame bounds in order to center the frame on the page
      myDuplicatedItem.geometricBounds = [yCoordsCalc, xCoordsCalc, (yCoordsCalc + dupedItemHeight), (xCoordsCalc + dupedItemWidth)];

      //move the image to fit into the centered frame
      myDuplicatedItem.fit(FitOptions.contentToFrame);

      //Set Name of exported pdf to match the name of the linked image
      var myFile = File(“/Users/admin/Desktop/” + myLinkName + “.pdf”);

      //export the pdf
      myNewDocument.exportFile(ExportFormat.PDF_TYPE, myFile, false, “High Quality Print”);

      // End Script ////////////////////////////////////////////////////////////////////////////////////

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