Basil.js 和 Indesign 中的 ExtendScript / 如何设置文本框架的样式?

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

Indesign 中的 svg 元素 placed/drawn 之后,我想更改 部分或所有元素 的样式。在我的示例中,我在绘制 textFrames 时设置了样式。我的例子有效。

但如何在 放置文本框后更改样式?

我想使用倾斜角度(应用于 TextFrame)和旋转角度(查看我的示例 -> forLoop)

我尝试了以下方法:r.textFrames.shearAngle=20;doc.textFrames.add({shearAngle:20}); ...但都不起作用。

    #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();

你快明白了。在您的代码中,变量 r 已经是一个 textFrame 对象。

所以应该是:

r.shearAngle = 20; 

明天见 class ;-)

编辑 1:

正如评论中所说。代码

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

returns properties 对象。不是文本框。删除 .properties 部分,Benedikts 和我的方法应该有效。

编辑2:

Benedikts 的方法行不通。我收到以下错误。

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

@Benedikt: shearAngle 不是文本 属性。它适用于 TextFrame、Rectangle、Oval 等 pageItem。 Basil.js 中有没有办法设置这样的属性?嵌套属性如何?我会为此设置一个 new question