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
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
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
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
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
Copy link to clipboard
Copied
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