How to do multi-threading on extend script ?

Community Beginner ,
Sep 18, 2018 Sep 18, 2018

Copy link to clipboard

Copied

I have process which takes around 10 minutes - during this time I see frozen window on frame maker. Any ideas on this issue ?

TOPICS
Scripting

Views

564

Likes

translate

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
community guidelines
Mentor ,
Sep 19, 2018 Sep 19, 2018

Copy link to clipboard

Copied

Hi, I believe the concept of multiple processing threads within the FM environment is well beyond any current capability. If your tasks are taking too long, perhaps you could optimize your code to reduce the time. There are many tricks to do the same task differently and more quickly. You haven't provided any details on what your code does, so I couldn't comment any further.

Russ

Likes

translate

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
community guidelines
Community Beginner ,
Sep 23, 2018 Sep 23, 2018

Copy link to clipboard

Copied

Thanks for the answer. I get all the .fm files of 2 books and save2dita. Books are quite big. I use 3 while loop to get  3 level hierarchy - source/folder(1..n) + .fm files/folder(1..n) + .fm files.  Overall takes around 10 minutes. And I see loading icon and not responding window as long as the process is going.

Likes

translate

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
community guidelines
Mentor ,
Sep 24, 2018 Sep 24, 2018

Copy link to clipboard

Copied

Well, I'm still not exactly sure what you are doing, but maybe let me ask this question... if you were to follow all the steps manually in the UI, would it still take 10 minutes of processing? In some cases, if you are calling functionality or another API client with complex internal processing, there isn't much you can do except wait. If you are constructing your own logic piece by piece, sometimes there are multiple ways to do something, with some ways more efficient than others.

Russ

Likes

translate

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
community guidelines
Enthusiast ,
Sep 24, 2018 Sep 24, 2018

Copy link to clipboard

Copied

I have several scripts that load and edit several documents.

In this case I use a "ProgressConsoleWindow" that shows the file or/and the step the script is working on.

So the user can see, that something is happening and FrameMaker is still alive.

But I agree with Russ, that there could be a way to make the script more efficient.

Likes

translate

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
community guidelines
Community Beginner ,
Sep 25, 2018 Sep 25, 2018

Copy link to clipboard

Copied

Thanks Klaus, Russ - please find main part of code below.

function book2Xml (bookpath)

{

var comp = bookpath.FirstComponentInBook;

while (comp.id)

{

var compType=comp.ComponentType;

if(Constants.FV_BK_FOLDER == compType || Constants.FV_BK_GROUP == compType)

{

var comp1 = comp.FirstComponentInBookComponent;

while (comp1.id)

{

var compType2=comp1.ComponentType;

if(Constants.FV_BK_FOLDER == compType2 || Constants.FV_BK_GROUP == compType2)

{

var comp2 = comp1.FirstComponentInBookComponent;

while (comp2.id)

{

Console("Processing Sub-Sub Component: " + comp2.Name);

var doc3 = OpenFm (comp2.Name)

if (doc3.ObjectValid() == true) {

save2Xml (doc3)

}

comp2 = comp2.NextComponentInBook;

}

} else {

Console("Processing Sub Component: " + comp1.Name);

var doc1 = OpenFm (comp1.Name)

if (doc1.ObjectValid() == true) {

save2Xml (doc1)

}

}

comp1 = comp1.NextComponentInBook;

}

}

else

{

var compName = comp.Name;

Console("Processing Component: " + compName);

var doc2 = OpenFm (compName)

if (doc2.ObjectValid() == true) {

save2Xml (doc2)

}

}

comp = comp.NextComponentInBook;

}

}

I run this for 2 big books - I see not responding window and I don't see logs updating after few seconds because of not responding window. 

Manually it takes also 12 minutes. I know I can optimize this code but I'm not sure if it will solve this issue. I am thinking that I am missing something there.

Thanks.

Likes

translate

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
community guidelines
Engaged ,
Sep 25, 2018 Sep 25, 2018

Copy link to clipboard

Copied

Hi,

Multithreading is not possible in FrameMaker, FDK and ExtendScript.

There is nothing you can do here, but live with it. Algorithm seems OK while I prefer recursive algorithms for this, but this doesn't change anything.

I'm not sure which FM Version you are running, perhaps it's worth trying FM 2019 64bit, as I've seen significant performance optimizations there in general.

Markus

Likes

translate

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
community guidelines