0

After the svg elements are placed/drawn in Indesign, I wanna change the style from some or all elements. In my example I style the textFrames while they are drawn. My example works.

But how can I change the style after the textFrames are placed?

I wanna use the skewing angle (applied to the TextFrame) and the rotationAngle (look in my example -> forLoop)

I tried the following: r.textFrames.shearAngle=20; and 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();
fabianmoronzirfas
  • 4,091
  • 4
  • 24
  • 41
LolaRuns
  • 99
  • 1
  • 1
  • 8

1 Answers1

1

You nearly got it. In your code the variable r is already a textFrame object.

So it should be:

r.shearAngle = 20; 

See you tomorrow in class ;-)

Edit1:

As said in the comments. The code

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

returns the properties object. Not the TextFrame. Remove the .properties part and Benedikts and my way should work.

Edit2:

Benedikts way does not work. I get the following error.

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

@Benedikt: shearAngle is not a text property. It is for pageItems like TextFrame, Rectangle, Oval and so on. Is there a way in Basil.js to set properties like these? And how is it with nested properties? I will setup a new question for that.

Community
  • 1
  • 1
fabianmoronzirfas
  • 4,091
  • 4
  • 24
  • 41
  • Hey Fabian, your version sounds logical. but it doesn't work. strange^^ here are my solution: doc.textFrames.item(0).shearAngle=20; – LolaRuns Apr 19 '16 at 12:27
  • Normally the shorthand `b.typo(r, "shearAngle", 20)` should do the trick too. – Benedikt Groß Apr 19 '16 at 13:30
  • Maybe the .properties call at the end creates the problem. Try to output r to the console. b.println(r.constructor.name); after your var r=… It should give you "TextFrame" if you get a "Object" the properties is the problem. – fabianmoronzirfas Apr 19 '16 at 14:13
  • Here is my follow up question http://stackoverflow.com/questions/36723099/how-to-set-pageitem-properties-in-basil-js – fabianmoronzirfas Apr 19 '16 at 15:36