Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

select some text in textframe and color this

Return to Member Forum

  • Author
    Posts
    • #87026
      Anonymous
      Inactive

      select some text in textframe and color this
      in first times i took text frame and color text and background.
      but i need color only first words, and in second times i can not color only selected word. please, help me! thanks.

      var textHeaderTf;
      try{
      textHeaderTf = headerTf.paragraphs.item(0);
      if(textHeaderTf!=undefined && textHeaderTf!=null)
      {
      headerTf.parentStory.insertionPoints.item(-1).contents = ‘myNewText’;
      // textHeaderTf.fillColor = myColorA;
      textHeaderTf.strokeColor = myColorB;

      }
      }catch(e){log.write(‘setHeader font-color error7’+e);}

      try{
      textHeaderTfWord = textHeaderTf.words[0];//headerTf.paragraphs.item(1);
      if(textHeaderTfWord!=undefined && textHeaderTfWord!=null)
      {
      textHeaderTfWord.fillColor = myColorA;
      textHeaderTfWord.strokeColor = myColorA;

      }
      }catch(e){log.write(‘setHeader font-color error8’+e);}

    • #87028

      Try this one and try to avoid all those try/catch things :)

      var sel = app.selection[0];
      
      // check your selection
      if (sel != undefined) {
        var textHeaderTf = sel;
      }
      
      // the parent story
      var parStory = textHeaderTf.parentStory;
      // insert text at the end (realize, that there is no space before the new word)
      parStory.insertionPoints[-1].contents = 'myNewText';
      
      // a fill and a stroke color
      var props = {
        fillColor: app.activeDocument.swatches[4],
        strokeColor: app.activeDocument.swatches[5]
      }
      
      // give the first word in the story a fill and a stroke color
      var firstWord = parStory.words[0];
      
      // since you insert something above, therre is always a word
      firstWord.properties = props;
      
      // give the frame a fill and a stroke color
      textHeaderTf.properties = props;
      
Viewing 1 reply thread
  • You must be logged in to reply to this topic.
Forum Ads