Highlighted

How to get Conditional tag name for F_TextItemT

Explorer ,
Mar 08, 2018

Copy link to clipboard

Copied

Hi,

I am trying to get Condition tag name if present for TextItem inside paragraph

F_TextRangeT trSel, trFound;

F_IntsT condIds;

F_PropValsT findParams;

trSel.beg.objId = trSel.end.objId = hPgfId;

trSel.beg.offset = trSel.end.offset = 0;

findParams = F_ApiAllocatePropVals(1);

findParams.val[0].propIdent.num = FS_FindText;

findParams.val[0].propVal.valType = FT_String;

//For demo "c" is the first character in the string of every F_TextItemT

findParams.val[0].propVal.u.sval = F_StrCopyString((ConStringT)"c");

trFound = F_ApiFind(docId, &trSel.beg, &findParams);

//Setting insertion point

F_ApiSetTextRange(FV_SessionId, m_doc.getDocId(), FP_TextSelection, &trFound);

//Get condition ids at insertion point

condIds = F_ApiGetInts(FV_SessionId, docId, FP_InCond);

I am able to get the name by making every textitem a insertion point and fetching its condition values.

Is there any way to fetch conditional tag name without adding insertion point for a textItem?

Thanks,
Abhijeet

[Moved to Scripting Forum by moderator: more chance of programming expertise here.]

Adobe Community Professional
Correct answer by frameexpert | Adobe Community Professional

Here is a function from a very old plugin that I used to sell. This function takes a text object, like a paragraph, and finds a condition format and replaces it with another. Of interest to you will be:

  • Line19 where I am getting the a text list of character property changes.
  • Line 25 is where I am seeing if there is a condition format change.
  • Lines 27-33: I am making a text range for the current unique conditional text formatting, because I want to replace the current format with new formatting. You may not need to do this.

Please let me know if you have any questions or comments.

IntT FindChangeCondFmts(F_ObjHandleT oDoc, F_ObjHandleT oTextObj, StringT findFmt,

    F_ObjHandleT changeFmtId)

{

    UIntT i = 0, j = 0, n = 0;

    IntT iBeginOffset = 0, iEndOffset = 0, iOldFound = 0, iCount = 0;

    F_IntsT iOldConds, iNewConds;

    F_ObjHandleT findFmtId;

    F_TextItemsT tTextItems; // Text items returned by F_ApiGetText().

    F_TextRangeT tTextRange; // Text range of unique character tag formatting.

    F_PropValT pCharProp; // Properties of text range.

    F_PropValT pNewProp; // New properties of text range.

    // Get the old condition format object.

    findFmtId = F_ApiGetNamedObject(oDoc, FO_CondFmt, findFmt);

    // Get a list of character property changes.

    tTextItems = F_ApiGetText(oDoc, oTextObj, FTI_CharPropsChange);

    // Loop through the list of text items.

    for (n=0; n < tTextItems.len; n++)

    {

        // See if the character format has changed.

        if (tTextItems.val.u.idata & FTF_CONDITIONTAG)

        {

            if (tTextItems.val.offset != iBeginOffset)

            {

                iEndOffset = tTextItems.val.offset;

                // Make a text range of the unique tag formatting.

                tTextRange.beg.objId = tTextRange.end.objId = oTextObj;

                tTextRange.beg.offset = iBeginOffset;

                tTextRange.end.offset = iEndOffset;

                // Get the text properties at the beginning of the range.

                pCharProp = F_ApiGetTextPropVal(oDoc, &tTextRange.beg, FP_InCond);

                iOldConds = pCharProp.propVal.u.isval;

                if (iOldConds.len)

                {

                    // Initialize the new condition integer list.

                    iNewConds.val = (IntT *)F_Alloc(sizeof(IntT), NO_DSE);

                    // Loop through the old conditions and look for the find condition.

                    for (i = 0, j = 0; i < iOldConds.len; i++)

                    {

                        if(iOldConds.val != (IntT)findFmtId)

                        {

                            iNewConds.val = (IntT *)F_Realloc(iNewConds.val, sizeof(IntT)*(j+1), NO_DSE);

                            iNewConds.val = iOldConds.val;

                            j++;

                        }

                        else // Find condition found.

                        {

                            if ((IntT)changeFmtId > 0) // Add the change condition to the new list.

                            {

                                iNewConds.val = (IntT *)F_Realloc(iNewConds.val, sizeof(IntT)*(j+1), NO_DSE);

                                iNewConds.val = changeFmtId;

                                j++;

                            }

                            iOldFound = 1; // The old condition was found/changed.

                        }

                    }

                    iNewConds.len = j;

                    if (iOldFound == 1)

                    {

                        // Set up the text property with the new condition list.

                        pNewProp.propIdent.num = FP_InCond;

                        pNewProp.propVal.valType = FT_Ints;

                        pNewProp.propVal.u.isval = iNewConds;

                        // Apply the new condition list to the text range.

                        F_ApiSetTextPropVal(oDoc, &tTextRange, &pNewProp);

                        iCount++;

                        // Deallocate the property value.

                        F_ApiDeallocatePropVal(&pNewProp);

                    }

                }

                // Deallocate the property value.

                F_ApiDeallocatePropVal(&pCharProp);

                // Advance the beginning offset variable to the current offset.

                iBeginOffset = iEndOffset;

           }

        }

    }

    // At the end of the text object, make a text range including the end.

    tTextRange.beg.objId = tTextRange.end.objId = oTextObj;

    tTextRange.beg.offset = iBeginOffset;

    tTextRange.end.offset = FV_OBJ_END_OFFSET;

    // Get the text properties at the beginning of the range.

    pCharProp = F_ApiGetTextPropVal(oDoc, &tTextRange.beg, FP_InCond);

    iOldConds = pCharProp.propVal.u.isval;

    if (iOldConds.len)

    {

        // Initialize the new condition integer list.

        iNewConds.val = (IntT *)F_Alloc(sizeof(IntT), NO_DSE);

        // Loop through the old conditions and look for the find condition.

        for (i = 0, j = 0; i < iOldConds.len; i++)

        {

            if(iOldConds.val != (IntT)findFmtId)

            {

                iNewConds.val = (IntT *)F_Realloc(iNewConds.val, sizeof(IntT)*(j+1), NO_DSE);

                iNewConds.val = iOldConds.val;

                j++;

            }

            else // Find condition found.

            {

                if ((IntT)changeFmtId > 0) // Add the change condition to the new list.

                {

                    iNewConds.val = (IntT *)F_Realloc(iNewConds.val, sizeof(IntT)*(j+1), NO_DSE);

                    iNewConds.val = changeFmtId;

                    j++;

                }

                iOldFound = 1; // The old condition was found/changed.

            }

        }

        iNewConds.len = j;

        if (iOldFound == 1)

        {

            // Set up the text property with the new condition list.

            pNewProp.propIdent.num = FP_InCond;

            pNewProp.propVal.valType = FT_Ints;

            pNewProp.propVal.u.isval = iNewConds;

            // Apply the new condition list to the text range.

            F_ApiSetTextPropVal(oDoc, &tTextRange, &pNewProp);

            iCount++;

            // Deallocate the property value.

            F_ApiDeallocatePropVal(&pNewProp);

        }

    }

    // Deallocate the property value.

    F_ApiDeallocatePropVal(&pCharProp);

    return(iCount);

}

TOPICS
Scripting

Views

236

Likes

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

How to get Conditional tag name for F_TextItemT

Explorer ,
Mar 08, 2018

Copy link to clipboard

Copied

Hi,

I am trying to get Condition tag name if present for TextItem inside paragraph

F_TextRangeT trSel, trFound;

F_IntsT condIds;

F_PropValsT findParams;

trSel.beg.objId = trSel.end.objId = hPgfId;

trSel.beg.offset = trSel.end.offset = 0;

