Is it possible to force indesign search for frames by their links and apply a specified object style to them? Any Script will appreciated!
Try this... Works just like a grep query.
// [310718] Link2ObjectStyle
// Apply object style to graphic frames in regard to linked file name
// written by Vinny
if (parseFloat(app.version) < 6) {
main();
} else {
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Link2ObjectStyle");
}
function main() {
if (app.documents.length > 0) {
//------------
//Variables
var
myDoc = app.documents[0],
myObjectStyles = myDoc.objectStyles.everyItem(),
myLinks = myDoc.allGraphics;
//------------
//Dialog box
var myDialog = app.dialogs.add({
name: "Apply object style to graphic frames in regard to linked file name",
canCancel: true
});
with(myDialog) {
with(dialogColumns.add()) {
with(borderPanels.add()) {
with(dialogColumns.add()) {
staticTexts.add({
staticLabel: "File name contains:"
});
}
with(dialogColumns.add()) {
var myTextEditField = textEditboxes.add({});
}
}
with(borderPanels.add()) {
with(dialogColumns.add()) {
staticTexts.add({
staticLabel: "Apply object style:"
});
}
with(dialogColumns.add()) {
var myObjectStylesMenu = dropdowns.add({
stringList: myObjectStyles.name,
selectedIndex: 0
});
}
}
}
if (myDialog.show() == true) {
var myString, myObjectStyle, myObjectStylesMenu, fileName, j = 0;
myString = myTextEditField.editContents;
myObjectStyle = myDoc.objectStyles[myObjectStylesMenu.selectedIndex];
myDialog.destroy();
//------------
//let's rock
if (myString == "") {
alert("you didn't enter any string");
return null;
} else {
for (i = 0; myLinks.length > i; i++) {
if (myLinks[i].itemLink.name.search(myString) != -1) {
myLinks[i].parent.applyObjectStyle(myObjectStyle);
j++;
}
}
//------------
//end
if (j == 0) {
alert("String could not be found\nScript ends");
} else {
alert(j + " objects found.\nYou're done");
}
}
} else {
myDialog.destroy()
}
}
} else {
alert("Open a document");
return null
}
}
-
Thanks Vinny, This is what I wanted, really appreciate your effort, apples and strawberries are now free to roam around my documents!!! :D – Roozbeh E Jul 31 '18 at 20:48
-
-
1A • M • A • Z • I • N • G • ! – user120647 Jul 31 '18 at 22:40
-
1@Vinny I tried it in a test document like yours, but need to go to work and run it there, most matter in my mind was issues with multi-purpose objects and wanted to make sure script detects every kind of objects like, inline anchored, custom anchored, outside of the page, in multi pages, anchored in table, in groups (with and without anchor), and normal placed images. Script found everything. Before this with some other scripts I had some issues that not all kind of objects detected by script, and it was most annoying thing! But now this one is working so fine! – Roozbeh E Aug 1 '18 at 3:21
Tested script to create an empty style to all frames with .eps or .tif. Running the script add two object styles to the document that can be modified.
//ApplyObjectStylesTo_ContainersOf_TIF_EPS.jsx
//Uwe Laubender
/**
* @@@BUILDINFO@@@ ApplyObjectStylesTo_ContainersOf_TIF_EPS.jsx !Version! Thu Dec 12 2013 13:15:30 GMT+0100
*/
//Edit your style names here. Change the name between the two " " only!!
//OR: edit your object styles in InDesign after running the script.
var styleNameForEPS = "EPS-Containers-Only";
var styleNameForTIF = "TIF-Containers-Only";
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
app.doScript(_ApplyObjectStylesToContainers, ScriptLanguage.JAVASCRIPT, [], UndoModes.ENTIRE_SCRIPT, "Apply object styles to containers for TIF and EPS graphics");
function _ApplyObjectStylesToContainers(){
var d=app.documents[0];
var allGraphicsArray = d.allGraphics;
if(!d.objectStyles.itemByName(styleNameForEPS).isValid){
d.objectStyles.add({name:styleNameForEPS});
};
if(!d.objectStyles.itemByName(styleNameForTIF).isValid){
d.objectStyles.add({name:styleNameForTIF});
};
for(var n=0;n<allGraphicsArray.length;n++){
//The EPS case:
if(allGraphicsArray[n].getElements()[0].constructor.name === "EPS"){
allGraphicsArray[n].parent.appliedObjectStyle = d.objectStyles.itemByName(styleNameForEPS);
};
//The TIF case
if(allGraphicsArray[n].getElements()[0].constructor.name === "Image" && allGraphicsArray[n].getElements()[0].imageTypeName === "TIFF"){
allGraphicsArray[n].parent.appliedObjectStyle = d.objectStyles.itemByName(styleNameForTIF);
};
};
}; //END: function _ApplyObjectStylesToContainers()
-
2Daniel, come back here. Vinny wrote an amazing script and it so handy and catchy. come here asap and get it! also don't forget to visit my question at adobe forum, vinny also added a mini gif video to explain the script: forums.adobe.com/thread/2518997 – Roozbeh E Jul 31 '18 at 20:51
Ass I wrote in the comments:
Unfortunately I don't know coding, but my logic tells me that changing the image to another folder makes it easy to search the frames with missing links and apply the style. Then return the image to the source folder.
This is the script to add a style to all the frames with missing links in a document:
var link, image, frame,
doc = app.activeDocument,
links = doc.links,
counter = 0;
nameOfObjectStyle = "YourStyle"; /**Replace *YourStyle* for the name of your style**/
var objectStyleThatShouldBeApplied = app.documents[0].objectStyles.itemByName( nameOfObjectStyle );
for (var i = links.length-1; i >= 0; i--) {
if (links[i].status == LinkStatus.LINK_MISSING) {
try {
link = links[i];
image = link.parent;
frame = image.parent;
frame.applyObjectStyle( objectStyleThatShouldBeApplied , false, false );
counter++;
}
catch (err) {
$.writeln(i + " - " + err);
}
}
}
-
Thank you dan... the object linkstatus maybe a clue for someone. maybe it could be a another parameter like "location" , "path" or name. – Roozbeh E Jul 31 '18 at 7:47
var myGraphicFrames = app.activeDocument.rectangles; for (i=myGraphicFrames.length-1; i>=0; i--) { if (myGraphicFrames[i].graphics.length < 1) myGraphicFrames[i].remove(); }
this script delete empty graphic frames – user120647 Jul 30 '18 at 16:49