Highlighted

Check if Specific function executed

Engaged ,
Jul 27, 2020

Copy link to clipboard

Copied

Hi Pros.

is there away to test if Specific fucntion by Name is Exceuted, so i can alert the user that the function is executed then i can exit the script, So please can you show me an Example? , My Funtion Name is (doUnStyler();), Thanks in Advance.

 

Best Regards

Mohammad

ExtendScript predates anything async in JavaScript by a decade.

 

A problem of the alert in the middle of the script execution may be that InDesign's text processing "composer" is async and not completed when the alert dialog shows and blocks all other InDesign processing (kind of the opposite of async). You may eventually get around that by adding this line before the alert(), it forces the composer to complete.

app.activeDocument.recompose()

Topics

How to, Scripting

Views

104

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Check if Specific function executed

Engaged ,
Jul 27, 2020

Copy link to clipboard

Copied

Hi Pros.

is there away to test if Specific fucntion by Name is Exceuted, so i can alert the user that the function is executed then i can exit the script, So please can you show me an Example? , My Funtion Name is (doUnStyler();), Thanks in Advance.

 

Best Regards

Mohammad

ExtendScript predates anything async in JavaScript by a decade.

 

A problem of the alert in the middle of the script execution may be that InDesign's text processing "composer" is async and not completed when the alert dialog shows and blocks all other InDesign processing (kind of the opposite of async). You may eventually get around that by adding this line before the alert(), it forces the composer to complete.

app.activeDocument.recompose()

Topics

How to, Scripting

Views

105

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
Jul 27, 2020

Copy link to clipboard

Copied

I did not quite understand you requirement, how about placing an alert inside the method defintion saying it was called, like the following

function doUnStyler
{
 alert("You called doUnStyler")
//do your stuff here
}

-Manan

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Engaged ,
Jul 27, 2020

Copy link to clipboard

Copied

Thank you for your reply but i mean when function is finshing executing and all the function code is done!, how to alert the user that the function is done befor exit the script?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Adobe Community Professional ,
Jul 27, 2020

Copy link to clipboard

Copied

The answer remains the same as above, just the alert line becomes the last line of the function definition, unless it has some other routes of exit.

If you could show a simple example of your code decribing what is needed while the code flows across functions maybe i will be able to give a better idea

 

-Manan

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Engaged ,
Jul 27, 2020

Copy link to clipboard

Copied

I tried it here but still alert the user before it real finishing the code, here is the code :

//Remove all Object Styles, Paragraph Styles, Character Styles
//Developed By Neal Derek
//Additional Developing : Mohammad Ibrahim

//Activate Undo Feature for this Script
if (parseFloat(app.version) < 6)
doUnStyler();
else
app.doScript(doUnStyler, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "UnStyle all Object,Paragraph,Character Styles");
//Start the Function
function doUnStyler() {
//Remove all Object Styles, Paragraph Styles, Character Styles
#target InDesign    
    myDoc = app.activeDocument;         
    var chs1 = myDoc.characterStyles.length;    
    for(var j=chs1-1; j>0; j--) //j++ replaced here by j--    
    {    
      var CharRes = myDoc.characterStyles[j].remove();    
    }    
  var pghs1 = myDoc.paragraphStyles.length;    
    for(var j=pghs1-1; j>1; j--)//j++ replaced here by j--    
    {    
      var PSRes = myDoc.paragraphStyles[j].remove();    
    }    
  var objs1 = myDoc.objectStyles.length;    
    for(var j=objs1-1; j>0; j--) //j++ replaced here by j--    
    {    
      var ObjRes = myDoc.objectStyles[j].remove();    
    }
//Check if the Program is Done
 alert("Finished")
}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Adobe Community Professional ,
Jul 27, 2020

Copy link to clipboard

Copied

How did you come to the conclusion that the alert is shown before the code execution is finished. I see the script deletes the styles properly before the alert pops up. What am i missing here? Which version of InDesign are you using?

-Manan

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Engaged ,
Jul 27, 2020

Copy link to clipboard

Copied

Im using InDesign 2020 (15.1.1) I have test it on 50 page document , and alert start very early!, if you test it in One Page only you will feel its normal

 

Mohammad

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Engaged ,
Jul 27, 2020

Copy link to clipboard

Copied

Hello Mohammad

 

you could try waitForTask();

 

//Remove all Object Styles, Paragraph Styles, Character Styles
//Developed By Neal Derek
//Additional Developing : Mohammad Ibrahim

//Activate Undo Feature for this Script
if (parseFloat(app.version) < 6)
doUnStyler();
else
task = app.doScript(doUnStyler, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "UnStyle all Object,Paragraph,Character Styles");
//Start the Function
function doUnStyler() {
//Remove all Object Styles, Paragraph Styles, Character Styles
#target InDesign    
    myDoc = app.activeDocument;         
    var chs1 = myDoc.characterStyles.length;    
    for(var j=chs1-1; j>0; j--) //j++ replaced here by j--    
    {    
      var CharRes = myDoc.characterStyles[j].remove();    
    }    
  var pghs1 = myDoc.paragraphStyles.length;    
    for(var j=pghs1-1; j>1; j--)//j++ replaced here by j--    
    {    
      var PSRes = myDoc.paragraphStyles[j].remove();    
    }    
  var objs1 = myDoc.objectStyles.length;    
    for(var j=objs1-1; j>0; j--) //j++ replaced here by j--    
    {    
      var ObjRes = myDoc.objectStyles[j].remove();    
    }
//Check if the Program is Done
 task.waitForTask();
 alert("Finished")
}

 

 

you may need to move the "task = " to  function doUnStyler()

Regards,

Mike

 

Edit:   Please disregard my mistake, waitForTask(); is for background task.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
medos20 LATEST
Engaged ,
Jul 28, 2020

Copy link to clipboard

Copied

Thansk alot manan, your ideas help me alot, thanks again for your generous help

Best

-Mohammad

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Adobe Community Professional ,
Jul 27, 2020

Copy link to clipboard

Copied

JS is by nature async so it could be possible that in a big document this happens. There is not much we can do here in my opinion, we can't force the sync behaviour. One idea is try putting the alert after doScript and then check.

 

-Manan

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Engaged ,
Jul 27, 2020

Copy link to clipboard

Copied

Thank you very much

-Mohammad

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Advisor ,
Jul 27, 2020

Copy link to clipboard

Copied

ExtendScript predates anything async in JavaScript by a decade.

 

A problem of the alert in the middle of the script execution may be that InDesign's text processing "composer" is async and not completed when the alert dialog shows and blocks all other InDesign processing (kind of the opposite of async). You may eventually get around that by adding this line before the alert(), it forces the composer to complete.

app.activeDocument.recompose()

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Adobe Community Professional ,
Jul 27, 2020

Copy link to clipboard

Copied

That's a fine idea Dirk. I meant the same where the api's return promptly and might lead to cases where the effect is not yet registered totally as you explained. i think your suggestion should work. Thanks for sharing your thoughts

 

-Manan

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Engaged ,
Jul 28, 2020

Copy link to clipboard

Copied

Thank you a lot,

This is much Accurate Solution, Thank you all , everyday we learn new things

Best

-Mohammad

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...