Copy link to clipboard
Copied
Hi, I am new to Extendscript and Framemaker. I am trying to cycle through a book and find which paragraphs are/contain anchored frames. If they contain an anchored frame, I want to be able to select the paragraph and apply/remove conditional tags on the paragraph.
This is what I have so far:
//code to Show All conditions including hidden ones in book.
//take the object of the active book
var openedBook = app.ActiveBook;
//function call - defiend below
openBookFiles(openedBook);
function openBookFiles(openedBook)
{
var bookChapter = openedBook.FirstComponentInBook;
var counter = 0;
if(bookChapter.ObjectValid())
{
var chapterId = bookChapter.id;
while (chapterId)
{
var chapterName = bookChapter.Name;
chapterId = openFile(chapterName);
var msg = "Opened Chapter " + chapterName + "Component #"+ counter + "\n\n";
alert(msg);
counter++;
bookChapter.ComponentIsSelected = true;
chapterId.ShowAll = 1;
bookChapter = bookChapter.NextComponentInBook;
chapterId = bookChapter.id;
}
}
//code to find all paragraphs in book, check to see if they are/contain anchored frames or not.
var mainflow = doc.MainFlowInDoc;
var tframe = mainflow.FirstTextFrameInFlow;
var pgf = tframe.FirstPgf;
while (pgf.ObjectValid())
{
//find out if the paragraph is/contains an anchored frame
//if it does, deslect/select a condition tag applied on the paragraph.
pgf = pgf.NextPgfInFlow;
}
}
I like to isolate tasks into functions:
function hasAnchoredFrame(textObj) {
var textList;
textList = textObj.GetText (Constants.FTI_FrameAnchor);
if (textList.length) {
return true;
}
else {
return false;
}
}
Then you can call this in your code:
if (hasAnchoredFrame (pgf) === true) {
// Do something with the paragraph.
}
Try to get in the habit of isolating tasks into functions and then assembling them into finished scripts. This facilitates testing, troubleshooting
...Copy link to clipboard
Copied
I like to isolate tasks into functions:
function hasAnchoredFrame(textObj) {
var textList;
textList = textObj.GetText (Constants.FTI_FrameAnchor);
if (textList.length) {
return true;
}
else {
return false;
}
}
Then you can call this in your code:
if (hasAnchoredFrame (pgf) === true) {
// Do something with the paragraph.
}
Try to get in the habit of isolating tasks into functions and then assembling them into finished scripts. This facilitates testing, troubleshooting, and reuse. When you string all of your code together linearly, it causes problems with maintenance and scaling.
-Rick