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
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
...
Copy link to clipboard
Copied
Can you post the code? Or, give an overview of what the code is doing?
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);
}
Copy link to clipboard
Copied
It does find my document though.
Line 27.
Copy link to clipboard
Copied
Are you trying to do something after a document is opened?
Copy link to clipboard
Copied
Try describing the purpose of the script in plain language.
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
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;
}
}
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
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.
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
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
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
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.
Copy link to clipboard
Copied
Thank you for your reply 🙂 Vicki