findParams = F_ApiAllocatePropVals(1);

findParams.val[0].propIdent.num = FS_FindText;

findParams.val[0].propVal.valType = FT_String;

//For demo "c" is the first character in the string of every F_TextItemT

findParams.val[0].propVal.u.sval = F_StrCopyString((ConStringT)"c");

trFound = F_ApiFind(docId, &trSel.beg, &findParams);

//Setting insertion point

F_ApiSetTextRange(FV_SessionId, m_doc.getDocId(), FP_TextSelection, &trFound);

//Get condition ids at insertion point

condIds = F_ApiGetInts(FV_SessionId, docId, FP_InCond);

I am able to get the name by making every textitem a insertion point and fetching its condition values.

Is there any way to fetch conditional tag name without adding insertion point for a textItem?

Thanks,
Abhijeet

[Moved to Scripting Forum by moderator: more chance of programming expertise here.]

Adobe Community Professional
Correct answer by frameexpert | Adobe Community Professional

Here is a function from a very old plugin that I used to sell. This function takes a text object, like a paragraph, and finds a condition format and replaces it with another. Of interest to you will be:

  • Line19 where I am getting the a text list of character property changes.
  • Line 25 is where I am seeing if there is a condition format change.
  • Lines 27-33: I am making a text range for the current unique conditional text formatting, because I want to replace the current format with new formatting. You may not need to do this.

Please let me know if you have any questions or comments.

IntT FindChangeCondFmts(F_ObjHandleT oDoc, F_ObjHandleT oTextObj, StringT findFmt,

    F_ObjHandleT changeFmtId)

