Removing Links

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

carlosantulio
Posts: 1
Joined: Thu Jan 25, 2018 5:55 pm

Removing Links

Post by carlosantulio »

I wasn't sure where to post this since there wasnt a section for Indesign scripts. 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[d].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();
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Removing Links

Post by Kukurykus »