2 Replies Latest reply: Aug 7, 2012 2:06 AM by michael.shen RSS

    use bridge to create text layer which contains special characters

    michael.shen

      Hi,guys.

      I want create a psd using bridge. but failed. Can anyone help me?

       

      here is my script:

       

       

      script2 = 'var docWidth = 1650;';

      script2 +='var docHeight = 1650;';

      script2 +="var docName ='Front';";

      script2 +='var docRef = app.documents.add(docWidth,docHeight, 300,docName);';

      script2 +="var myLayer1 = docRef.artLayers.add();";

      script2 +="myLayer1.kind = LayerKind.TEXT;";

      script2 +="myLayer1.textItem.kind = TextType.POINTTEXT;";

      script2 +="myLayer1.textItem.font='News702 BT';";

      script2 +="myLayer1.textItem.size=13;";

      script2 +="var textColor1 = new SolidColor;";

      script2 +="textColor1.rgb.hexValue = 'F8F3E9';";

      script2 +="myLayer1.textItem.color = textColor1;";

      script2 +="myLayer1.textItem.contents = 'abcd\'abd\'ed\"afa\"';";      

      var bt = new BridgeTalk();

      bt.target = "photoshop";

      bt.body = script2;

      bt.send();

      the problem is the text content contains ' or ".

        • 1. Re: use bridge to create text layer which contains special characters
          Paul Riggott Community Member

          You have a few problems with your script, you are giving values for the width and height for the new document and they will default the ruler unit setting you have in Photoshop, this may not be pixels.

          The font name should be the postScript name and they do not contain spaces.

          It is best to pass an encoded string to the script and then decode it in Photoshop IE:-

           

           

          var text = encodeURI('abcd\'abd\'ed\"afa');
          var bt = new BridgeTalk();
          bt.target = "photoshop";
          bt.body = bt.body = "var main = " + script.toSource() + "; main(" + text.toSource() + ");";
          bt.send(4);
           
          function script(text){
          var docWidth = 1650;
          var docHeight = 1650;
          var docName ='Front';
          var docRef = app.documents.add(new UnitValue(docWidth,'px'),new UnitValue(docHeight,'px'), 300,docName);
          var myLayer1 = docRef.artLayers.add();
          myLayer1.kind = LayerKind.TEXT;
          myLayer1.textItem.kind = TextType.POINTTEXT;
          myLayer1.textItem.font='Georgia';
          myLayer1.textItem.size=13;
          var textColor1 = new SolidColor;
          textColor1.rgb.hexValue = 'F8F3E9';
          myLayer1.textItem.color = textColor1;
          myLayer1.textItem.contents =decodeURI(text);
          }
          
          
          • 2. Re: use bridge to create text layer which contains special characters
            michael.shen Community Member

            Thank you very much, you script works excellently.

             

            the problems in my code just a test. Thanks again!