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

Script: Automatically apply the specified object style and shrink it

Enthusiast ,
Mar 11, 2017 Mar 11, 2017

Copy link to clipboard

Copied

This script is used to import the picture, the format contains the article contains: @ name.jpg (or tif / psd) @

I want to add some functionality:

The image is automatically applied to the specified object style.

Also, the picture automatically equals to 1/3 of the page size

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Below is the original script,Thanks to Kasyan

Place inline images

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

main();

function main() {

  var name, f, file, text,

  arr = [];

  if(app.documents.length != 0) {

  var doc = app.activeDocument;

  var folder = Folder.selectDialog("Choose a folder with images");

  if (folder != null) {

  app.findObjectPreferences = app.changeGrepPreferences  = NothingEnum.NOTHING;

  app.findGrepPreferences.findWhat = "@.+?@";

  f = doc.findGrep(true);

  for (i = 0; i < f.length; i++) {

  name = f.contents.replace(/@/g, "");

  file = new File(folder.fsName + "/" + name);

  if (file.exists) {

  f.remove();

  f.insertionPoints[0].place(file);

  }

  else {

  arr.push("File doesn't exist '" + name + "'");

  }

  }

  app.findObjectPreferences = app.changeGrepPreferences  = NothingEnum.NOTHING;

  arr.push("------------------------------------------");

  text = arr.join("\r");

  writeToFile(text);

  }

  }

  else{

  alert("Please open a document and try again.");

  }

}

function writeToFile(text) {

  var file = new File("~/Desktop/Place inline images.txt");

  if (file.exists) {

  file.open("e");

  file.seek(0, 2);

  }

  else {

  file.open("w");

  }

  file.write(text + "\r");

  file.close();

}

TOPICS
Scripting

Views

459

Translate

Translate

Report

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 ,
Mar 16, 2017 Mar 16, 2017

Copy link to clipboard

Copied

LATEST

Hi,

then I would:

1. Place the graphic to a prepared graphic frame. Not at the insertion point.
So you couuld best workaround of a possible text and graphic overflow, if the image is too large for the text frame.

// Pseudo code where myObjectStyle and myGeometricBounds should be defined first:

var newFrame = app.documents[0].rectangles.add({appliedObjectStyle : myObjectStyle , myGeometricBounds });

newFrame.place(file);

2. Anchor the graphic to the insertion point.

See method insertAnchoredObject() of the anchoredObjectSettings for the Rectangle class:

Adobe InDesign CS6 (8.0) Object Model JS: AnchoredObjectSetting

// Pseudo code continued:

newFrame.anchoredObjectSettings.insertAnchoredObject( f.insertionPoints[0] , AnchorPosition.INLINE_POSITION );

I don't know what you exactly mean by a third of your page.
Should the image exceed the width or the height of the text frame? I don't think so…

Regards,
Uwe

Votes

Translate

Translate

Report

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