Skip to main content
Known Participant
October 30, 2019
Answered

Extendscript - How to make a specific document active?

  • October 30, 2019
  • 1 reply
  • 2085 views

I am actually looking to modify a set of open FM files,. However, my script works fine only for the active document. I am unable to apply my script to other open documents. So, how to activate a document in extendscript? Please help me. 

This topic has been closed for replies.
Correct answer frameexpert

If the documents are already open, you can loop through them and get the Doc object for each one. Something like this:

var doc;

doc = app.FirstOpenDoc;
while (doc.ObjectValid () === 1) {

    // Call a function, passing in doc as the Doc to process.

    doc = doc.NextOpenDocInSession;

}

1 reply

frameexpert
Community Expert
frameexpertCommunity ExpertCorrect answer
Community Expert
October 30, 2019

If the documents are already open, you can loop through them and get the Doc object for each one. Something like this:

var doc;

doc = app.FirstOpenDoc;
while (doc.ObjectValid () === 1) {

    // Call a function, passing in doc as the Doc to process.

    doc = doc.NextOpenDocInSession;

}

Known Participant
October 30, 2019

Actually that was the way I had tried. But the formatting is not happening in the docs: I have shared the code below: Could you please help me?

 

var i=0;
var ind=getFontIndex ("Calibri");
var ptag, ptagFormat, ptagFormatName, ptagsSize;
var newpara, oldpara;
var ctags =[];
var ptags =[];
var ctag, ctagFormat, ctagFormatName, ctagsSize;
var newchar, oldchar;
var dc=app.FirstOpenDoc;

while(dc.ObjectValid())
{

changePgFormat(dc);
changeChFormat (dc);
dc=dc.NextOpenDocInSession;
}

function changePgFormat(DocName)
{
ptagFormat= DocName.FirstPgfFmtInDoc ;

while (ptagFormat.ObjectValid() == true)
{
ptagFormatName = ptagFormat.Name;
// alert(ptagFormatName);

ptags.push(ptagFormatName);
ptagFormat=ptagFormat.NextPgfFmtInDoc;
}
ptagsSize = ptags.length;
//alert ("Number of formats in array before processing: " +ptagsSize);

for(i=0; i<ptagsSize; i++)
{
ptagFormatName = ptags[i];
newpara = doc.GetNamedPgfFmt (ptagFormatName);
newpara.FontFamily=130;
}

for(i=0; i<ptagsSize; i++)
{
ptags.pop();
}
ptagsSize = ptags.length;
//alert ("Number of formats in array after processing: " +ptagsSize);
}


function changeChFormat(DocName)
{
ctagFormat= DocName.FirstCharFmtInDoc;
while (ctagFormat.ObjectValid() == true)
{
ctagFormatName = ctagFormat.Name;
ctags.push(ctagFormatName);
ctagFormat=ctagFormat.NextCharFmtInDoc;
}
ctagsSize = ctags.length;

for(i=0; i<ctagsSize; i++)
{
ctagFormatName = ctags[i];

if(ctagFormatName!="Symbol"){
newchar= doc.GetNamedCharFmt (ctagFormatName);

newchar.FontFamily=ind;

}
}

for(i=0; i<ctagsSize; i++)
{
ctags.pop();
}

}

function getFontIndex(fontName)
{
var fname=app.FontFamilyNames;
var fLen = fname.length;
for (i=0; i<fLen; i++)
{
if(fname[i]== fontName)
{
return i;
}
}
}

 

 

 

frameexpert
Community Expert
Community Expert
October 30, 2019

How do you know that the change is not being made?