Quantcast
Channel: Adobe Community : All Content - FrameMaker Scripting
Viewing all 888 articles
Browse latest View live

Enabling background color option in a condition/char tag using Framescript

$
0
0

Hello fellows,

 

AFAIK, Framescript v5.x does not support this option. Am I right?

 

Thank you!


Add paragraphs with text

$
0
0

Dear patient helpers,

I want to 'dump' the contents of an array into a series of paragraphs. Two problems appear in my script:

- inserting a TAB by \t inserts a NewLine

- items are not placed in succesive paragraphs but at the start of the flow - hence in reverse order and not in own paragraphs

t-write-array.png

// write array to multiple paragraphs  var items      = new Array ();  var nItems, pgf, textLoc, oDoc;  items = ["Århus", "Çedille", "Dandy"];  nItems = items.length;  oDoc = app.ActiveDoc;   pgf = oDoc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;  // get first pgf in flow  textLoc = new TextLoc (pgf, 0);   for (var i = 0; i < nItems; i += 1) {    insText = items[i];    oDoc.AddText (textLoc, insText + "\t" + insText); // \t insert a NL...    oDoc.NewSeriesObject(Constants.FO_Pgf, pgf);  // add a paragraph    pgf = oDoc.NextPgfInFlow;  }

Text to table?

$
0
0

Hi all

 

Is it possible to produce a script that creates a table from the currently selected text?

 

I can find plenty of discussion about going the other way (ie converting a table to text) but none about converting a text selection to a table. I've looked everywhere I can think of, including the Adobe FM Scripting Guide, but no joy, so I'm beginning to doubt it's even possible.

 

Apologies if the scarcity of info is because it's so laughably simple that everyone else has worked it out -- I'm still at the stage where I'm quite surprised to be able to create a table at all (using NewTable), never mind anything more sophisticated!

 

Any clues will be extremely gratefully received.

 

Many thanks

How to set relative path for the cross references?

$
0
0

Hi,

I'm using FDK.

I try to work with cross references and I have problem with path name <XRefSrcFile>. Every time when I set it using by F_ApiSetString, it's set as an absolute path and I need to set it as relative path.

Has anybody any idea how to solve it?

 

Kate

Open an RTF document

$
0
0

After a RTF has been processed by EndNote it is opened in FM and the paragraphs are handled.

It turns out that I do not need to set special Open parameters to specify the filter RTF (which is requested when opening manually). This is the central part of my script:

openParams = GetOpenDefaultParams();  openReturnParams =  new PropVals();   newDoc = Open (fileName, openParams, openReturnParams);   pgf = newDoc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;  // get first pgf in flow

All works fine - for me it's a mystery, but a welcome one!

See the whole test script and test-file at my DropBox.

file.execute() not working for bat file

$
0
0

Dear all,
The purpose of my function copyToWinClipboard (text) is to get a string directly into the Windows Clipboard. The purpose is to allow the user of my project just to paste into the open-dialog of the application EndNote. I’m not certain whether the FM clipboard (supported by the copy/cut/paste methods for Doc) really fills into the Windows Clipboard also.
In the PhotoShop script forum I found the idea how to do this.

#target framemaker
// note the blank in the path
copyToWinClipboard ("E:\\_DDDprojects\\FM+EN escript\\FM-11-testfiles\\BibFM-collected.rtf");

function copyToWinClipboard (text) {
  var theCmd, clipFile = new File(Folder.temp + "\\ClipBoardW.bat");  clipFile.open('w');
//  theCmd = "echo \"" + text + "\" | clip"; // this doesn’t help either  theCmd = "echo " + text + " | clip";  clipFile.writeln (theCmd);  clipFile.close ();  clipFile.execute ();
}

Running this script provides a short flicker (the command prompt), but the clipboard does not contain the expected string. However, when double clicking on the generated I:\!_temp\ClipBoardW.bat the clipboard is filled correctly.
IMHO the execute method does not work correctly for bat files. In another area of my project-script i run an exe file with this method correctly.

Copy to clipboard

$
0
0

I try to set up a script for this function - but do not get any useful results.

Obviously my understanding of TextRange is not complete...

CopyToClipboard ("E:\\_DDDprojects\\FM+EN escript\\FM-11-testfiles\\BibFM-collected.rtf");

