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

$.stack is not a string

$
0
0

ESTK and FDK documentation and even typeof claims that $.stack is a string. If it is printed with $.writeline it behaves as such and creates multiple lines.
I want to build a function which can be called in any routine and will then indicate the calling level by indentation and the name of the function.
For that puprose I wanted to split the 'string' into an array, the length of which indicating the nesting level of the function in question.
But it turns out that $.stack can not be handled as a string:

 

function ZTrace () {
// $.stack is not a string - what is it?
var level, aStack = [], s1Stack, s2Stack;  s1Stack = toHex($.stack);  $.writeln (s1Stack);                    // see what it looks like      s2Stack = $.stack.toString();           // sStack behaves as stack  aStack = s2Stack.split (hex2a("829a")); // does not split  level = aStack.length;                  // always 1  $.writeln (aStack[0]);                  // always full stack  $.writeln (aStack[1]);                  // undefined
} // --- end ZTrace

function toHex(str) {
    var hex = '';    for(var i=0;i<str.length;i++) {        hex += ''+str.charCodeAt(i).toString(16);    }    return hex;
}
function hex2a(hexx) {
// http://stackoverflow.com/questions/3745666/how-to-convert-from-hex-to-ascii-in-javascript
// hex2a('32343630'); // returns '2460'    var hex = hexx.toString();//force conversion    var str = '';    for (var i = 0; i < hex.length; i += 2)        str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));    return str;
}

 

For example, in a nested function calling ZTrace () will create a stack like this

 

[ZTrace-test.jsx]
Level_0()
Level_1()
Level_2()
Level_3()
ZTrace()

 

But the line 05 creates (here both in hex and interpreted):

 

5b5a54726163652e6a73785da4c6576656c5f302829a4c6576656c5f312829a4c6576656c5f322829a4c6576656c5f332829a5a54726163652829a
[ Z T r a c e . j s x ] ¤ Æ W f u Å ó ??????L e v e l _ 1 ( ) ¤ Æ W f V Å ó ??????L e v e l _ 3 ( ) ¥ ¥ G ????6 R ????


Now, of what type is $.stack?


Trapping "white document window"

$
0
0

Dear fiends,

You know, the last 10% are the most cumbersome ones...

With my script I get a "white document window" after opening of document files. I can not reproduce the behaviour reliably neither within FM (with menu) nor with ESTK (invoking only one function without menu). Even if the white screen appears, ESTK does not show a halt or error.

Painstaikenly repeating the actions (after a double FM-restart - see later why double) the effect may happen or not:

------------------------------------------------------------------------ ESTK, different sequence of files
Open FM
Open Simple Text
Start Script for work with Dialog C    Refresh ... script works correctly
Open Markers and tables    => white screen    Working on the markers possible (but I don't see what)    CTRL-l does not do anything    Running SetDisplay from ESTK does not change the situation    Where are we stuck?    Closing panel    Closing FM is time consuming
------------------------------------------------------------------------ ESTK, different sequence of files
Open FM
Open Markers and Tables
Start Script for work with Dialog C    Refresh ... script works correctly
Open Simple Text    Marke contents is default    Check syntax operates on marker of prev. document! (known problem)
Open Developer log    Refresh ... script works correctly
Switching documents etc all works
Open From-scratch-CS-markers    => White screen    There seems to be one C marker in there    Closing panel    Closing FM is time consuming

 

How to catch the reason for these white screens?

I can work on the document, but don't see the results...

 

Closing FM after appearance of "white document window":

Method one:

For each open document:

  • Click on X to close document, wait (15 sec) until dialog "save yes/no") appears
  • Document is visible
  • Click either Yes or No and wait again (about 5 sec)
  • Document is closed, nex one is white

Close FM with X

Nothing happens for at least 20 sec, so I click into the window which becomes white.

Click on X again => "Adobe FrameMaker is not responding"

OK => Cancel => FM disappears.

Method two:

Close FM with X and wait until the dialog "Select the files to save before closing" appears (30 sec)

OK => wait at least 10 sec, then the dialog closes

FM is still open und hence i click on X

=> "Adobe FrameMaker is not responding"OK => Cancel => FM disappears.

Why restart FM a second time before next test?

If I use the script just after a restart of FM (after the white screen happening), I get "Window can not be created" errors). Hence I need a second restart of FM. Then the script can be started again.

FDK 2017 linker error

$
0
0

Hi

I have installed the 2017 FDK to compile a previous project. I think I have set all the options correctly but when trying to build I get some errors related to the linker. This is the first one:

 

error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1800' in fdk.lib(fde_netlib.obj)

 

From what I have investigated it appears that the fdk.lib was compiled with VS2012, in the FDK requirements it says to use VS2010 like I have done with previous releases, but in this case I think the FDK libs should be compiled with 2010 also. Please let me know if this is the case or if I can try something else.

 

Thanks

Is it possible to create a text file from scratch?

$
0
0

I'm using a text file to keep a number that is used in controlled documents.

For example file contents can be: 17-154. So when we need to create a new controlled document it will be 17-155 and so forth.

All that works fine, but:

 

- What if the text file does not exist?

 

I would like to create a text file from scratch and write '17-001' to it...

 

Any ideas?

Thanks guys.

Unable to create Window

$
0
0

Dear friends and experts,
Until now I always had at least one document open before I started my script. Now I first started the script (File > Scripts > Catalog > scriptname > Run) just after FM start. The effect described also happened in the past during debugging and I attributed it to forgetting to unregister etc. But now I just 'work' with the script.
The following happens randomly after having open one or more documents.
As soon as I want to open a panel (via shortcut or from the menu) the script reports

Error Message      : Unable to create Window
Script, Line#   : E:\_DDDprojects\FM-calc\FMcalc\FMcalc_dialogC.jsx,  14


The referenced script line is this or similar:

  wPalC  = new Window("palette", goTxt.wPalC, undefined);


Each test is a separate start of FM, then starting the script, then opening the first document.
Test 1:  One document open; error after first invocation of panel
Test 2:  5 documents open; after each open invocation of panel OK
Test 3:  One document open; error after first invocation of panel
Test 4:  One document open; error after first invocation of panel
Test 5:  Open FM and just leave it. This requires at the next start to search for the script.
Test 6:  4 documents open; after each open invocation of panel OK

 

What I have found so far on this problem is of little help: www.hivmr.com, www.deskdr.com

The only reasonable information is given here: simplephotoshop.com/elementsplus/
«Unfortunately, this is a bug in Adobe's script engine known to users of PSE and Photoshop and the total remedy hasn't been found yet. As a rule, this problem resolves itself after several computer re-boots. However, if in your case the problem persists, the author can suggest the only solution - using the action based version of "Elements+" »

 

This reflects my experience of randomness.
Any other ideas how to cure the problem?

Trying to understand element selection limitations

$
0
0

I have created an ExtendScript which is used to install structured application definitions the first time that a script is run. Here's what it does:

  1. Opens a copy of a structapps.fm file that contains the required XML application definitions.
  2. Creates a backup of the local structapps file.
  3. Opens the local structapps file.
  4. Delete any XML applications with names that match the new XML apps.
  5. Copies the new XML apps into the local structapps file.
  6. Reads the structapps file using fmDispatcher, saves and closes the files.

 

This all works very well up to a point. Where I have a problem is with the insertion point for the copied XML applications. I want to insert them directly after the <Version> element.

I can do that when there are other following <XMLApplication> elements. However if there are no following elements it inserts the copied elements before the <Version> element which is invalid. Here's the code:

