Skip to main content
Ch__Efstathios
Inspiring
April 12, 2016
Answered

How can I get the current paragraph?

  • April 12, 2016
  • 1 reply
  • 1241 views

I want to get the current paragraph where the insertion point is.

How can I do this in FDK?

This topic has been closed for replies.
Correct answer Russ Ward

Ch,

I can answer some of these questions but if you decided that this thread is answered, please give the credit to Mike.

Regarding the check for an FO_Pgf object, you should not need that. I think there is some obscure case where F_ApiGetTextRange() gives you an object that is not a paragraph... I forget exactly but I think it has to do with a text line graphic object or something like that. I could be wrong. In any case, if you have a normal text flow with an insertion point, you will get a paragraph object.

This line will abort the operation if any text is selected. Do you really want that?

if (insertionPoint.beg.objId != insertionPoint.end.objId) 



This line will abort the operation if multiple paragraphs are selected. Do you really want that? Without this check, you would still get the text of the first selected paragraph.

if (insertionPoint.beg.offset != insertionPoint.end.offset)


Otherwise, the code looks OK to me, at least as far as the FDK calls. Are you having problems with it?


Russ

1 reply

Participating Frequently
April 13, 2016

Read the section Getting and setting the insertion point or text selection in the FDK Programmer’s Guide.

The code below is from memory, but should give you the idea of what is required. You should add error checking, and test it.

F_ObjHandleT activeDoc;

F_TextRangeT textRange;

activeDoc = F_ApiGetId(0, FV_SessionId, FP_ActiveDoc);

textRange = F_ApiGetTextRange(FV_SessionId, activeDoc, FP_TextSelection);

/*

* textRange.beg.objId is the ID of the paragraph or text line at the start of the current selection

* textRange.end.objId is the ID of the paragraph or text line at the end of the current selection

*/

if (F_ApiGetObjectType(activeDoc, textRange.beg.objId) == FO_Pgf) {

     // we have a paragraph

}
else {

     // we have a text line

}

Ch__Efstathios
Inspiring
April 13, 2016

In your code: if (F_ApiGetObjectType(activeDoc, textRange.beg.objId) == FO_Pgf) {      // we have a paragraph  }  else {      // we have a text line  } Is it necessary to check for FO_Pgf? What is the different of a paragraph and text line? In my situation I just get all text lines from the object where the insertion point is and most of the time all these text items are form a paragraph (I am not sure)...

Russ WardCorrect answer
Legend
April 13, 2016

Ch,

I can answer some of these questions but if you decided that this thread is answered, please give the credit to Mike.

Regarding the check for an FO_Pgf object, you should not need that. I think there is some obscure case where F_ApiGetTextRange() gives you an object that is not a paragraph... I forget exactly but I think it has to do with a text line graphic object or something like that. I could be wrong. In any case, if you have a normal text flow with an insertion point, you will get a paragraph object.

This line will abort the operation if any text is selected. Do you really want that?

if (insertionPoint.beg.objId != insertionPoint.end.objId) 



This line will abort the operation if multiple paragraphs are selected. Do you really want that? Without this check, you would still get the text of the first selected paragraph.

if (insertionPoint.beg.offset != insertionPoint.end.offset)


Otherwise, the code looks OK to me, at least as far as the FDK calls. Are you having problems with it?


Russ