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

script 'document is still loading'

Community Beginner ,
Sep 13, 2024 Sep 13, 2024

Copy link to clipboard

Copied

Good afternoon,

 

Trying to run a script and it says 'document is still loading'.

 

Chatgbt says that when this happens it usually means the script is trying to run on the document before it’s fully initialized.
I have put some delay code in, and same message.
It is a blank Dita concept file.
Any suggestions?

Thank you,

Vicki

Views

489

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

correct answers 1 Correct answer

Community Expert , Sep 17, 2024 Sep 17, 2024

I am sorry for the delay in responding. Here is code that deletes all Paragraph Formats from the active document.

 

main ();

function main () {
	
	var doc;
	
	// Test for an open, active document.
	doc = app.ActiveDoc;
	if (doc.ObjectValid () === 1) {
		processDoc (doc);
	}
}

function processDoc (doc) {
	
	var pgfFmt, nextFmt;
	
	// Delete all paragraph formats in the document.
	pgfFmt = doc.FirstPgfFmtInDoc;
	while (pgfFmt.ObjectValid () === 1) {
		nextFmt = pgfFmt.NextPgfFmtInDoc;
		pgfFmt.D
...

Votes

Translate

Translate
Community Expert ,
Sep 13, 2024 Sep 13, 2024

Copy link to clipboard

Copied

Can you post the code? Or, give an overview of what the code is doing?

Votes

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 13, 2024 Sep 13, 2024

Copy link to clipboard

Copied

//  Function to Delay Execution
function delay(ms) {
    var start = new Date().getTime();
    while (new Date().getTime() < start + ms) {}
}

// Function to Check Document Loading Status
function checkDocumentLoading(doc, maxAttempts, delayMs) {
    var attempts = 0;
    while (attempts < maxAttempts) {
        if (doc.IsLoaded) {
            return true;
        }
        attempts++;
        delay(delayMs);
    }
    return false;
}

// Main Script Execution
try {
    var doc = app.ActiveDoc;

    if (doc == null) {
        alert("No document is open.");
    } else {
        alert("Document detected: " + doc.Name);
        
        // Introduce delay before checking
        delay(5000); // Wait for 5 seconds

        // Check if the document is fully loaded
        var loaded = checkDocumentLoading(doc, 10, 2000); // 10 attempts with 2-second intervals

        if (loaded) {
            alert("Document is fully loaded: " + doc.Name);

            // Example of accessing Paragraph Catalog
            try {
                var paraCatalog = doc.ParagraphCatalog;
                if (paraCatalog == null) {
                    alert("Paragraph Catalog is not accessible.");
                } else {
                    alert("Paragraph Catalog is accessible. Number of formats: " + paraCatalog.Count);
                }
            } catch (e) {
                alert("Error accessing Paragraph Catalog: " + e.message);
            }
        } else {
            alert("Document is still loading after multiple attempts.");
        }
    }
} catch (e) {
    alert("Error: " + e.message);
}




Votes

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 13, 2024 Sep 13, 2024

Copy link to clipboard

Copied

It does find my document though.

 

Line 27.

alert("Document detected: " + doc.Name);

Votes

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 Expert ,
Sep 13, 2024 Sep 13, 2024

Copy link to clipboard

Copied

Are you trying to do something after a document is opened?

Votes

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 Expert ,
Sep 13, 2024 Sep 13, 2024

Copy link to clipboard

Copied

Try describing the purpose of the script in plain language.

Votes

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 16, 2024 Sep 16, 2024

Copy link to clipboard

Copied

GM,
I was trying to access the Paragraph Catalog and delete all the paragraphs styles, so that could import my own styles. I got an error message saying that it could not access the Paragraph Catalog.
  I then tried to troubleshoot. Is it able to open the document? Yes. But the reply is that the document is still loading and because of that unable to access Paragraph Catalog.
  I think the scripts and question is too big to be answered here.
May I ask if there is there a good resource that you like to learn about ExtendScript for Framemaker?
Thank you,
Vicki

Votes

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 Expert ,
Sep 17, 2024 Sep 17, 2024

Copy link to clipboard

Copied

I am sorry for the delay in responding. Here is code that deletes all Paragraph Formats from the active document.

 

main ();

function main () {
	
	var doc;
	
	// Test for an open, active document.
	doc = app.ActiveDoc;
	if (doc.ObjectValid () === 1) {
		processDoc (doc);
	}
}

function processDoc (doc) {
	
	var pgfFmt, nextFmt;
	
	// Delete all paragraph formats in the document.
	pgfFmt = doc.FirstPgfFmtInDoc;
	while (pgfFmt.ObjectValid () === 1) {
		nextFmt = pgfFmt.NextPgfFmtInDoc;
		pgfFmt.Delete ();
		pgfFmt = nextFmt;
    }
}

Votes

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 17, 2024 Sep 17, 2024

Copy link to clipboard

Copied

Thank you for posting.

Is there  a good resource that you like to learn about ExtendScript for Framemaker?

Again thank you,

Vicki

Votes

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 Expert ,
Sep 17, 2024 Sep 17, 2024

Copy link to clipboard

Copied

Russ from www.weststreetconsulting.com has a bunch of free sample scripts. My YouTube channel has some ExtendScript stuff; just search YouTube for Rick Quatro.

Votes

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 17, 2024 Sep 17, 2024

Copy link to clipboard

Copied

Rick, No 'book' to learn from?  Like the Camel book for Perl.
How did you learn how to write scripts?

Thanks,

Vicki

Votes

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 17, 2024 Sep 17, 2024

Copy link to clipboard

Copied

Wonderful examples, & you have just loaded up a new script to watch on youtube.

Your script ran beautifully, btw.
Thank you,

Vicki

Votes

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 17, 2024 Sep 17, 2024

Copy link to clipboard

Copied

per new video, Set Table Row Formatting: https://www.youtube.com/watch?v=tU8vshrS2sA

 

How did you know to pick the 'outputclass ' attribute was the 1 you needed?

Where is the documentation for the attributes of an element?
No luck with a quick search.

Thank you,
Vicki

Votes

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 Expert ,
Sep 17, 2024 Sep 17, 2024

Copy link to clipboard

Copied

The original poster was using DITA so I picked the outputclass attribute, which DITA has as a general purpose attribute for tasks like these.. But the choice was somewhat arbitrary and I just wanted to give an example.

Votes

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 18, 2024 Sep 18, 2024

Copy link to clipboard

Copied

LATEST

Thank you for your reply 🙂  Vicki

Votes

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