dersenn
New Here
dersenn
New Here
Activity
‎Sep 03, 2024
02:32 AM
Hello everybody. In case anybody is still watching this. Last week I came across this script again and thought I'd give it another try as some time has passed and InDesign has been updated a few times. And it worked! Albeit just with color profile warnings on open turned on (which I had on lately). Turning it off again brought back the warning about the doc being already open. Unfortunately it doesn't even work by setting "app.colorSettings.mismatchAskWhenOpening" temporarily to "true" in the script. So, not really a solution, but another direction to look into. But I'm suspecting unless InDesign adresses this bug, we're out of luck. Thanks everybody!
... View more
‎Jan 26, 2023
07:27 AM
Hi everybody. I'm back on this Issue, still with no success. But I found a Bug Report by Peter Kahrel from late 2018, which is more or less exactly the issue here. Unfortunately without any resolve. Interesting that I never saw this before. I also worked my way through the other threads mentioned above, but since the script is working on direct links and the error messages correlate I think it's more the issue of not being able to process layers in files opened by script... but at least it's a new direction to dig in.
... View more
‎Nov 11, 2022
07:28 AM
And now I've gotten consistently 3 as a result. Several restarts of Indesign... Also, if I put a writeln in there: fn = p[i].parent.allGraphics[0].itemLink.name;
$.writeln(fn); It reports the expected 6 files: Product 01.indd
Layout 01.indd
Techinfo A.indd
Product 02.indd
Layout 02.indd
Techinfo A.indd
... View more
‎Nov 11, 2022
07:12 AM
Hey Rob & Uwe, I also finally had the time to quickly run this testing script. And it gets weirder every time. First run, from ID: 6 Documents. Second run, from ID: also 6. Third run, from Visual Studio: 3. Fourth run, from ID: 3. Quit Indesign. Another run from Indesign: 8(!) Documents...
... View more
‎Nov 04, 2022
01:57 AM
Hey @m1b, thanks for looking into this. I'm pretty sure I was looking into the thread above and crazyPandas script when I did the first Versions of the script (for direct links). In the end I ended up with a modified Version for Kasyans batch processor and eventually wrote a simplified standalone version. But it has been a few years. I will look into that thread, script and bug report in detail. Thanks!
... View more
‎Nov 04, 2022
01:51 AM
Ah, Thanks @Laubender, will try that.
... View more
‎Nov 03, 2022
09:09 AM
Ok, working a bit more with the simplified version I found out, that the thing breaks as soon as layer.currentVisibility = checklist[ft][k].checkedState; actually means a change to layer.currentVisibility. If both values are the same, it runs through until the end. Still no clue as to why — I've used this method on scripts for direct links a thousand times.
... View more
‎Nov 03, 2022
06:25 AM
Hey @Dirk Becker, I tried this. But apparently getElements() is not a supported method for links.
... View more
‎Nov 03, 2022
06:23 AM
Ok. So here is the simplified (well, as simple as possible) example. Open the "Overview.indd" and run the script on that file. Which should open the "Product" files and change layer visibility on placed files therein. Right now apparently it only creates an error when there's a difference. So you need to uncheck something in the Dialog. And here's the script, thanks for any help! // object containing the layers we have in the different kinds of files.
var layertypes = {
techinfo: [
{name: "Container", showDefault: true},
{name: "Information", showDefault: true}
],
layout: [
{name: "Badge", showDefault: true},
{name: "Artwork", showDefault: true}
]
};
// stores the desired visibility.
var checklist = {
techinfo: [],
layout: []
};
var doc,
settings;
// Collection for the "Product" files we want to open.
var products = [];
var thisLink,
thisFile,
thisFileName,
thisDoc,
thisDocLinks;
var currentLink,
currentLinkname,
currentLayer,
currentChecklistItem;
var ft,
layer;
Main();
function Main() {
if(app.documents.length == 0){
alert("No documents are open. Please open a document and try again.");
exit();
}
else {
doc = app.activeDocument;
settings = saveSettings();
app.linkingPreferences.checkLinksAtOpen = false;
myDialog();
restoreSettings(settings);
}
}
// Dialog gets constructe from the layertypes object.
function myDialog() {
var myDialog = app.dialogs.add({name:"Show / Hide Layers", canCancel: true});
with(myDialog) {
with(dialogColumns.add()) {
with(dialogRows.add()) {
staticTexts.add({ staticLabel: "Techinfo" });
for (var i = 0; i < layertypes.techinfo.length; i++) {
with(dialogRows.add())
checklist.techinfo.push(checkboxControls.add({
staticLabel: layertypes.techinfo[i].name,
checkedState: layertypes.techinfo[i].showDefault
}));
}
}
}
with(dialogColumns.add()) {
with(dialogRows.add()) {
staticTexts.add({ staticLabel: "Layout" });
for (var i = 0; i < layertypes.layout.length; i++) {
with(dialogRows.add())
checklist.layout.push(checkboxControls.add({
staticLabel: layertypes.layout[i].name,
checkedState: layertypes.layout[i].showDefault
}));
}
}
}
}
if (myDialog.show() == true) {
checkLinks(doc.links);
if(products.length > 0) {
changeNestedLayers(products);
}
alert("Done!");
} else {
myDialog.destroy();
}
}
// The problematic function.
function changeNestedLayers(linksArr) {
for (l = linksArr.length - 1; l >= 0; l--) {
thisLink = linksArr[l];
thisFile = File(thisLink.filePath);
thisFileFullPath = thisFile.fullName;
thisDoc = app.open(thisFile, true);
$.writeln("Opened: " + thisFile);
thisDocLinks = thisDoc.links;
for(var s = thisDocLinks.length - 1; s >= 0; s--) {
currentLink = thisDocLinks[s];
currentLinkname = currentLink.parent.itemLink.name;
if (currentLink.parent.constructor.name == "ImportedPage" && currentLink.parent.itemLink != null && currentLink.parent.itemLink.linkType == "InDesign Format Name") {
if(hasSubstring(currentLinkname, "Techinfo")) {
changeLayerVisibility(currentLink, "Techinfo");
}
if(hasSubstring(currentLinkname, "Layout")) {
changeLayerVisibility(currentLink, "Layout");
}
}
}
if (thisDoc.converted) {
thisDoc.save(File(thisFileFullPath))
} else {
thisDoc.save()
}
$.writeln("Closing: " + thisDoc.fullName);
thisDoc.close(SaveOptions.NO);
if (thisLink.status == LinkStatus.LINK_OUT_OF_DATE) {
thisLink.update();
}
}
}
// the other problematic function.
function changeLayerVisibility(thisLink, filetype) {
ft = filetype.toLowerCase();
for (var k = 0; k < layertypes[ft].length; k++) {
layer = thisLink.parent.graphicLayerOptions.graphicLayers.item(layertypes[ft][k].name);
if (layer.isValid) {
$.writeln(layer.currentVisibility);
$.writeln(checklist[ft][k].checkedState);
// If the following line is commented out, all goes well.
// Otherwise error, pointing to line 149. File already open...
layer.currentVisibility = checklist[ft][k].checkedState;
}
}
}
// check and change layer visibility for direct links (Not in use right now).
// push products to separate list for opening (in use).
function checkLinks(linksArr) {
for (var l = 0; l < linksArr.length; l++) {
var thisLink = linksArr[l];
var linkname = thisLink.parent.itemLink.name;
if (thisLink.parent.constructor.name == "ImportedPage" && thisLink.parent.itemLink != null && thisLink.parent.itemLink.linkType == "InDesign Format Name") {
if(hasSubstring(linkname, "Product")) {
products.push(thisLink);
}
else if(hasSubstring(linkname, "Techinfo")) {
changeLayerVisibility(thisLink, "Techinfo");
}
else if(hasSubstring(linkname, "Layout")) {
changeLayerVisibility(thisLink, "Layout");
}
}
}
}
// Utility Functions
function hasSubstring(string, substring) {
if(string.indexOf(substring) !== -1) return true;
}
function saveSettings() {
var settingsTemp = {
checkLinksAtOpen: app.linkingPreferences.checkLinksAtOpen
};
return settingsTemp;
}
function restoreSettings(settings) {
app.linkingPreferences.checkLinksAtOpen = settings.checkLinksAtOpen;
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
}
... View more
‎Nov 01, 2022
08:25 AM
Yes. That's why I grabbed the full filepath and name before opening the link and creating the doc.
... View more
‎Nov 01, 2022
08:18 AM
Interesting. I now tried to create a simplified version including shareable indd files. And it throws me an error exactly when I try to open the file... arrgh. I think I'll have to take a step back again here.
... View more
‎Nov 01, 2022
07:09 AM
Hey @rob day, finally I'm having time again to get back to this. Thanks for your input. But I don't think this is the problem. After all, if I take out everything between opening and saving/closing the file, everything works as expected. The Files get opened and saved. I was mistakenly referring to filename in my previous reply, when I meant the full path and name. Which I get via: thisFileName = thisFile.fullName; And using this to save my file is essentially the same as constructing it from path and name afterwards as in your example: thisFilePath = thisDoc.filePath + "/" + thisDoc.name;
// Changed var name to avoid confusion. However, I still like the idea of the conditional save involving .converted.
... View more
‎Oct 27, 2022
07:12 AM
Which is basically what your snippet does!
... View more
‎Oct 27, 2022
07:11 AM
Hey @rob day. Yes, that's why I grab that filename before opening the doc. But the .converted property is interesting nonetheless and could simplify that. Only do it if it is a converted document. Otherwise just save as usual. Thanks!
... View more
‎Oct 27, 2022
05:35 AM
This could be something. I'll try it later.
... View more
‎Oct 27, 2022
05:33 AM
Thanks for this input. Although I doubt it is the culprit. The error happens before that and it doesn't even get to the saving part. A little background on why it is saved as a new file with the same name. This is a solution I came across for another script (which updates nested links). Nowadays InDesign gets updated fairly regularly, so files that have not been touched for a few weeks/months get opened as a copy and you need to save them again. You've certainly done this and you need to overwrite the file. Since they get opened as a copy ([converted]), they don't have their original filename and path information. That's why this gets stored before the file is opened.
... View more
‎Oct 26, 2022
05:12 AM
Again, thanks. I've got the minimal setup now running (with just the launch.json). Will look into the more refined settings once I need it. Okay, it is pretty nice to finally have a console for InDesign scripting! 😂 Now I just need to figure out why on earth it wants to open a file on that line...
... View more
‎Oct 26, 2022
12:30 AM
Hey @m1b , thank you for your thorough guide. I'll definitely give this a try later, when I'm back on that task.
... View more
‎Oct 25, 2022
10:12 AM
I quickly gave it a try. So far resulting in two InDesign crashes. I'll give your launch.json a try. Thanks!
... View more
‎Oct 25, 2022
09:25 AM
Hey @rob day , thanks for the input. I haven't tried any writeln statements, since there's no toolkit anymore and I have been a bit reluctant to change from my current editor to Visual Studio... But might be a good moment to give it a try. Still I find it strange that it works perfectly if there simply is an alert somewhere...
... View more
‎Oct 25, 2022
09:16 AM
Yes, you are right. I was referring to the outer loop, since I think the problem lies there somewhere. But also reversing the loop you mentioned doesn't change anything. But good to hear you had the same issue — just too bad you couldn't figure it out either 😉
... View more
‎Oct 25, 2022
08:16 AM
Hey AdobeScripts, thanks for your reply. In general our workflow with the placed INDD files works like charm. And we have a single source of truth which we can export when needed. Iterating backwards... interesting. I remember rewriting the for loops to my liking when adapting the scripts. I quickly tried reversing the outermost loop. Doesn't change anything though. Also, I'm not iterating over the general links collection, but rather an array of collected links. And the script works exactly as advertised IF there is any alert() somewhere between opening and saving the file. This is what's really bugging me...
... View more
‎Oct 25, 2022
07:12 AM
Dear community I am at a loss here and can't find a solution. This is part of a script which opens linked InDesign files, changes the layer visibility on the documents placed in the opened links.
If I put an alert() somewhere between opening and saving the document, everything works fine. If I remove the alert() I get an error, telling me that the file is already open. The error points to the last command in the changeLayerVisibility() Function: layer.currentVisibility = checklist[ft][k].checkedState;
I'm thinking it has something to do with async or timeouts. The alert slowing the process, allowing the loop to finish. But I can't understand why it would ever try to open the same file again...
Here's the relevant part of the script. I hope someone sees where I'm going wrong. If not I can try to create a reduced version of the thing.
function changeNestedLayers(linksArr) {
var thisLink,
thisFile,
thisFileName,
thisDoc;
for (var l = 0; l < linksArr.length; l++) {
thisLink = linksArr[l];
thisFile = File(thisLink.filePath);
thisFileName = thisFile.fullName;
thisDoc = app.open(thisFile, true);
var currentLink,
currentLinkname,
currentLayer,
currentChecklistItem;
for(var s = 0; s < thisDoc.links.length; s++) {
currentLink = thisDoc.links[s];
currentLinkname = currentLink.parent.itemLink.name;
if (currentLink.parent.constructor.name == "ImportedPage" && currentLink.parent.itemLink != null && currentLink.parent.itemLink.linkType == "InDesign Format Name") {
if(hasSubstring(currentLinkname, "FiletypeA")) {
changeLayerVisibility(currentLink, "FiletypeA");
count++;
}
else {
changeLayerVisibility(currentLink, "FiletypeB");
count++;
}
}
}
thisDoc.save(new File(thisFileName));
thisDoc.close(SaveOptions.NO);
}
}
function changeLayerVisibility(thisLink, filetype) {
var ft = filetype.toLowerCase();
var layer;
for (var k = 0; k < layertypes[ft].length; k++) {
layer = thisLink.parent.graphicLayerOptions.graphicLayers.item(layertypes[ft][k].name);
if (layer.isValid) {
layer.currentVisibility = checklist[ft][k].checkedState;
}
}
}
Thanks!
... View more
‎Feb 16, 2016
05:16 AM
Hello Ronald Great! I have been looking for something like this the whole Day! And this script seems to work like a charm. Thanks a lot! It even works in CS 5.5, if anybody wonders. How would I proceed if I wanted to look for multiple strings to replace? Say: "2015.psd" to "2015_CMYK_C.psd" and "2015_U.psd" to "2015_CMYK_U.psd"? And possibly even more? Thanks for any Help! Best, Christoph
... View more