{

    UIntT i = 0, j = 0, n = 0;

    IntT iBeginOffset = 0, iEndOffset = 0, iOldFound = 0, iCount = 0;

    F_IntsT iOldConds, iNewConds;

    F_ObjHandleT findFmtId;

    F_TextItemsT tTextItems; // Text items returned by F_ApiGetText().

    F_TextRangeT tTextRange; // Text range of unique character tag formatting.

    F_PropValT pCharProp; // Properties of text range.

    F_PropValT pNewProp; // New properties of text range.

    // Get the old condition format object.

    findFmtId = F_ApiGetNamedObject(oDoc, FO_CondFmt, findFmt);

    // Get a list of character property changes.

    tTextItems = F_ApiGetText(oDoc, oTextObj, FTI_CharPropsChange);

    // Loop through the list of text items.

    for (n=0; n < tTextItems.len; n++)

    {

        // See if the character format has changed.

        if (tTextItems.val.u.idata & FTF_CONDITIONTAG)

        {

            if (tTextItems.val.offset != iBeginOffset)

            {

                iEndOffset = tTextItems.val.offset;

                // Make a text range of the unique tag formatting.

                tTextRange.beg.objId = tTextRange.end.objId = oTextObj;

                tTextRange.beg.offset = iBeginOffset;

                tTextRange.end.offset = iEndOffset;

                // Get the text properties at the beginning of the range.

                pCharProp = F_ApiGetTextPropVal(oDoc, &tTextRange.beg, FP_InCond);

                iOldConds = pCharProp.propVal.u.isval;

                if (iOldConds.len)

                {

                    // Initialize the new condition integer list.

                    iNewConds.val = (IntT *)F_Alloc(sizeof(IntT), NO_DSE);

                    // Loop through the old conditions and look for the find condition.

                    for (i = 0, j = 0; i < iOldConds.len; i++)

                    {

                        if(iOldConds.val != (IntT)findFmtId)

                        {

                            iNewConds.val = (IntT *)F_Realloc(iNewConds.val, sizeof(IntT)*(j+1), NO_DSE);

                            iNewConds.val = iOldConds.val;

                            j++;

                        }

                        else // Find condition found.

                        {

                            if ((IntT)changeFmtId > 0) // Add the change condition to the new list.

                            {

                                iNewConds.val = (IntT *)F_Realloc(iNewConds.val, sizeof(IntT)*(j+1), NO_DSE);

                                iNewConds.val = changeFmtId;

                                j++;

                            }

                            iOldFound = 1; // The old condition was found/changed.

                        }

                    }

                    iNewConds.len = j;

                    if (iOldFound == 1)

                    {

                        // Set up the text property with the new condition list.

                        pNewProp.propIdent.num = FP_InCond;

                        pNewProp.propVal.valType = FT_Ints;

                        pNewProp.propVal.u.isval = iNewConds;

                        // Apply the new condition list to the text range.

                        F_ApiSetTextPropVal(oDoc, &tTextRange, &pNewProp);

                        iCount++;

                        // Deallocate the property value.

                        F_ApiDeallocatePropVal(&pNewProp);

                    }

                }

                // Deallocate the property value.

                F_ApiDeallocatePropVal(&pCharProp);

                // Advance the beginning offset variable to the current offset.

                iBeginOffset = iEndOffset;

           }

        }

    }

    // At the end of the text object, make a text range including the end.

    tTextRange.beg.objId = tTextRange.end.objId = oTextObj;

    tTextRange.beg.offset = iBeginOffset;

    tTextRange.end.offset = FV_OBJ_END_OFFSET;

    // Get the text properties at the beginning of the range.

    pCharProp = F_ApiGetTextPropVal(oDoc, &tTextRange.beg, FP_InCond);

    iOldConds = pCharProp.propVal.u.isval;

    if (iOldConds.len)

    {

        // Initialize the new condition integer list.

        iNewConds.val = (IntT *)F_Alloc(sizeof(IntT), NO_DSE);

        // Loop through the old conditions and look for the find condition.

        for (i = 0, j = 0; i < iOldConds.len; i++)

        {

            if(iOldConds.val != (IntT)findFmtId)

            {

                iNewConds.val = (IntT *)F_Realloc(iNewConds.val, sizeof(IntT)*(j+1), NO_DSE);

                iNewConds.val = iOldConds.val;

                j++;

            }

            else // Find condition found.

            {

                if ((IntT)changeFmtId > 0) // Add the change condition to the new list.

                {

                    iNewConds.val = (IntT *)F_Realloc(iNewConds.val, sizeof(IntT)*(j+1), NO_DSE);

                    iNewConds.val = changeFmtId;

                    j++;

                }

                iOldFound = 1; // The old condition was found/changed.

            }

        }

        iNewConds.len = j;

        if (iOldFound == 1)

        {

            // Set up the text property with the new condition list.

            pNewProp.propIdent.num = FP_InCond;

            pNewProp.propVal.valType = FT_Ints;

            pNewProp.propVal.u.isval = iNewConds;

            // Apply the new condition list to the text range.

            F_ApiSetTextPropVal(oDoc, &tTextRange, &pNewProp);

            iCount++;

            // Deallocate the property value.

            F_ApiDeallocatePropVal(&pNewProp);

        }

    }

    // Deallocate the property value.

    F_ApiDeallocatePropVal(&pCharProp);

    return(iCount);

}

TOPICS
Scripting

Views

237

Likes

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
Mar 08, 2018 0
Adobe Community Professional ,
Mar 08, 2018

Copy link to clipboard

Copied

You should be able to query the beginning of the text range directly:

F_PropValT prop;

prop = F_ApiGetTextPropVal (docId, &trFound.beg, FP_InCond);

Likes

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
Reply
Loading...
Mar 08, 2018 1
Explorer ,
Mar 09, 2018

Copy link to clipboard

Copied

Thanks for the suggestion. I am wondering how can I get textRange when iterating over all paragraphs in document without adding insertion point?

My aim is to create custom XML from FM document and want to have Conditional Tag information if present for each textItem.

F_ObjHandleT hPgfId = m_doc.getFMDocId(hFrameId, FP_FirstPgf);

//Iterate all pragraphs in textframe

while (hPgfId != NULL)