function copyXApps(localStrappDoc, sourceStrappDoc)
{    var copyApps, ser = new ElementRange(), ter = new ElementRange(), copyApps, target,    sourceElem = sourceStrappDoc.MainFlowInDoc.HighestLevelElement.FirstChildElement.NextSiblingElement;    target = localStrappDoc.MainFlowInDoc.HighestLevelElement.FirstChildElement.NextSiblingElement;       if(sourceElem === null || sourceElem.ObjectValid() === false) return;           ser.beg.parent = ser.end.parent = sourceElem.ParentElement;        ser.beg.child = sourceElem;        ser.end.child = sourceElem.ParentElement.LastChildElement;               ser.end.parent = sourceElem.ParentElement;        ser.beg.offset = 0;        ser.end.offset = 0;           //Set the document element selection.    sourceStrappDoc.ElementSelection = ser;    copyApps = sourceStrappDoc.Copy (0);       if (copyApps === Constants.FE_Success){        ter.beg.parent = ter.end.parent = target.ParentElement;        ter.beg.child = ter.end.child = target;        ter.beg.offset = ter.end.offset = 0;               //Set insertion point for copied Xapps, then paste:        localStrappDoc.ElementSelection = ter;        pasteApps = localStrappDoc.Paste (0);        return pasteApps;       }    }

 

There's also a problem with the selection code which selects all apps except the last one despite using LastChildElement. I seem to be misunderstanding something here.

Thanks for any help.

Ian

​How can I save all the files of a book at one go

$
0
0

Hi,

How can I save all the files of a book at one go rather than Shift+Control, with the help of any extended script or so?.

It would be of great help if there is really an option to save all the files at 1 shot.

Importing graphic into graphics frame on a Reference page

$
0
0

Hello All,

Need to import a graphic (by copy) into a graphics frame located on a Reference page of the document. The objective is to have a number for each chapter on the First Master Page. This is done by using 'Frame Above Pgf' of the Paragraph Tag. This works fine manually, as shown below. I would like to have a generic chapter FM file where I can change the chapter number according to the value of <$chapnum>.

Is there a way to import the graphic (number) into the graphics frame? I see Import, but it requires a TextLoc that I don't have.

Any help is greatly appreciated.

 

 

#target framemaker


var oDoc, oPage, oFrame, oGfx;


var oDoc = app.ActiveDoc;


if (oDoc.ObjectValid()){
    //    oPage = oDoc.FirstRefPageInDoc;    while (oPage.ObjectValid()) {        alert(oPage.Name);        oFrame = oPage.PageFrame;        if(oPage.Name == 'Reference Page 2'){            oGfx = oFrame.FirstGraphicInFrame;            if(oGfx.ObjectValid()){                while (oGfx.ObjectValid()){                    if (oGfx.constructor.name == 'UnanchoredFrame'){                    alert(oGfx.Name);                    }                oGfx = oGfx.NextGraphicInFrame;                }           }        }        oPage = oPage.PageNext;    }
}

Drag document in book structure

$
0
0

Hi.

I try to create function for remove documents in structure view and have problem. When I create funciton, were I want to stop dragging document in structure view by using F_ApiReturnValue(FR_CancelOperation); I stoped the drag action, but document in my book list disappear. This document shows only when FM is reopened.

I have already tried redisplay for book, deselect element range, but it doesn't help.

Are there any other options?

 

Thanks.

Running ExtendScripts on FM and MIF Files.

$
0
0

Hi,

 

I was trying to run a script to extract all Paragraphs in a fm file with a specific tag name and I could see that I did not extract texts for many paragraphs.

 

However when I saved the fm file as a mif file, and on running my script hereafter I was able to extract all paragraphs including paragraphs that were hidden.

 

Please let me know why is there such a difference between running on a FM file and a MIF File.

Secondly, If i were to update the MIF files with new paragraphs (and text ), could I save it as an FM file and use it interchangably.

 

Thanks,

Sebin

(Attaching my Script)

 

    var doc = app.ActiveDoc;

    var pgf= doc.FirstPgfInDoc;

    var count = 0 ;

    while (pgf.ObjectValid()){

 

        if (pgf.Name == 'Specific_Par_Name')

        {  

             count += 1;

             var test = pgf.GetText(Constants.FTI_String ); 

             var text, str;

             text = "";

             //$.writeln(test);

             for (var i=0; i < test.len ; i +=1)

             {

                 var str=test[i] .sdata.replace(/^\s+|\s+$/g, '') ;

                 //var str=test[i] .sdata;

                  text = text + str;

                  //PrintTextItem (test[i]);

             }   

       

         //  file.writeln(text);

         }

 

 

       // $.writeln(paraname);

        pgf=pgf.NextPgfInDoc;

 

 

}

$.writeln(count);

//file.close();

How could I add Existing Variables into a Paragraph using ExtendScripts?

$
0
0

Hi,

 

Based on a specific paragraph tag, I would like to add an existing variable (Name and Fmt) as part of the paragraph's text. I am able to add strings as part of paragraph texts at the moment.

 

I was looking up extend scripts to do this, however I am quite not sure how to add a variable. I could only find instances of updating variable values and so on.

 

Any help would be appreciated.

 

Giving a brief overview of my intention: (For example; Variable = "Part Number: 0x404"

 

                            var newpgf = doc.NewSeriesObject(Constants.FO_Pgf, pgf);

                            var attribute= doc.GetNamedObject(Constants.FO_VarFmt, "Variable");

           

                            var textLoc = new TextLoc();

                            textLoc.obj = newpgf;

                            textLoc.offset = -1;

 

 

                         

                                                               doc.AddText(textLoc, "( ");

                                                                         

Something like this:                            -> doc.AddText(textLoc, attribute.Fmt);       // Not Sure how to do this, possibly link the variable text range to this Text Location?

                                                               doc.AddText(textLoc, " )");               

 

Expected Paragraph:

                                             <Previous Para>

          new Para:                    (Part Number: 0x404 )

 

 

 

Thanks,
Sebin

Gotopage and RoundRectangle

$
0
0

Hello,

 

I'm trying to create a script that go to the Right Master Page used in my document and create a round rectangle (at pos x, y and size h,w).

But i can't go to the right page. (I'm already in the Master Page View, using Fcodes)

 

I'm using :

Fcodes([app.GetNamedCommand("GotoPage").Fcode]);

I have the GotoPage dialog box, but how can i force it to got to the page named : RightMasterPageEnglish intead having the dialog box?

 

I'm trying with RoundRectanble too, but how to define the x,y,h and w parameters to past with the fcodes ?

Framemaker 12 and Framemaker 15 get stuck after one complete traversal of all Paragraphs in the doc

$
0
0

Hi,

 

I noticed that after one traversal of all paragraphs as given by function 1, framemaker gets stuck and maybe due to that I am unable to execute the while loop in the second function. ($.writeln("CHECK2"); doesn;t get executed)

 

Please let me know if I am missing out on closing some dangling variables etc. I have attached the code as well.

 

Thanks,

Sebin

 

var doc = app.ActiveDoc;

doc.ShowCondIndicators =1;

    var txtFile = "C:/gen_seb.txt";

    var file = new File(txtFile);

    file.open("w"); // open file with write access

    var hash = generate_list(doc);

    find_defined_list_attributes(doc);

    file.close();

function generate_list(doc)

{

 

 

    var list = {};

    var pgf= doc.FirstPgfInDoc;

    var cndfmt = doc.FirstCondFmtInDoc;

    var count = 0 ;

    //doc.CondFmtIsShown = 1;

    doc.ShowAll = 0;

   

    while (pgf.ObjectValid()){

             var test = pgf.GetText(Constants.FTI_String); 

             var text, str;

             text = "";

             for (var i=0; i < test.len ; i +=1)

             {

                

                 var str=test[i] .sdata.replace(/^\s+|\s+$/g, '') ;

                  text = text + str;

             } 

        if (pgf.Name == 'Name_1')

        {                      

                            var tr = new TextRange (); 

                            tr.beg.obj = tr.end.obj = pgf; 

                            tr.beg.offset = 0; 

                            tr.end.offset = Constants.FV_OBJ_END_OFFSET;                         

 

 

                                var props = doc.GetTextPropVal(tr.beg,Constants.FP_InCond);

 

 

                                if(props.propVal.isval.length >0)

                                {

                                   var cnt = 0;

                                   var con_shown = 0;

                                   var propLength= props.propVal.isval.length;

 

 

                                   while(cnt<propLength)

                                   {  

                                      if((props.propVal.osval[cnt].CondFmtIsShown))

                                        {

 

 

                                            con_shown = 1;

                                            break;

                                        }

                                        else

                                            cnt++;

                                    }

                                       if(con_shown == 1)

                                       {

                                            file.writeln(text);

                                            var regexp = /\(\S+\)/gi;

                                            var regmatch = text.match(regexp);

                                            regmatch=String(regmatch);

                                            regmatch= regmatch.replace(/\(|\)/g, '');

                                                                                      

                                            list[regmatch] = [0,0];

                                       }

                                }

               

        }  

 

 

          pgf=pgf.NextPgfInDoc;   

         

}

return reg_list;

}

function find_defined_list_attributes(doc)

{   $.writeln("CHECK1");

    var pgf= doc.FirstPgfInDoc;   

    while (pgf.ObjectValid())

        { $.writeln("CHECK2");

 

 

 

 

            pgf=pgf.NextPgfInDoc;

        }

   

}

Get Attribute Value from Structured Book

$
0
0

Hello,

 

In a Structured book, i need to get on attribute valus (on the highest element) but ...

 

In a FM document, i can get value from an element by looping through all my document by "wraping" the element text and get the attributes (using : element.TextRange.beg/end).

 

But in a structured book, i can't wrap the "element text" because it's not text, so how can i get the value of my highest element?

Accessing the "Read Application Definitions" function from the StructureTools menu

$
0
0

Using extendscript or framescript, is there a way to access the "Read Application Definitions" to read an opened structure file? I'm using Structured Framemaker 11, and I need to update an application definition file to shift between a portrait and landscape layouts.

 

The keyboard shortcut is alt-r, shift-R if I can just call it from a keyboard shortcut.

 

Thanks for any help you can give me!

 

Rick


FrameMaker 2015 - ESTK - Page Size DefaultParams

$
0
0

Hi everybody,

 

I'm struggling with the page sizes when creating a PDF file from a book. I can't manage to change the sizes of the pages to DIN A4. The default parameters seems to be 210,3 x 279,4 mm.

 

The same issue has been discussed for FDK, but I don't get how to adapt the code:

Framemaker 2015 - FDK Client application page size issue

 

Here is the function I use to save PDF with the attempt to alter the page height to 297mm:

I'm glad for any help.

function SaveAsPDF(book) {    var comp = book.FirstComponentInBook;    while(comp.ObjectValid()) {        var doc = SimpleOpen(comp.Name);        doc.PDFBookmark = true;        doc.DocAcrobatElements = false;        doc.PDFPageHeight = 297; // here is my attempt        comp = comp.NextBookComponentInDFSOrder;        }       var params = GetSaveDefaultParams();    var index = GetPropIndex(params, Constants.FS_FileType);    params[index].propVal.ival = Constants.FV_SaveFmtPdf;    book.Save(pdfPath, params, new PropVals());
 }

Framescript: Displaying set to 1 but the file is not displayed

$
0
0

Hello fellows,

 

Before I run a certain part of my script, set Displaying to 0.

When done, I return Displaying to 1. The script has finished running (I can scroll through the open file, switch between files) but the file is not displayed (sort of blank page). Only when I try to close the file, its contents appears on the screen.

 

Any idea what could be the cause of this problem?

 

Thank you in advance!

transform text value in object

$
0
0

Hi everyone !

 

Here is a trickie one : I made a script to get the keys property by property in a layer. If I enter a full property name by hand like this

 

myProp = app.project.item(55).layer("titre").property("Transform").property("Position");
alert(myProp.numKeys);

 

It gives me the number of keys on my property... But, if I get the exact same property path by another way (text file, script...) it doesn't work anymore.

 

myProp = myTextFileDataArray; //the exact property path is entered in the text file
alert(myProp[0].numKeys);

 

Returns "undefined".

My program has to scan all the layers and properties in a comp, so I need to have a myProp value dynamically.

 

Hope my ask is clear :/

FrameMaker unresponsive after running script, 'ENGINE BUSY'

$
0
0

Hello scripters!

 

I've recently run into a small problem and I'm wondering if anyone has experienced the same and/or could shed any light on the issue. I have a script which, when run on large (~250 page) documents, renders FM completely unresponsive and requires me to force quit the application. The script isn't anything fancy, it simply walks through the active doc and inserts index markers into specific paragraphs. These are the important bits:

 

// adds index markers to doc

function addIndexMarkers(doc, pgf)

{

    // walk through pgfs in the main doc flow

    while (pgf.ObjectValid()) {

        var pgfFmt = pgf.Name;

 

        if (pgfFmt == "thing1" || pgfFmt == "thing2") {

            var offset = getOffset(pgf);

            var text = getText(pgf);

            createMarker(doc, pgf, offset, "Index", text);

        }

        pgf = pgf.NextPgfInFlow;

    }

}

 

// returns the offset to first char in the provided pgf

// will return different values for structured and

// unstructured documents

function getOffset(pgf) {

    return pgf.GetText(Constants.FTI_String)[0].offset;

}

 

// returns the textual data of the provided pgf

function getText(pgf)

{

    var textItems;

    var text = "";

    textItems = pgf.GetText(Constants.FTI_String);

 

    for (var i = 0; i < textItems.length; i++) {

        if (textItems[i].dataType == Constants.FTI_String) {

            text += textItems[i].sdata;

        }

    }

 

    return text;

}

 

// creates an index marker and places it at the specified

// offset position within the given pgf

function createMarker(doc, pgf, offset, type, text)

{

    var textLocation = new TextLoc(pgf, offset);

    var marker = doc.NewAnchoredObject(Constants.FO_Marker, textLocation);

    var markerType = doc.GetNamedObject(Constants.FO_MarkerType, type);

    marker.MarkerTypeId = markerType;

    marker.MarkerText = text;

}

 

The script makes it all the way to the end, I see my "Script Complete" message then ESTK just keeps spinning and FrameMaker becomes unresponsive. If I stop the script and try to restart it, I get 'ENGINE BUSY'. Again, this only happens on large documents (both structured and unstructured). I tried with ~100 page docs and it works just dandy.

 

Any ideas on why this might be happening?

Framescript: Check for unresolved xrefs in a doc without loop

$
0
0

Hello fellows,

 

Is there a way to check whether a doc contains unresolved xrefs without the need to loop through each and every xref and check its status?

 

What I'd like to do is to state "if there are no broken xrefs in doc, <do xyz>" or "if all xrefs are alive, <do xyz>". :-)

 

Thank you in advance!

Viewing all 888 articles
Browse latest View live


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