function CopyToClipboard (theText) {
// - create a textframe with a paragraph on the first masterpage (which always exist)
  var masterPage, textFrame, pgf, textLoc, PT = 65536;   var oTRange = new TextRange, oTexts;  var doc = app.ActiveDoc;   masterPage = doc.FirstMasterPageInDoc;          // Get the first master page in the document.   textFrame = doc.NewTextFrame (masterPage.PageFrame); // Add a temporary text frame to the master page.    textFrame.Width  = 480 * PT;   pgf = textFrame.FirstPgf;   textLoc = new TextLoc (pgf, 0);   doc.AddText (textLoc, theText);                 // write the string into this paragraph  oTexts = pgf.GetText (Constants.FTI_String);    // select it  oTLoc1.obj = pgf;  oTLoc2.obj = pgf;  for ( i = 0; i < oTexts.length; i++ ) {    if (oTexts[i].dataType == Constants.FTI_String ) {      oTLoc1.offset = oTexts[i].offset;      oTLoc2.offset = oTexts[i].offset + oTexts[i].sdata.length;      oTRange.beg = oTLoc1;      oTRange.end = oTLoc2;      oDoc.TextSelection = oTRange;    }  }  doc.Copy (0);                                   // copy selection to clipboard not interactive
alert ("something to see?");  textFrame.Delete ();                            // delete the text frame
}

The text frame is placed either on the master page or the body page - depending on which i have switched to - strange.

The alert at the end shows that the text is placed, but my TextRange construct has no effect: the clipboard contains old stuff.

How to test for Cancel in ChooseFile

$
0
0

Dear all,

Again I'm stuck with some silly problem.

When I cancel the ChooseFile dialogue, I want to bail out of the function GetTheFile. However, I have not found the appropriate test for this.

The inputFile is reported to be null in the Cancel case:

var prompt = "Select the formatted Citation file";
GetTheFile ();

function GetTheFile () {
  var inputFile = ChooseFile (prompt, GetDocPath (), "*.rtf", Constants.FV_ChooseSelect);  if (inputFile == 0) {    alert  ("No input - no processing");    return;  }  alert ("Further processing of the inputfile = " + inputFile);
}

If I cancel, line 10 reports "Further processing of the inputfile = null".

Testing in line 6 for the string "null" does not help either.

The Scripting Guide says for this function:

«The method returns 0 if the user clicked Open, Select, Use, or Save; a nonzero value if the user clicked Cancel or an error occurred»

function GetDocPath () {
// ----------------------------------------------- Get the document/book path  var docFile, scrPath, lastBSlash;  if (app.ActiveBook.ObjectValid()) {    docFile = app.ActiveBook.Name;  } else {    docFile = app.ActiveDoc.Name;  }   lastBSlash = docFile.lastIndexOf("\\");        // \ needs escaping  scrPath = docFile.substring(0, lastBSlash);  return scrPath;                                 // no final \ !
} // --- end GetDocPath

Testing in line 6 for !== 0 catches the valid input-file names (of course). So what is a valid test for the Cancelled function?


updateXRef(srcDoc, xref) framemaker documentation issue

$
0
0

The documentation for updateXRef (Adobe FrameMaker 12 * UpdateXRef) appears incorrect; it references the various constants for updateXrefFlags, however I believe this applies only to updateXRefs and not updateXRef, and this section should be removed.

Missing graphics - how to skip in Open

$
0
0

In my test script to cope with the various open errors I have this definition for the OpenParms:

  i = GetPropIndex(params, Constants.FS_RefFileNotFound);  // Document imports another file that isn’t available.  params[i].propVal.ival = Constants.FV_AllowAllRefFilesUnFindable; 

When opening a book with files creating various errors, I get a dialog at the file which has missing graphics

«Cannot display some imported graphics. The image will appear as gray boxes»

Isn't this covered by the above OpenParm ?

The whole test with files is in my dropbox.

How to get formatted text into arrays

$
0
0

Dear experts and helpers,

For my project I import an RTF file and then read the data from it into 3 arrays. This works fine when just using the string contents of the paragraphs. However, the final script should be able to read and replace formatted text...
Why use the intermediate arrays? Because otherwise I need to switch back and forth between two fm-documents (and one may be a book component).

The imported file starts with a number of lines separated into two items by a TAB (» denotes a TAB, in FM \x08)
[[Garneau, 1990 #12]]    »   [9]
The right item may also be locally formatted text, e.g. [9]
Then follow the same (or smaller) number of paragraphs with formatted text like this:
[9] » D. Garneau, Ed., National Language Support Reference Manual (National language Information Design Guide. Toronto, CDN: IBM National Language Technical Centre, 1990.

 

Is it possible to replace in the body of the function below the following piece

  while(pgf.ObjectValid()) {    pgfText = GetText (pgf, newDoc);    gaBibliography.push(pgfText);    pgf = pgf.NextPgfInFlow;  }

with this

  while(pgf.ObjectValid()) {    gaBibliography.push(pgf);    pgf = pgf.NextPgfInFlow;  }

Do I need a special declaration of the array gaBibliography ?
And how to get the right part of the intro lines as formatted thingy into array gaFmtCitsFmt ?

 

Currently I read into arrays only the 'strings' (function GetText not shown):

var gaFmtCitsRaw  = [];                           // left column in processed RTF
var gaFmtCitsFmt  = [];                           // right column in processed RTF
var gaBibliography= [];                           // bibliography lines from processed RTF
// filename is something like E:\_DDDprojects\FM+EN-escript\FM-testfiles\BibFM-collected-IEEE.rtf

function ReadFileRTF (fileName) {
  var nCits=0, nBib = 0, openParams, openReturnParams, newDoc, pgf, pgfText ;  var TAB = String.fromCharCode(8);               // FM has wrong ASCI for TAB  var parts = [];   openParams = GetOpenDefaultParams();  openReturnParams =  new PropVals();   newDoc = Open (fileName, openParams, openReturnParams);   pgf = newDoc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;  // get first pgf in flow

// --- read the temp/formatted citations   while(pgf.ObjectValid()) {    pgfText = GetText (pgf, newDoc);    if (pgfText.substring (0,2) == "[[") {        // citation lines start with [[      parts = pgfText.split(TAB);                 // get the two parts of the line      gaFmtCitsRaw.push (parts[0]);               // Push the result onto the global array      gaFmtCitsFmt.push (parts[1]);      pgf = pgf.NextPgfInFlow;    } else { break }  }

// --- read the bibliography
  while(pgf.ObjectValid()) {                      // until end of doc    pgfText = GetText (pgf, newDoc);    gaBibliography.push(pgfText);    pgf = pgf.NextPgfInFlow;  }  newDoc.Close (Constants.FF_CLOSE_MODIFIED);
} // --- end ReadFileRTF

 

The next questions then will be how to modify Ian Proudfoot's FindAndReplace script to handle formatted text as replacement. IMHO i will need to use copy/paste ...

How to create a book folder component?

$
0
0

Hello,

 

I'm trying to create a book folder from a script. From what I understand the relevant methods are "NewSeriesObject" and "NewSeriesBookComponent"; they only take the object name. OK, so I create it and get what seems to be a file without a valid path. I then try to change the "ComponentType" property to "FV_BK_FOLDER", but cannot do it. If I try to change it directly, it just stays put; if I try to change it via "SetProps" the document simply disappears from the book.

 

The FDK has a sample of how to create a book component in C, but it creates a file, not a folder. Otherwise it seems to be as I described: first insert the component and then change it (the sample changes the name). The FDK reference doesn't describe the "ComponentType" property though.

 

Does anyone know how to create a folder?

 

Kind regards,

Mikhail

Trouble Setting the structured app on import - FS_StructuredImportApplication

$
0
0

Hello All,

 

I have some referenced documents that I refresh when opening the parent document and I am trying to set the structured application on import.

 

I am using>            

 

        var importParams = GetImportDefaultParams();

                    

                        i=GetPropIndex(importParams,Constants.FS_StructuredImportApplication);

                        importParams[i].propVal.ival= "myStructApp";

              

                        alert(importParams[i].propVal.ival);

 

I expect the alert to return "myStructApp" , which exists in the list of structured apps. However, my alert returns 0.

 

What am I doing wrong please?

 

 

thanks,

Tracey

 

[Thread moved to Scripting Forum by moderator]

Losing table rulings when setting cell.CellUseOverrideShading = true; How do I keep existing table rulings?

$
0
0

Hi All,

 

I am applying a custom shading to a cell, according to an attribute setting, however after the custom shading is applied,  I lose the table rulings that were present. How do I tell it in code to keep existing rulings?

 

cell.CellUseOverrideShading = true ;

                cell.CellUseOverrideFill = true ;

                cell.CellOverrideFill = 0 ; // change the table

                var colorObj = doc.GetNamedColor("MYshading");

                cell.CellOverrideShading = colorObj;

 

 

thanks,

Tracey

ImportExport Show/Hide settings?

$
0
0

Hello,

 

I have just tested the ImportExportVariables which is going to be very usefull for large books where we want to make a selective import of the variables (on a given file of the book, only import the variables that are useful for this particular file).

 

I would like to do the same thing for the condition tags Show/hide settings. Be able to import only the Condition Tags (and their show/hide settings) that are usefull for a particular file of a book instead of propagating all the condition tags to all the files.

 

Is there a Extend script for that or could you give indications for modifying the ImportExport variable to make it support condition tags as well?

 

Cheers,

 

Bruno

 

[Thread moved to scripting section by moderator]


Changing condition properties via ES

$
0
0

Hello fellows,

 

I am trying to change properties of a certain condition tag through extendscript.

For example, I'd like add a background color to the condition tag. So I came up with this faulty code:


The ES toolkit complains that UseBkColor and BkColor are "undefined", but according to the FM10 Object Reference, these are properties of CondFmt. What am I missing?  Thank you for your inputs in advance!


#target framemaker

 

CondApplBcolor(doc, TestCond);

 

function CondApplBcolor (doc, TestCond)

{

var doc = app.ActiveDoc;

var TestCond = doc.GetNamedCondFmt(Insert);

 

if (TestCond.ObjectValid())

{

   Props = TestCond.GetProps();

   Bcolor_en = GetPropIndex(Props, UseBkColor);

   Bcolor = GetPropIndex(Props, BkColor);

   Props[Bcolor_en].propVal.ival = 1;

   Props[Bcolor].propVal.sval ="Pale Green";

   TestCond.SetProps (Props);

   return(1);

}

 

}



framescript: write to text file

$
0
0

Hello fellows,

 

When I loop through a list of book files and write their names to the FM console, the full list is displayed. However, when I write the list to a text file, only the 1st file name is written. Any ideas why?

 

Loop ForEach(BookComponent) In(vCurrentBook) LoopVar(v_File)

...

Write Console v_File;

 

vs.:

 

Set vPath = v_UserPath+DIRSEP+'_'+'Test'+'.txt';

 

New TextFile File(vPath) NewVar(vFile_Listing);

 

Write Object(vFile_Listing) v_File;

 

EndLoop

 

 

Thank you for your input in advance!

Roman

Saving a review PDF

$
0
0

Hi all,

 

I'm just getting into Extendscript for FM 12 so bear with me.

I have found the FM_Outputs_CondText file which does everything I need it to do except for I want the file to be saved as a review PDF. I've found the FCodes.KBD_SAVEASPDFREVIEW command and can get it to open the saveas dialog. However, I cannot for the life of me figure out how to interact with this. Any thoughts on how I can achieve the following process:

 

1: Apply conditional text show/hide (included in FM_Outputs_CondText)

2: Change output file name (depends on how I achieve step 3)

3: Save as review pdf

4: Move to next conditional text show/hide (included in FM_Outputs_CondText)

 

Any suggestions of what to do or where to look would be amazing.

(any FM scripter/user groups in Portland, OR?)

---Corey---

Create a QR code in extendscript?

$
0
0

Hello fellow FrameMaker Scripters,

 

I was just wondering if anybody knew a way to use Extendscript to create QR codes in FM. I'm creating several thousand files and would like to be able to tag each output with a QR code so a person in the field can simply scan it to pull up the PDF file. Unfortunately this would mean individually creating and saving thousands of QR codes. If I could automate the generation of QR codes mid-export I could do the tagging automatically and all would be right with the world.

 

Any thoughts or suggestions on where to look?

 

---Corey---

Text nodes in a structured FrameMaker file

$
0
0

Hello Scripters,

 

I have a recursive function that touches every element in a structured FrameMaker file. I am trying to find out how to get text nodes as I process the elements.

 

#target framemaker

var doc = app.ActiveDoc;
var element = doc.MainFlowInDoc.HighestLevelElement;

processElements (element);

function processElements (element) {
       if (element.ElementDef.ObjectValid()) {        $.writeln (element.ElementDef.Name);    }    else {        // I thought I could get text nodes here, but it never gets here.    }    var element2 = element.FirstChildElement;    while(element2.ObjectValid()) {        processElements (element2);        element2 = element2.NextSiblingElement;    }
}

 

I expected that I would get the text nodes on line 14, but it the else statement never gets there. In FrameScript, if an element has no ElementDef, then it is a text node. I am not sure about the FDK. Any ideas how I can pick up the text nodes in a function like this? Thanks.

 

-Rick

Viewing all 888 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>