Copy link to clipboard
Copied
@frameexpert - Adding a mention since you don't necessarily follow the InDesign boards.
First off, I know this isn't only an Adobe issue. I've run into similar problems with Visual Basic (and similar solutions).
Anyway - My scripts tend to run through a lot of steps and function calls. I've noticed that sometimes some of the steps are "missed" - i.e., I'll run the script and the expected action does not happen. I'll run the script again and it works as expected. I'm "assuming" that the script moves on to the next action before the previous one completes and that causes the issue.
I've found often putting a 0.5-second pause before and after the action usually resolves the issue:
$.sleep(500);
but I wasn't sure if this was commonplace (I haven't seen it often in scripts others posted online), or if there was a better solution ...
Issues with this solution (applies to VBA also):
Thanks in advance!
Copy link to clipboard
Copied
What kind of operations are you talking about?
I know at least one specific situation - but maybe it's not the same.
Copy link to clipboard
Copied
Hi @Marshall_Brooks a pause might help when you are dealing with an asynchronous call to some other process, but it is not a comfortable situation. Can you identify the "actions" that might be causing the subsequent missing operations? Sometimes there are more robust approaches that avoid them without hacks like $.sleep.
Putting a delay *before* an operation suggests that it is actually *after* a previous operation that has not completed. Otherwise there is no reason to sleep before an operation because nothing has happened yet.
Perhaps you could insert an assertion into the code after the "action" that checks if the action is finished (this could be a while loop with a short $.sleep(100) and a timeout. Just an idea.
- Mark
Copy link to clipboard
Copied
Great suggestions. The script does multiple things. The specific action that was being skipped was a find and replace character formats. The action before that step was a save document (to a network drive). The action before that were other find and replace text statements. The script also sets and hides conditional formats, opens a template on the network drive and updates master pages, etc.
Also, there seem to be two types of intermittent errors:
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Hi @Marshall_Brooks , Can you show an example your find and change code?
Copy link to clipboard
Copied
Find and Change (there are a couple of them) is here: https://community.adobe.com/t5/framemaker-discussions/script-to-change-red-text-to-black/m-p/1530539...
I have a couple of them in the script (one is just text, but is similar).
I have most of the issues with the script worked out. I added about eight 0.5-second sleep statements. Crude and ugly, but the script seems to be working.
The issue with the window freezing seemed to happen when I had a revert to save step and closed and re-opened the document and the script lost the active document. I had to add code to close and re-open the pop-up window and redefine the "doc" variable, but that seemed to fix the issues.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Understood. On the FrameMaker forum, I was previously referred here for ScriptUI questions, which is basically what this is.
Copy link to clipboard
Copied
Understood. On the FrameMaker forum, I was previously referred here for ScriptUI questions, which is basically what this is.
By @Marshall_Brooks
But those are completely different applications 🙁 so problems are most likely not related.
Copy link to clipboard
Copied
Not sure I’m understanding your code, but it doesn’t look like you are using the built-in ExtendScript F&C properties and methods—is there a reason for that?
A simple text search example:
//the Find/Change result as an array
var res = getTextSearch("hello")
//loop the returned array
for (var i = 0; i < res.length; i++){
$.writeln(res[i].contents)
};
/**
* Gets results of a text search as an array
* @ param text to search for
* @ return result array
*/
function getTextSearch(fp){
app.findTextPreferences = app.changeTextPreferences = app.findChangeTextOptions = null;
app.findChangeTextOptions.properties = {includeHiddenLayers:true,
includeLockedLayersForFind:true,
includeLockedStoriesForFind:true,
includeMasterPages:true}
app.findTextPreferences.findWhat = fp;
return app.activeDocument.findText()
}
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Correct, the script is for FrameMaker.
The original script was posted here: https://community.adobe.com/t5/framemaker-discussions/find-replace/td-p/3581679#4032650 by @Ian Proudfoot as a modification of @Russ Ward code.
I needed it to search for font changes and @frameexpert helped me with that in the previously linked thread.
There are minor issues with the script (it seems to wrap to the beginning even though the code implies it shouldn't, but otherwise, it seems to work well.
Copy link to clipboard
Copied
But it has nothing to do with InDesign...
Maybe in the FrameMaker there is a possibility of "skipping" F&C request - but not in the InDesign.
Not in the ExtendScript nor in VBS - maybe in the UXP version of the script.
Copy link to clipboard
Copied
Hi @Marshall_Brooks ,
with very large InDesign documents I would work with exportFile() instead of asynchronousExportFile().
You could determine this e.g. by the number of pages that are involved in the export process.
Notes:
Perhaps it would also help if your script has only one document open at the same time going through a lot of documents in a folder or documents from a book file.
Regards,
Uwe Laubender
( Adobe Community Expert )
Find more inspiration, events, and resources on the new Adobe Community
Explore Now