• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Extend Script - How can I access the prefix of a prefix rule for a certain element

Explorer ,
Aug 29, 2024 Aug 29, 2024

Copy link to clipboard

Copied

I need to publish structured documents to xml. Some of the Headings are created by prefix rules in the EDD. When I publish the document to xml, the headings are missing in the xml.

I am a scripting novice to be honest, I have no clue how to get the text out of the prefix rule, which depends on the context. In the FrameMaker scripting guide I found  the following objects which may or may not handle the prefixes
- Element.MatchingPrefixClause; of data type Objects (ID of the prefix clause that apply to the element)

- ElementDef.PrefixRules; of data type objects (IDs of the prefix format rules)

- FmtRuleClause.ElemPrefixSuffix: of data type string (The text of the string)
I am able to select the heading element, but how the hell do I get the content of the prefix from there?
Any hints appreciated!

TOPICS
Scripting , Structured

Views

109

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 29, 2024 Aug 29, 2024

This is kind of a brute force method, but it looks like a prefix shows up in the list of the element's strings. If you know for sure that the element has a prefix, you can probably use something like this. Note that you may have to drop the delimiter between the prefix and the main element text from the end of the string.

 

#target framemaker

main ();

function main () {

    var doc, element, stringArray, prefix;
    
    doc = app.ActiveDoc;
    if (doc.ObjectValid () === 1) {
        element
...

Votes

Translate

Translate
Community Expert ,
Aug 29, 2024 Aug 29, 2024

Copy link to clipboard

Copied

This is kind of a brute force method, but it looks like a prefix shows up in the list of the element's strings. If you know for sure that the element has a prefix, you can probably use something like this. Note that you may have to drop the delimiter between the prefix and the main element text from the end of the string.

 

#target framemaker

main ();

function main () {

    var doc, element, stringArray, prefix;
    
    doc = app.ActiveDoc;
    if (doc.ObjectValid () === 1) {
        element = doc.ElementSelection.beg.child;
        stringArray = (getAnArrayOfStrings (element, doc));
        prefix = stringArray[0];
        alert (prefix);
    }
}

function getAnArrayOfStrings (textObj, doc) {
    
    // Gets an array of strings from the text object or text range.

    var text, textItems, count, i;
    
    text = [];
    
    // Get a list of the strings in the text object or text range.
    if (textObj.constructor.name !== "TextRange") {
        textItems = textObj.GetText(Constants.FTI_String);
    } else {
         textItems = doc.GetTextForRange(textObj, Constants.FTI_String);
    }
    // Concatenate the strings.
    count = textItems.len;
    for (i = 0; i < count; i += 1) {
        text.push (textItems[i].sdata);
    }
    
    return text; // Return the array
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 30, 2024 Aug 30, 2024

Copy link to clipboard

Copied

LATEST

Hi Rick, it works like a charme - thank you very much. I am now able to traverse through the elements of my documents, grab the prefixes of certain Heading elements and write the prefix content into an attribute of the Heading element.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines