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

Help with placi

Explorer ,
Sep 26, 2018 Sep 26, 2018

Copy link to clipboard

Copied

Help with opening a specific folder and placing a InDesign snippet file (idms)

I’ve got one script that will place a particular graphic…but I’m having trouble getting my script to open a particular folder and allow me to select which file I want to place.

In addition, I’d like the file to automatically place on page A2 in a newspaper document at x=0.347 in and y=1 in.

Here is what I have so far.

It opens the folder, but when I select the file, nothing happens.

var myDocument = app.activeDocument, 

myPage = myDocument.pages.item(0);

var dir = Folder("/C/Users/lpitts/Downloads");

var files = dir.openDlg('This is always the same folder?','',true);

myStory = myPage.place();

Obviously, I'm missing a command or something else, but everything I've come up empty with everything I've tried so far.

I’m new to scripting, so I’m flying blind…

Thanks for any help or advice.

Larry

TOPICS
Scripting

Views

445

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

Community Expert , Sep 28, 2018 Sep 28, 2018

Try the following

var myDocument = app.activeDocument,  

myPage = myDocument.pages.item(1);  //I suppose A2 means the 2nd page. If you mean pagename then you can use itemByName method instead of item(1)

if(myPage.isValid)

{

     var dir = Folder("/Users/manan/Downloads"); 

     var files = dir.openDlg('This is always the same folder?','',true); //This will open the folder at the location specified in the previous line      

     if(files && files.length > 0) //We need to check if the user did select

...

Votes

Translate

Translate
Community Expert ,
Sep 27, 2018 Sep 27, 2018

Copy link to clipboard

Copied

Hi Larry,

Try the following code, you were very close to make it work

var myDocument = app.activeDocument,

myPage = myDocument.pages.item(0);

var dir = Folder("/Users/manan/Downloads");

var files = dir.openDlg('This is always the same folder?','',true); //This will open the folder at the location specified in the previous line

if(files && files.length > 0) //We need to check if the user did select and did not cancel the dialog

     myStory = myPage.place(files[0]);     //You have enabled multiselect in the previous call of openDialog so we place just the first file

-Manan

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
Explorer ,
Sep 27, 2018 Sep 27, 2018

Copy link to clipboard

Copied

Thanks, Manan:

AIt worked great.....thanks so much.


Any suggestions on how to make sure the file is placed where I need it to go?

On page A2 with the coordinates of x = 0.375in and y= 1in?

As is now.....it places the file off to the side of page A1.

Thanks for your help and advice.

Larry

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
Community Expert ,
Sep 28, 2018 Sep 28, 2018

Copy link to clipboard

Copied

Try the following

var myDocument = app.activeDocument,  

myPage = myDocument.pages.item(1);  //I suppose A2 means the 2nd page. If you mean pagename then you can use itemByName method instead of item(1)

if(myPage.isValid)

{

     var dir = Folder("/Users/manan/Downloads"); 

     var files = dir.openDlg('This is always the same folder?','',true); //This will open the folder at the location specified in the previous line      

     if(files && files.length > 0) //We need to check if the user did select and did not cancel the dialog 

     {

       placedItem = myPage.place(files[0]);     //You have enabled multiselect in the previous call of openDialog so we place just the first file

       a = placedItem[0].parent

       a.geometricBounds = ["0.375in", "1in", a.geometricBounds[2], a.geometricBounds[3]]

     }

}

-Manan

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
Explorer ,
Sep 28, 2018 Sep 28, 2018

Copy link to clipboard

Copied

LATEST

Thanks again, so much....Manan.

That did the trick...
I have been playing with this script for over a week, trying to get it to work.

And without your help, I would still be working on it...

So thanks so much...

Fantastic job...

Larry

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