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

Removing Image

New Here ,
Jan 26, 2018 Jan 26, 2018

Hey y'all just need some help finishing up my script, I am trying to get my script to allow you to place all images into an indesign file on its own page from a folder, duplicate the page, remove the linked image in the duplicated page and place the new one and continue.

The reason I need the page duplicated is because there is a text variable that prints the images dimension, resolution & color mode when intersecting with the box and wont run/work when on master page. I have written a script that just about does it all except for the deleting the image on the new duplicated page because all it does is delete all linked images. Code I am using pasted below...

var doc = app.activeDocument;

var myPages = doc.pages;

var w =doc.documentPreferences.pageWidth;

var h = doc.documentPreferences.pageHeight;

doc.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;

var _folder = Folder.selectDialog("Select a folder");

var _files = _folder.getFiles();

for(var i =0;i<_files.length;i++)

{

if(_files instanceof File)

{

var image = doc.pages.item(-1).place(_files);

var gb = image[0].parent.geometricBounds;

var imageheight = gb[2] - gb[0];

var imagewidth = gb[3] - gb[1];

image[0].parent.geometricBounds = [

(h-imageheight)/2,

(w-imagewidth)/2,

(h-imageheight)/2+imageheight,

(w-imagewidth)/2+imagewidth

];

image[0].parent.fit(FitOptions.CONTENT_TO_FRAME)

app.layoutWindows[0].activePage.duplicate (LocationOptions.AT_END);

doc.select(myPages.item(-1), SelectionOptions.ADD_TO);

re();

function re(){

var link, image;

for (var d = 0; d < app.documents.length; d ++){

links = app.documents.links,

counter = 0;

for (var i = links.length-1; i >= 0; i--) {

if (links.hasOwnProperty('relink')) {

try {

link = links;

image = link.parent;

image.remove();

counter++;

}

catch (err) {

$.writeln(i + " - " + err);

}

}

}

}

}

}

}

doc.pages.item(-1).remove();

TOPICS
Scripting
1.1K
Translate
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

Explorer , Jan 30, 2018 Jan 30, 2018

Hi, it seems that you copied the re() function somewhere — maybe here How to remove all image in open docs ? — without fully understanding it, this function is actually designed to remove all the links from all the opened documents, so the result you get is not surprising.

I suggest to give up the re() function and simply remove image[0].parent from the active page after duplicating this page. Instead of working on the last page, keep on working on the first page using doc.pages.item(0) instead o

...
Translate
Explorer ,
Jan 30, 2018 Jan 30, 2018

Hi, it seems that you copied the re() function somewhere — maybe here How to remove all image in open docs ? — without fully understanding it, this function is actually designed to remove all the links from all the opened documents, so the result you get is not surprising.

I suggest to give up the re() function and simply remove image[0].parent from the active page after duplicating this page. Instead of working on the last page, keep on working on the first page using doc.pages.item(0) instead of doc.pages.item(-1), place the _files on  the first page that you duplicate then each time at the end of the document before removing the current image from the first page and placing the next image still on the first page. Finally, remove the first page instead of the last.

Here is my modified version:

var doc = app.activeDocument;

var myPages = doc.pages;

var w = doc.documentPreferences.pageWidth;

var h = doc.documentPreferences.pageHeight;

doc.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;

var _folder = Folder.selectDialog('Select a folder');

var _files = _folder.getFiles();

for (var i=0; i<_files.length; i++)

{

  if (_files instanceof File)

  {

    var image = doc.pages.item(0).place(_files);

    var gb = image[0].parent.geometricBounds;

    var imageheight = gb[2] - gb[0];

    var imagewidth = gb[3] - gb[1];

    image[0].parent.geometricBounds = [

      (h - imageheight) / 2,

      (w - imagewidth) / 2,

      (h - imageheight) / 2 + imageheight,

      (w - imagewidth) / 2 + imagewidth

    ];

    image[0].parent.fit(FitOptions.CONTENT_TO_FRAME);

    app.layoutWindows[0].activePage.duplicate(LocationOptions.AT_END);

    doc.select(myPages.item(0), SelectionOptions.ADD_TO);

    //re();

    image[0].parent.remove();

  }

}

doc.pages.item(0).remove();

Regards,

Frédéric.

Translate
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 06, 2018 Feb 06, 2018
LATEST

Frédéric thank you sooooo much!! I couldnt figure it out for the life of me.

Translate
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