Skip to main content
Klaus Göbel
Legend
November 1, 2021
Answered

[ExtendScript ] Creating a MiniTOC failed

  • November 1, 2021
  • 3 replies
  • 690 views

I'm trying to create a MiniTOC, but I failed with this code:

 

var goDoc = app.ActiveDoc;
var gaMiniTocPgfFmts = ["Title1","Title2"];
    
var oTextRange = goDoc.TextSelection;
var oMTOCPgf = oTextRange.beg.obj
   
var oCursor = new TextLoc(oMTOCPgf,0);
var oMiniToc = goDoc.NewInlineComponentOfType(Constants.FV_MiniTOC,gaMiniTocPgfFmts,Constants.FP_InsertLinks,oCursor);

FA_errno always is -1

I did it manually with the same unstructured document and was successful.

 

Has anyone managed to do that?

 

The documentation is very poor or non-existent.

This topic has been closed for replies.
Correct answer frameexpert

Hi Klaus,

You have to use a Strings object instead of an Array. Try this for your second line:

var gaMiniTocPgfFmts = new Strings ("Title1","Title2");

Rick

3 replies

Klaus Göbel
Legend
November 3, 2021

Hi Russ,

many thanks for your effort.

I've created a bug report in the prereleas forum.

I will keep you up to date.

 

frameexpert
Community Expert
frameexpertCommunity ExpertCorrect answer
Community Expert
November 3, 2021

Hi Klaus,

You have to use a Strings object instead of an Array. Try this for your second line:

var gaMiniTocPgfFmts = new Strings ("Title1","Title2");

Rick

Klaus Göbel
Legend
November 3, 2021

Hi Rick,

you saved my life

thanks a lot !!!!!!!!!!

That works - GREAT.

Legend
November 3, 2021

Hi Klaus, I played around with it but I was also unsuccessful. But, I tried with the FDK (2020) and it worked. I noticed this in fapi.h:

 

extern F_ObjHandleT F_ApiNewInlineComponentOfType FARGS((F_ObjHandleT docId, IntT inlineCompType, const F_StringsT *tags, BoolT hyperLinks, const F_TextLocT *textLocp));

 

So I tried this (some custom functions there, but you can get the idea):

 

  F_ObjHandleT docId;
  F_TextRangeT tr;
  F_StringsT tempStrings;

  docId = ad(0);
  tr = F_ApiGetTextRange(FV_SessionId, docId, FP_TextSelection);

  ws_StrsInit(&tempStrings, 0, False);
  ws_StrsAppend(&tempStrings, "Heading1");
  ws_StrsAppend(&tempStrings, "Heading2");

  F_ApiNewInlineComponentOfType(docId, FV_MiniTOC, &tempStrings, True, &tr.beg);

 

Works great. So, I don't know. Maybe the ExtendScript implementation is just incomplete. I tried several variations with no success.

 

Russ