Skip to main content
Velprakash
Inspiring
April 25, 2012
Answered

Problem in saving the applied Tag.

  • April 25, 2012
  • 1 reply
  • 654 views

Hi All,

      I created 4 tags manually in cs5. It named b, bi, i, sc for (bold, bolditalic, italic, small caps) already there's a tag default as root.

I want to find bold, italic, bolditalic, small caps words in a document and applying appropriate tags.If I applied tags and then making another word in a document as bold and running this Jx file, It finding correctly. But not able to save the tag applied for new word which is created as bold.

xmlObj[0].name=b;

xmlObj[1].name=bi;

xmlObj[2].name=i;

xmlObj[3].name=root;

xmlObj[4].name=sc;

I also need to mention to apply tagname instead of specifying the above lines.

My code is below. Please some one guide me...

docObj=app.activeDocument;

xmlObj = docObj.xmlTags;

pageObj=docObj.pages.item(0);

myTextFrame=pageObj.textFrames.item(0);

myText=myTextFrame.parentStory.paragraphs.item(0);

app.findTextPreferences = app.changeTextPreferences =  NothingEnum.nothing;

app.findTextPreferences.fontStyle = "Bold";

result = app.activeDocument.findText();

boldlength=0;

boldlength=result.length;

alert(boldlength);

for (i=0; i<boldlength;i++)

{

  

        var myElem=result.associatedXMLElements[0].markupTag.name;

        alert(myElem);

        if(myElem==xmlObj[0].name)

        {

            alert("No need to apply");

            }

        else

        {

            myElem=xmlObj[0].name;

            //result.changeTextPreferences.markupTag=xmlObj[0].name;

            //app.changeTextPreferences.markupTag=xmlObj[0].name;

            alert("apply tag:" +myElem);

            app.changeTextPreferences.result.=myElem.changeText();

            }

       }

//~ app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;

//~ app.findTextPreferences.fontStyle = "Bold Italic";

//~ app.changeTextPreferences.markupTag=xmlObj[1].name;

//~ alert(app.changeTextPreferences.markupTag);

//~ app.activeDocument.changeText();

//~ app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;

//~ app.findTextPreferences.fontStyle = "Italic";

//~ app.changeTextPreferences.markupTag=xmlObj[2].name;

//~ alert(app.changeTextPreferences.markupTag);

//~ app.activeDocument.changeText();

//~ app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;

//~ app.findGrepPreferences.capitalization = Capitalization.SMALL_CAPS;

//~ app.changeGrepPreferences.markupTag=xmlObj[4].name;

//~ alert(app.changeGrepPreferences.markupTag);

//~ app.activeDocument.changeGrep();

This topic has been closed for replies.
Correct answer Velprakash

Correct Codes:

docObj=app.activeDocument;

xmlObj = docObj.xmlTags;

pageObj=docObj.pages.item(0);

myTextFrame=pageObj.textFrames.item(0);

myText=myTextFrame.parentStory.paragraphs.item(0);

app.findTextPreferences = app.changeTextPreferences =  NothingEnum.nothing;

app.findTextPreferences.fontStyle = "Bold";

result = app.activeDocument.findText();

boldlength=0;

boldlength=result.length;

//alert(boldlength);

for (i=0; i<boldlength;i++)

{  

        var myElem=result.associatedXMLElements[0].markupTag.name;

        //alert(myElem);      

        if(myElem=="b")

        {

            }

        else

        {

            app.select(result);

            mySel=app.selection[0];

            docObj.xmlElements[0].xmlElements.add({markupTag:"b", xmlContent:mySel});           

            }

       }

app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;

app.findTextPreferences.fontStyle = "Italic";

result1 = app.activeDocument.findText();

boldlength=0;

boldlength=result1.length;

for (i=0; i<boldlength;i++)

{  

        var myElem=result1.associatedXMLElements[0].markupTag.name;

        if(myElem=="i")

        {

         }

        else

        {

            app.select(result1);

            mySel=app.selection[0];

            docObj.xmlElements[0].xmlElements.add({markupTag:"i", xmlContent:mySel});               

            }

       }

app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;

app.findTextPreferences.fontStyle = "Bold Italic";

result2 = app.activeDocument.findText();

boldlength=0;

boldlength=result2.length;

for (i=0; i<boldlength;i++)

{  

        var myElem=result2.associatedXMLElements[0].markupTag.name;

        if(myElem=="bi")

        {

         }

        else

        {

            app.select(result2);

            mySel=app.selection[0];

            docObj.xmlElements[0].xmlElements.add({markupTag:"bi", xmlContent:mySel});               

            }

       }

app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;

app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;

app.findGrepPreferences.capitalization = Capitalization.SMALL_CAPS;

result3 = app.activeDocument.findGrep();

boldlength=0;

boldlength=result3.length;

for (i=0; i<boldlength;i++)

{  

   

        var myElem=result3.associatedXMLElements[0].markupTag.name;

        if(myElem=="sc")

        {

         }

        else

        {

            app.select(result3);

            mySel=app.selection[0];

            docObj.xmlElements[0].xmlElements.add({markupTag:"sc", xmlContent:mySel});               

            }

       }

  

  

Thanks and Regards,

Vel...

1 reply

Velprakash
VelprakashAuthorCorrect answer
Inspiring
April 25, 2012

Correct Codes:

docObj=app.activeDocument;

xmlObj = docObj.xmlTags;

pageObj=docObj.pages.item(0);

myTextFrame=pageObj.textFrames.item(0);

myText=myTextFrame.parentStory.paragraphs.item(0);

app.findTextPreferences = app.changeTextPreferences =  NothingEnum.nothing;

app.findTextPreferences.fontStyle = "Bold";

result = app.activeDocument.findText();

boldlength=0;

boldlength=result.length;

//alert(boldlength);

for (i=0; i<boldlength;i++)

{  

        var myElem=result.associatedXMLElements[0].markupTag.name;

        //alert(myElem);      

        if(myElem=="b")

        {

            }

        else

        {

            app.select(result);

            mySel=app.selection[0];

            docObj.xmlElements[0].xmlElements.add({markupTag:"b", xmlContent:mySel});           

            }

       }

app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;

app.findTextPreferences.fontStyle = "Italic";

result1 = app.activeDocument.findText();

boldlength=0;

boldlength=result1.length;

for (i=0; i<boldlength;i++)

{  

        var myElem=result1.associatedXMLElements[0].markupTag.name;

        if(myElem=="i")

        {

         }

        else

        {

            app.select(result1);

            mySel=app.selection[0];

            docObj.xmlElements[0].xmlElements.add({markupTag:"i", xmlContent:mySel});               

            }

       }

app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;

app.findTextPreferences.fontStyle = "Bold Italic";

result2 = app.activeDocument.findText();

boldlength=0;

boldlength=result2.length;

for (i=0; i<boldlength;i++)

{  

        var myElem=result2.associatedXMLElements[0].markupTag.name;

        if(myElem=="bi")

        {

         }

        else

        {

            app.select(result2);

            mySel=app.selection[0];

            docObj.xmlElements[0].xmlElements.add({markupTag:"bi", xmlContent:mySel});               

            }

       }

app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;

app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;

app.findGrepPreferences.capitalization = Capitalization.SMALL_CAPS;

result3 = app.activeDocument.findGrep();

boldlength=0;

boldlength=result3.length;

for (i=0; i<boldlength;i++)

{  

   

        var myElem=result3.associatedXMLElements[0].markupTag.name;

        if(myElem=="sc")

        {

         }

        else

        {

            app.select(result3);

            mySel=app.selection[0];

            docObj.xmlElements[0].xmlElements.add({markupTag:"sc", xmlContent:mySel});               

            }

       }

  

  

Thanks and Regards,

Vel...