Skip to main content
Silly-V
Legend
August 21, 2017
Question

VBScript wait for application open

  • August 21, 2017
  • 1 reply
  • 2326 views

I have my VBS code which detects if Illustrator is running and launches it if not. The problem is, it doesn't really stop and wait with the rest of the code while Illustrator is launching, and appears to be running code too soon and causing errors.

I found this thread on our forum, but it looks like it's dealing with a document being loaded in the app?

This topic has been closed for replies.

1 reply

Disposition_Dev
Legend
August 22, 2017

can you do something like a while loop that executes until the file is completely loaded? For instance whatever document properties are missing when the rest of your script starts executing.. perhaps each of the properties causing your errors.

idk VBS but in JS:

In this example we want to verify that there is an active document, that we can access the layers in the document and that we can access the swatches. if any of those fail, then the loop continues.

function test()

{

    var docReady = false;

    var MAX_TRIES = 1000;

    var curTries = 0;

    while(!docReady && curTries < MAX_TRIES)

    {

        try

        {

            curTries++;

            $.writeln("trying number " + curTries);

            var docRef = app.activeDocument;

            var layers = docRef.layers;

            var swatches = docRef.swatches;

            docReady = true;

        }

        catch(e)

        {

            $.writeln("doc not ready");

        }

    }

    $.writeln("finished.");

}

test();

just a thought. i don't know whether AI will continue to open the file during the while loop execution or if the loop will pause illustrator until it's done.

Silly-V
Silly-VAuthor
Legend
August 23, 2017

Good idea, I can try to make a VB try-catch approximation which repeats in a loop until one of the code lines which depends on the Illustrative being loaded and running, does not error. I'll try this and say what I find.

Participating Frequently
November 28, 2018

Any chance you have this one figured out? I am recently running into the same problem in VB.