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

find the text based on language

Contributor ,
Jan 02, 2019 Jan 02, 2019

Copy link to clipboard

Copied

Hi,

     how to find the text based on specific language.. is there any mistake in following code

findParams = AllocatePropVals(2);

findParams[0].propIdent.num = Constants.FS_FindCharFmt;

findParams[0].propVal.valType = Constants.FTF_LANGUAGE;

findParams[0].propVal.sval =Constants.FV_LANG_ENGLISH;

var foundText = doc.Find(tloc, findParams);

TOPICS
Scripting

Views

991

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
Mentor ,
Jan 03, 2019 Jan 03, 2019

Copy link to clipboard

Copied

Hi,

There are definitely some errors in your code. I can point them out; however, I am not able to get the code to work myself. Neither can I get it to work in the UI (FM2019). So I do not have the final answer. I suspect a bug, but perhaps I am using the tool incorrectly in both the script and the UI.

I think all three lines where you define the findParams are wrong. The first is close, except according to the FDK doc, FS_FindCharFmt doesn't do anything. And I do know that the valType should be the datatype of the parameter, and that a language parameter is an integer. So you need to use ival. Basically, here is what I think should work, but does not.

      var doc = app.ActiveDoc;

      var textRange = doc.TextSelection;

      var findParams = AllocatePropVals(2);

     

      findParams[0].propIdent.num = Constants.FP_Language;   

      findParams[0].propVal.valType = Constants.FT_Integer;   

      findParams[0].propVal.ival = Constants.FV_LANG_ENGLISH; 

     

      findParams[1].propIdent.num = Constants.FS_FindWrap;   

      findParams[1].propVal.valType = Constants.FT_Integer;   

      findParams[1].propVal.ival = false; 

    

     textRange = doc.Find(textRange.beg, findParams);

In my test document, this code just finds all the text in the flow. The same thing happens when I attempt the same search in the UI. So I don't know what is going on. Maybe this can help you some.

Russ

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
Advocate ,
Jan 03, 2019 Jan 03, 2019

Copy link to clipboard

Copied

The Find method is notoriously hard to script. If Russ does not find a way to make a search for text in a particular language work, I am sure there will be no such option in the script method either.

If your content has full paragraphs in a particular language, it would probably be easier to run through all the paragraphs and checking their Language property. Something like this:

var oDoc = app.ActiveDoc;

var oPgf = oDoc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;

var oaTargetPgfs = [ ];

while( oPgf.ObjectValid( ) )

{

     if( oPgf.Language == Constants.FV_LANG_GERMAN )

     {

          oaTargetPgfs.push( oPgf );

     }

     oPgf = oPgf.NextPgfInFlow;

}

/* Now you have an array of all the paragraphs that have the German language set. */

I have not tested the above code, so you will have to debug it if I misspelled some of the properties. But I think it should work. Note however that this does not cover the paragraphs in tables - you will have to cycle through all the paragraphs in tables in a bunch of nested loops:

for every table in the document:

     for every cell h the table:

          for every pgf in the cell

               check the language and add to array if there is a match

Good luck with this

4everJang

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
Mentor ,
Jan 03, 2019 Jan 03, 2019

Copy link to clipboard

Copied

Indeed, I agree that the Find() method can be very tricky. What really confuses me this time is that I can't get the UI Find tool to work either. That is, I can't find text with a particular language. It does seem that the UI and my script are operating the same, though, so that's why I suspect a bug. But with the complexities and odd behavior of Find(), I really can't be sure.

Russ

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
Community Expert ,
Jan 03, 2019 Jan 03, 2019

Copy link to clipboard

Copied

From my earliest FrameScript and FDK days, I have never trusted the "Find" function that mimics the UI. So I have always used a "long" approach: I loop through all of the paragraphs in the document, and for each paragraph, loop through the character property changes. For each character property change, I test for what I am looking for. Below is a basic shell for doing this on a single paragraph. Note that I run the loop backwards in case I want to do something with each text range that may affect the offsets of my text items.

There are ways to specify exactly which changes you are looking for, but this general way is the simplest.

#target framemaker

var doc = app.ActiveDoc;

var pgf = doc.TextSelection.beg.obj;

processPropertyChanges (pgf, doc);

function processPropertyChanges (pgf, doc) {

    var end = Constants.FV_OBJ_END_OFFSET - 1, begin = 0, textRange;

   

    var textList = pgf.GetText (Constants.FTI_CharPropsChange);

    for (var i = textList.length - 1; i >= 0; i -= 1) {

        begin = textList.offset;

        if (begin !== end) {

            textRange = new TextRange (new TextLoc (pgf, begin), new TextLoc (pgf, end));

            doc.TextSelection = textRange;

            alert ("test the beginning of the text range for the property you are looking for.");

            end = begin;

        }

    }

    if (end > 0) {

        textRange = new TextRange (new TextLoc (pgf,0), new TextLoc (pgf,end));

        doc.TextSelection = textRange;

        alert ("test the beginning of the text range for the property you are looking for.");

    }

}

-Rick

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
Contributor ,
Jan 03, 2019 Jan 03, 2019

Copy link to clipboard

Copied

Hi all,

Thanks for you reply.. i am new in framemaker scripting.. your's suggestion and code very helpful to me

yes i have made mistake in my code and i think my question is not clear

ok, oPgf.Language returns hyphenation language right?

in clear,

langs.png

oPgf.Language returns 1(English) for arabic content also..

in above document how to i find arabic content and english content

please help

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
Advocate ,
Jan 03, 2019 Jan 03, 2019

Copy link to clipboard

Copied

OK, in this case there is an override for the language for part of the paragraph. You will have to get the text strings from the paragraph and check which ones have the language setting you are looking for. This must be done for each paragraph.

var oaTextItems = oPgf.GetText( Constants.FTI_CharPropsChange );

for( i = 0; i < oaTextItems.length; i++ )

{

     if( oaTextItems.idata & Constants.FTI_LANGUAGE )

     {

          /*  This is a text item for which the character language has changed.

               You need to find the language at this point and check it for the target language */

               var oTLoc = new TextLoc( oPgf, oaTextItems.offset );

               var oProp = oDoc.GetTextPropVal( oTLoc, Constants.FP_Language );

               /*  Now you have the propVal that shows the language at the current location.

                    Check this against your target language. The text item starts at oaTexItem.offset

                    and ends at the offset of the next oaTextItem or the end of the paragraph if the

                    oaTextItem is the last one  */

     }

}

Good luck.

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
Contributor ,
Jan 04, 2019 Jan 04, 2019

Copy link to clipboard

Copied

sorry,

var oDoc = app.ActiveDoc;

var oPgf = oDoc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;

var oaTextItems = oPgf.GetText( Constants.FTI_CharPropsChange );

alert(oaTextItems )

it returns empty for above document..

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
Advocate ,
Jan 04, 2019 Jan 04, 2019

Copy link to clipboard

Copied

You should use alert( oaTextItems.length ) to check if anything is returned, as oaTextItems is an array. But it might be that the array is empty.

If the length of the oaTextItems array is 0, there were no character property changes in the paragraph. This means the paragraph should have the language that is present in the oPgf.Language property. If that does not seem to be correct, you can also set the text location to point to the start of the paragraoh and retrieve the language propval from that location:

var oTLoc = new TextLoc( oPgf, 0 );

This is all the help I can give you at the moment - I need to return to my paid projects. With the info I gave you plus the Scripting Guide and the FDK Reference Guide, you should be able to make it work. Take one small step at a time (but I think you are already doing that).

Good luck

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
Contributor ,
Jan 04, 2019 Jan 04, 2019

Copy link to clipboard

Copied

yes i have already tried.. oaTextItems.length returns 0..

do you have scripting guide or other resources link for framemaker?

please share with me

and please guide where i start to learn framemaker scripting.. i have the scripting guide 2017 but it contains only properties,methods of objects

Thank you

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
Advocate ,
Jan 04, 2019 Jan 04, 2019

Copy link to clipboard

Copied

The Scripting Guide does contain some chapters that help you get started. I do confess it is not a lot. The Scripting Guide for FrameMaker 2017 should be sufficient for what you need to do. You can also search for the FDK Reference. This is for C++ programming but the objects and properties are basically the same and the FDK reference has more info.

https://help.adobe.com/en_US/framemaker/pdfs/fdkreference.pdf​

I am planning to start a series of blog posts about getting started with ExtendScript for FrameMaker. But you would need the info quicker than this, I guess. There was an earlier series of blog posts by Debra Herman. It seems she wants to revive the blog but I doubt it will happen. She did cover quite a bit of beginner's stuff in her older posts and they are still valid for FrameMaker 2019 (as scripting does not change a lot between versions, it just gets extended with more objects and properties as FrameMaker evolves).

Extending FrameMaker​

Good luck, again.

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
Mentor ,
Jan 04, 2019 Jan 04, 2019

Copy link to clipboard

Copied

LATEST

Also, I have a set of samples for beginners, available at:

FrameMaker ExtendScript Samples - West Street Consulting

The samples do not include this specific use case, but I think they have lots of general good stuff for a beginner.

Russ

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