{

  F_TextItemsT tix;

  tix = F_ApiGetText(docId, hPgfId, flags);

  //Iterating over all textitems in paragraph

  for (size_t tix = 0; tix < tix.len; tix++)

    {

        //How do I get text range for a textItem without seeting insertion point?

        //Or any other way to find Conditional Tag name for textItem?

       

        F_PropValT prop;

        prop = F_ApiGetTextPropVal (docId, &trFound.beg, FP_InCond);

    };

  hPgfId = m_doc.getFMDocId(hPgfId, FP_NextPgfInFlow);

}

Thanks,
Abhijeet

Likes

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
Reply
Loading...
Mar 09, 2018 0
Adobe Community Professional ,
Mar 09, 2018

Copy link to clipboard

Copied

Here is a function from a very old plugin that I used to sell. This function takes a text object, like a paragraph, and finds a condition format and replaces it with another. Of interest to you will be:

  • Line19 where I am getting the a text list of character property changes.
  • Line 25 is where I am seeing if there is a condition format change.
  • Lines 27-33: I am making a text range for the current unique conditional text formatting, because I want to replace the current format with new formatting. You may not need to do this.

Please let me know if you have any questions or comments.

IntT FindChangeCondFmts(F_ObjHandleT oDoc, F_ObjHandleT oTextObj, StringT findFmt,

    F_ObjHandleT changeFmtId)

