Skip to main content
Known Participant
Oct 30, 2019 1:59 PM UTC
Answered

Extendscript - How to make a specific document active?

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 is closed to new replies. Start a new post to keep the conversation going.
frameexpert
frameexpertCorrect answer
Community Expert
Oct 30, 2019 2:18 PM UTC

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;

}

www.frameexpert.com

7 replies

frameexpert
Community Expert
frameexpertCommunity ExpertCorrect answer
Community Expert
Oct 30, 2019 2:18 PM UTC

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;

}

Translate
www.frameexpert.com
Known Participant
Oct 30, 2019 2:30 PM UTC

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;
}
}
}

 

 

 

Translate
frameexpert
Community Expert
Community Expert
Oct 30, 2019 2:34 PM UTC

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

Translate
www.frameexpert.com