Quantcast
Channel: Adobe Community: Message List - FrameMaker Scripting
Viewing all articles
Browse latest Browse all 3715

Re: Applying a condition to a paragraph

$
0
0

Here is what I'm using that crashes FM...intended to loop through a doc and change existing condition (PrevTag) to a condition that has been detected in the document (NewTag):

 

function ChangeAllTextCondition(CurrDoc, PrevTag, NewTag) {
    var currPgf = CurrDoc.FirstFlowInDoc.FirstTextFrameInFlow.FirstPgf;       
    var oldFmt = CurrDoc.GetNamedCondFmt(PrevTag.Name);
    var newFmt = CurrDoc.GetNamedCondFmt(NewTag.Name);       
   
    var cTextLoc = new TextLoc(currPgf,0);   
    var cPropVal = allocatePropertiesCR(PrevTag.Name);
   
    var cTextRange = CurrDoc.Find(cTextLoc, cPropVal);   
    while (FA_errno == 0 && !CF_isInReferenceOrHiddenPageOrMasterPageCR(cTextRange.beg)) {  
        var cTextItems = CurrDoc.GetTextForRange (cTextRange, Constants.FTI_String);
        var counter = 0;
        while (counter < cTextItems.length) {
            var changed = 0;
            var temptr = new TextRange;
            temptr.beg.obj = cTextRange.beg.obj;
            temptr.end.obj = cTextRange.end.obj;
            temptr.beg.offset = cTextItems[counter].offset;
            if (counter != cTextItems.length-1) {
                temptr.end.offset = (cTextItems[counter+1].offset);
                }
            else if (counter == cTextItems.length-1) {
                temptr.end.offset = cTextRange.end.offset;
                }
                           
            var tempLoc =new TextLoc(cTextRange.beg.obj, cTextItems[counter].offset);
            var props = CurrDoc.GetTextPropVal(tempLoc, Constants.FP_InCond);
                        
            if (props.propVal.isval.length > 0) {
                var count = 0;    
                var propLength= props.propVal.isval.length;
                while (count < propLength) {
                    if (props.propVal.osval[count].id == oldFmt.id) {
                        props.propVal.isval[count] = newFmt.id;
                        props.propVal.osval[count] = newFmt;
                        changed = 1;
                        break;
                        }
                    }

                if (changed) {   
                    var result = CurrDoc.SetTextPropVal(temptr, props);   
                    }
                }
            cTextLoc = cTextRange.end;
            cTextRange = cCurrDoc.Find(TextLoc, tempPropVal);
            }
        }
  return
}


/*This functions returns whether a location is in which page*/
function CF_isInReferenceOrHiddenPageOrMasterPageCR(textLoc) {
    var pageType = CF_getTextLocPageTypeCR(textLoc);   
return ( pageType == Constants.FO_RefPage) ||
   (pageType == Constants.FO_HiddenPage) ||
            (pageType == Constants.FO_MasterPage);
}


function allocatePropertiesCR(iniTag) {
        var tempPropVal = new PropVal;
        tempPropVal = AllocatePropVals(1);
        tempPropVal[0].propIdent.num = Constants.FS_FindCondTextInCondTags;
        tempPropVal[0].propVal.valType = Constants.FT_Strings;
        tempPropVal[0].propVal.ssval[0]= iniTag;
        return tempPropVal;
}


function CF_getTextLocPageTypeCR(textLoc) {
var inPageType = Constants.FO_Bad;
if(textLoc.obj.ObjectValid()) {
  var parentFrame = textLoc.obj.InTextFrame;
  var parentType = parentFrame.type;
 
  while(parentType != Constants.FO_BodyPage
   && parentType != Constants.FO_MasterPage
   && parentType != Constants.FO_HiddenPage
   && parentType != Constants.FO_RefPage) {
   var oldParentFrame = parentFrame;
   parentFrame = parentFrame.FrameParent;
  
   if(!parentFrame.ObjectValid()) {
    parentFrame = oldParentFrame.PageFramePage;   
    if(!parentFrame.ObjectValid())
     break;
                }  
   parentType = parentFrame.type;
            }
  inPageType = parentType;
        }
return inPageType;
}


Viewing all articles
Browse latest Browse all 3715

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>