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

Scripting images into frames

New Here ,
Feb 07, 2017 Feb 07, 2017

Copy link to clipboard

Copied

Hi,

I'm beginning with this so I apologise in advance if this seems trivial. I'm struggling to script the placement of an image into a frame using JavaScript for InDesign CC 2017 (ExtendScript Toolkit). On my last line, I get "object is invalid" for the frame - which I've labelled with a script lael "Image1" in the InDesign file.

Any help would be really appreciated where it seems in terms of syntax I am doing the same as a number of tutorials out there.

var folder = "/c/Users/d_a_g/OneDrive/Work/InDesign/ContentTest/"
var myFolder = Folder(folder),
myTemplate = File(myFolder + "/ContentTemplate.indd"),
//myPics = myFolder.getFiles("*.jpg"),
newDoc = app.open(myTemplate),
myDoc = app.activeDocument,
myPages = myDoc.pages,
i = 0,
lastPage = 0;

firstPage = myDoc.pages.item(0)
firstFrame = firstPage.rectangles.item("Image1");

$.writeln(firstPage);
$.writeln(firstFrame);

var myGraphicFile = File.openDialog ("Choose a file");
$.writeln(myGraphicFile);
firstFrame.place(myGraphicFile);

Views

5.0K

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

correct answers 1 Correct answer

People's Champ , Feb 07, 2017 Feb 07, 2017

Try this:

var main = function() {

  var folder = "/c/Users/d_a_g/OneDrive/Work/InDesign/ContentTest/",

  myTemplate, newDoc, firstPage, myGraphicFile;

  //Checking folder existence

  if ( !folder.exists ) {

  alert(folder.fsName+" doesn't exist" );

  return;

  }

  myTemplate = File(myFolder + "/ContentTemplate.indd"),

  //Checking myTemplate existence

  if ( !myTemplate.exists ) {

  alert(myTemplate.fsName+" doesn't exist" );

  return;

  }

  //Referencing newDoc as the document being opened i.e. the activeDocu

...

Votes

Translate

Translate
Guide ,
Feb 07, 2017 Feb 07, 2017

Copy link to clipboard

Copied

Hi

I think you should ask your question in the INDD scripting forum:

InDesign Scripting

Vinny

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
New Here ,
Feb 08, 2017 Feb 08, 2017

Copy link to clipboard

Copied

LATEST

Apologies - when I searched to find this - I couldn't initially find it. Thanks for the link. Will put any future posts there.

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
People's Champ ,
Feb 07, 2017 Feb 07, 2017

Copy link to clipboard

Copied

Try this:

var main = function() {

  var folder = "/c/Users/d_a_g/OneDrive/Work/InDesign/ContentTest/",

  myTemplate, newDoc, firstPage, myGraphicFile;

  //Checking folder existence

  if ( !folder.exists ) {

  alert(folder.fsName+" doesn't exist" );

  return;

  }

  myTemplate = File(myFolder + "/ContentTemplate.indd"),

  //Checking myTemplate existence

  if ( !myTemplate.exists ) {

  alert(myTemplate.fsName+" doesn't exist" );

  return;

  }

  //Referencing newDoc as the document being opened i.e. the activeDocument

  newDoc = app.open(myTemplate),

  firstPage = newDoc.pages[0];

  //Referencing the first frame

  firstFrame = firstPage.rectangles[0];

  //Checking firstFrame validity

  if ( !firstFrame.isValid ) {

  alert(firstFrame+" doesn't exist" );

  doc.close(SaveOptions.NO);

  return;

  }

  myGraphicFile = File.openDialog ("Choose a file");

  //Exit if no file opened

  if ( !myGraphicFile ) return;

  //Placing the image

  firstFrame.place(myGraphicFile);

}

main();

HTH

Loic

Ozalto | Productivity Oriented - Loïc Aigon

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