简体   繁体   English

Indesign中的Basil.js和ExtendScript /如何设置textFrames的样式?

[英]Basil.js and ExtendScript in Indesign / How can I style textFrames?

After the svg elements are placed/drawn in Indesign, I wanna change the style from some or all elements . 在Indesign中放置/绘制svg元素后,我想更改部分或全部元素的样式。 In my example I style the textFrames while they are drawn. 在我的示例中,我在绘制textFrame时设置了样式。 My example works. 我的例子有效。

But how can I change the style after the textFrames are placed? 但是在放置textFrame 之后如何更改样式?

I wanna use the skewing angle (applied to the TextFrame) and the rotationAngle (look in my example -> forLoop) 我想使用偏斜角(应用于TextFrame)和rotationAngle(在我的示例中-> forLoop)

I tried the following: r.textFrames.shearAngle=20; 我尝试了以下方法: r.textFrames.shearAngle=20; and doc.textFrames.add({shearAngle:20}); doc.textFrames.add({shearAngle:20}); ...but both don't work. ...但是两者都不起作用。

    #includepath "~/Documents/;%USERPROFILE%Documents";
    #include "basiljs/bundle/basil.js";

    // this script shows how to load data into 
    // basil for further usage. 
    // The document you are working with needs to be saved at least once. 
    // The data needs to be in a folder next to that document 
    // The folder needs to be named "data" 
    // take a look into the output of the JS console of the ESTK
    function draw() {
      var doc = b.doc();
      b.clear(doc); // clear the doc
      b.units(b.MM); // use MM
      var yTextFrame = 195;
      // get the scripts name// get its containing folder// get the name of the script without the extension // add the .indd to the extension
      var fname = File($.fileName).parent.fsName + '/' + ($.fileName.split('/')[$.fileName.split('/').length - 1]).split('.')[0] + '.indd';
      // and save it
      doc.save(fname, false, 'basil', true); //save the file next to the script

      // code goes here -----------
      var filecontent = b.loadString("data.json"); // load the text file
      b.println(filecontent.constructor.name); // take a look at what kind of content we have
      var json = b.JSON.decode(filecontent); // transform it to JSON
      b.println(json.constructor.name); // take a look again what json is
      b.println(json.description); // print something from the file
      // loop all the entries
      for (var i = 0; i < 5; i++) {
        b.println(json.laundry_care_instructions[i].instruction); // take a look at the entry
        b.println(json.laundry_care_instructions[i].instruction.length); // how many characters does the entry have
        var r =b.text(json.laundry_care_instructions[i].instruction, 10 + 7 * i, yTextFrame, b.width - 20, 7).properties={rotationAngle:90, shearAngle:20};// create a text box with the entry // // The skewing angle applied to the TextFrame 
      }
      // end of your code ---------

    }
    b.go();

You nearly got it. 你差点知道了。 In your code the variable r is already a textFrame object. 在您的代码中,变量r已经是一个textFrame对象。

So it should be: 因此应该是:

r.shearAngle = 20; 

See you tomorrow in class ;-) 明天上课见;-)

Edit1: 编辑1:

As said in the comments. 如评论中所述。 The code 编码

var r = b.text("txt",x,y,width, height).properties = {something:10};

returns the properties object. 返回properties对象。 Not the TextFrame. 不是TextFrame。 Remove the .properties part and Benedikts and my way should work. 删除.properties部分和Benedikts,我的方法应该可以正常工作。

Edit2: 编辑2:

Benedikts way does not work. Benedikts方法不起作用。 I get the following error. 我收到以下错误。

Error: Object does not support the property or method 'shearAngle'

@Benedikt: shearAngle is not a text property. @Benedikt:shearAngle不是文本属性。 It is for pageItems like TextFrame, Rectangle, Oval and so on. 它适用于诸如TextFrame,Rectangle,Oval等的pageItem。 Is there a way in Basil.js to set properties like these? Basil.js中是否可以设置此类属性? And how is it with nested properties? 以及嵌套属性如何? I will setup a new question for that. 我将为此设置一个新问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM