Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

VBScript wait for application open

Valorous Hero ,
Aug 21, 2017 Aug 21, 2017

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?

TOPICS
Scripting
2.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Mentor ,
Aug 22, 2017 Aug 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Aug 22, 2017 Aug 22, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 28, 2018 Nov 28, 2018

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Nov 28, 2018 Nov 28, 2018

I will try to find what this was and see if I actually did it

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 29, 2018 Nov 29, 2018

Thanks, Silly-V. I am very new with VB and been racking my brain all last night.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 02, 2018 Dec 02, 2018
LATEST

Found out VBS isn't compatible with try/catch or wait. This may be a hack but seems to do the job for now.

num = 0

Do While num < 1000

  Set appRef = CreateObject("Illustrator.Application.CS5")

  num = num + 1

  Loop

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