{

    UIntT i = 0, j = 0, n = 0;

    IntT iBeginOffset = 0, iEndOffset = 0, iOldFound = 0, iCount = 0;

    F_IntsT iOldConds, iNewConds;

    F_ObjHandleT findFmtId;

    F_TextItemsT tTextItems; // Text items returned by F_ApiGetText().

    F_TextRangeT tTextRange; // Text range of unique character tag formatting.

    F_PropValT pCharProp; // Properties of text range.

    F_PropValT pNewProp; // New properties of text range.

    // Get the old condition format object.

    findFmtId = F_ApiGetNamedObject(oDoc, FO_CondFmt, findFmt);

    // Get a list of character property changes.

    tTextItems = F_ApiGetText(oDoc, oTextObj, FTI_CharPropsChange);

    // Loop through the list of text items.

    for (n=0; n < tTextItems.len; n++)

    {

        // See if the character format has changed.

        if (tTextItems.val.u.idata & FTF_CONDITIONTAG)

        {

            if (tTextItems.val.offset != iBeginOffset)

            {

                iEndOffset = tTextItems.val.offset;

                // Make a text range of the unique tag formatting.

                tTextRange.beg.objId = tTextRange.end.objId = oTextObj;

                tTextRange.beg.offset = iBeginOffset;

                tTextRange.end.offset = iEndOffset;

                // Get the text properties at the beginning of the range.

                pCharProp = F_ApiGetTextPropVal(oDoc, &tTextRange.beg, FP_InCond);

                iOldConds = pCharProp.propVal.u.isval;

                if (iOldConds.len)

                {

                    // Initialize the new condition integer list.

                    iNewConds.val = (IntT *)F_Alloc(sizeof(IntT), NO_DSE);

                    // Loop through the old conditions and look for the find condition.

                    for (i = 0, j = 0; i < iOldConds.len; i++)

                    {

                        if(iOldConds.val != (IntT)findFmtId)

                        {

                            iNewConds.val = (IntT *)F_Realloc(iNewConds.val, sizeof(IntT)*(j+1), NO_DSE);

                            iNewConds.val = iOldConds.val;

                            j++;

                        }

                        else // Find condition found.

                        {

                            if ((IntT)changeFmtId > 0) // Add the change condition to the new list.

                            {

                                iNewConds.val = (IntT *)F_Realloc(iNewConds.val, sizeof(IntT)*(j+1), NO_DSE);

                                iNewConds.val = changeFmtId;

                                j++;

                            }

                            iOldFound = 1; // The old condition was found/changed.

                        }

                    }

                    iNewConds.len = j;

                    if (iOldFound == 1)

                    {

                        // Set up the text property with the new condition list.

                        pNewProp.propIdent.num = FP_InCond;

                        pNewProp.propVal.valType = FT_Ints;

                        pNewProp.propVal.u.isval = iNewConds;

                        // Apply the new condition list to the text range.

                        F_ApiSetTextPropVal(oDoc, &tTextRange, &pNewProp);

                        iCount++;

                        // Deallocate the property value.

                        F_ApiDeallocatePropVal(&pNewProp);

                    }

                }

                // Deallocate the property value.

                F_ApiDeallocatePropVal(&pCharProp);

                // Advance the beginning offset variable to the current offset.

                iBeginOffset = iEndOffset;

           }

        }

    }

    // At the end of the text object, make a text range including the end.

    tTextRange.beg.objId = tTextRange.end.objId = oTextObj;

    tTextRange.beg.offset = iBeginOffset;

    tTextRange.end.offset = FV_OBJ_END_OFFSET;

    // Get the text properties at the beginning of the range.

    pCharProp = F_ApiGetTextPropVal(oDoc, &tTextRange.beg, FP_InCond);

    iOldConds = pCharProp.propVal.u.isval;

    if (iOldConds.len)

    {

        // Initialize the new condition integer list.

        iNewConds.val = (IntT *)F_Alloc(sizeof(IntT), NO_DSE);

        // Loop through the old conditions and look for the find condition.

        for (i = 0, j = 0; i < iOldConds.len; i++)

        {

            if(iOldConds.val != (IntT)findFmtId)

            {

                iNewConds.val = (IntT *)F_Realloc(iNewConds.val, sizeof(IntT)*(j+1), NO_DSE);

                iNewConds.val = iOldConds.val;

                j++;

            }

            else // Find condition found.

            {

                if ((IntT)changeFmtId > 0) // Add the change condition to the new list.

                {

                    iNewConds.val = (IntT *)F_Realloc(iNewConds.val, sizeof(IntT)*(j+1), NO_DSE);

                    iNewConds.val = changeFmtId;

                    j++;

                }

                iOldFound = 1; // The old condition was found/changed.

            }

        }

        iNewConds.len = j;

        if (iOldFound == 1)

        {

            // Set up the text property with the new condition list.

            pNewProp.propIdent.num = FP_InCond;

            pNewProp.propVal.valType = FT_Ints;

            pNewProp.propVal.u.isval = iNewConds;

            // Apply the new condition list to the text range.

            F_ApiSetTextPropVal(oDoc, &tTextRange, &pNewProp);

            iCount++;

            // Deallocate the property value.

            F_ApiDeallocatePropVal(&pNewProp);

        }

    }

    // Deallocate the property value.

    F_ApiDeallocatePropVal(&pCharProp);

    return(iCount);

}

Likes

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
Reply
Loading...
Mar 09, 2018 3
acroabhi LATEST
Explorer ,
Mar 11, 2018

Copy link to clipboard

Copied

That worked just great for me! Thanks a lot!

Used FP_Name to get conditional tag name

//Passing textRange for each textItem

case FTI_CharPropsChange:

{       

    F_PropValT pCharProp;

    F_IntsT condIds;

    if (item.u.idata & FTF_CONDITIONTAG)

    {

        pCharProp = F_ApiGetTextPropVal(m_doc.getDocId(), &tTextRange.beg, FP_InCond);

        condIds = pCharProp.propVal.u.isval;

        if (condIds.len)

        {

            for (int i = 0; i < condIds.len; i++)

            {

                //Got the conditional tag!

                StringT condtionTagName = F_ApiGetString(m_doc.getDocId(), condIds.val, FP_Name);

                if (condtionTagName != NULL)

                {

                    std::wstring condtionTag;

                    CFMUtils::FMToWChar(condtionTagName, condtionTag);

                }

            }

        }

    }

}

Thanks,
Abhijeet

Likes

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
Reply
Loading...
Mar 11, 2018 2