EzDevInfo.com

basil.js

The missing Javascript smart persistent layer Basil.js by Wisembly

add property to object

With Indesign scripting, why can't I add properties to an object? I get an error

Object does not support the property or method 'foo'

items = b.items(b.layer("s_labels"));

for (var i = 0; i < items.length; i++) {
    items[i].fit(FitOptions.frameToContent);

    items[i].foo = "bar";
    // other attempt
    items[i]["foo"] = "bar";
}

Source: (StackOverflow)

How to include additional scripts in basil.js

New to Basil.js, but love it dearly.

I am wondering if it is possible to link other javascript sheets in my .jsx script and what the correct procedure is. When I try:

#include "basiljs/users/anotherscript.jsx";

InDesign throws err:

Error Number: 48 Offending Text: #include "basiljs/users/anotherscript.jsx";


Source: (StackOverflow)

Advertisements

set object style with basil.js

from basil cheatsheet:

b.objectStyle(”myStyle”); // return or create style with given name

But when I try it (on a text frame):

b.selection().appliedObjectStyle =  b.objectStyle("CAPTION");

Nothing happens. While this works:

b.selection().appliedObjectStyle = app.documents[0].objectStyles.item("CAPTION");

So what is a good use of the 'b.objectStyle("CAPTION");' method apart from creating a object style?


Source: (StackOverflow)

Is there a way to create a gradient in basiljs?

It's a pretty self-explanatory question.

I am curious as to why there is no built-in function to create gradients. The only way I found to "fake it" is to create a series of lines or rectangles each with a unique color calculated with b.lerpColor.

I saw that the InDesign Object Model has of course the gradient class but I don't know how to access it using basiljs.

Maybe if someone could show me? Many thanks.


Source: (StackOverflow)

Syntax of b.startsWith() in basil.js

I was wondering how the syntax of the b.startsWith() function in basil.js is supposed to look.

I want to check all words of a text to see, if they start with the string 'some' (like 'sometimes', 'something', 'someone', 'somewhere' etc.).

So, I create a variable that passes on every word of my text to the b.startsWith() function.

When I put the string I am searching for in the brackets ( b.startsWith(some) ), then where exactly will I have to put the variable that will be checked if it starts with my 'some'-string?


Source: (StackOverflow)

How can I dynamically attach a scripting label to a newly created item in basil.js?

Is there a way to add scripting labels to PageItems that are created in code, i.e. without using the Scripting Label panel?

My code looks like this:

var tf = b.text("Hello World", 200, 200, 300, 300);

Source: (StackOverflow)

How can I gradually change font across a text frame in InDesign?

I would like to change the Typeface or Font Weight across a text frame gradually either by character, word, line, sentance or so on (basically any grep function).

I am generating (or interpolating) fonts so that I have a font family with the weights 1,2,3,4,5,6,7 which would change in the above fashion.

Unfortunately I do not have the scripting skills at the moment... Basil.JS looks promising though. Any help would be appreciated.


Source: (StackOverflow)

set display performance for document

If I set my display performance and run a basil.js script then basil seems to override my display performance settings.

What I would like at the end of the script is set the display performance settings to fast display.

Is this possible?


Source: (StackOverflow)

Can Basil.js use OSC to talk with other software?

Basil.js(basiljs.ch) uses processing like syntax to control javascript objects in Adobe's InDesign. I wonder whether there is or it is possible for Basil.js to talk with other tools through OSC. Please let me know! Thank you :)


Source: (StackOverflow)

How to apply a random font to a textbox by scripting InDesign?

I want to choose a random font from my installed fonts and apply it to a text box. I am using basil.js to facilitate coding.

I don't want to write a list of all available fonts by myself, like this:

var font = [];
font[0] = "Times New Roman";
font[1] = "Myriad Pro";
font[2] = "Impact";
b.textFont( font[Math.floor(Math.random()*font.length)] );     

(this idea is from: http://forums.adobe.com/thread/325180)

Many Thanks!


Source: (StackOverflow)

Does basil.js run with InDesign Version CS3?

I downloaded basil.js' bundle and installed it the way the installation guide told me. But running the example-scripts always fails.

It ist said there: JavaScript Error, Number 24, Line 7, Date.now is no function.

I reinstallend and installed again twice, checking if i connected and named the folders in the right way and everything seems to be ok.

Now I thought that maybe my InDesign-Version is just to old? I still work with CS3. Does anybody know about that?

Thank you Eva


Source: (StackOverflow)

How cut/crop an image and duplicate it in basil.js

I'm trying to do a script in basil.js to duplicate an image and cut/crop the image inside the frame. In the basil.js reference (http://basiljs.ch/reference/) I don't find a function to move the image inside the Indesign frame.

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

function draw() {

    for(var n=0; n<800; n+=100){
        for (var c=0; c<800; c+=100){
        var img = b.image('image-example.jpg', n, c, 100, 100);
        }
    }

}

b.go();

Anyone have an idea how do this with basil.js or java code ? Thanks

Ref: http://i.stack.imgur.com/qwWmK.jpg


Source: (StackOverflow)

get all methods and properties of an object

If I use (on a text frame):

b.selection().fit(FitOptions.frameToContent);

Then it works as expected, this means that the selected object has a fit method.

If I use:

for (var property in b.selection()) {
    b.println(property);
}

On the same selection then it doesn't print a fit method.

If I use this:

function getMethods(obj) {
  var result = [];
  for (var id in obj) {
    try {
      if (typeof(obj[id]) == "function") {
        result.push(id + ": " + obj[id].toString());
      }
    } catch (err) {
      result.push(id + ": inaccessible");
    }
  }
  return result;
}


b.println(getMethods(b.selection()));

Then I don't get the fit method either. And I would really like to know all methods and properties of the selected object. So how do i get them?


Source: (StackOverflow)

How to convert a .txt string to variables in basil.js?

I want to read a string of numbers from a .txt file on my harddrive, convert the numbers to variables in an array and draw circles with the numbers in the .txt file as radiuses.

This works fine in processing with code like this:

String[] numbers = loadStrings("data.txt"); 
radius = int(split(numbers[0], ',' ));

However, I can't get it to work in basil.js (and have been toying for a week). This is my closest attempt:

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

function draw() {   

var linesArray = b.loadString("males.txt");
data = int(b.split(linesArray[0], ',' ));

b.ellipse(200, 200, data[0], data[0]);
}

As far as I can tell, it failed to split the numbers in the .txt-file and store it in array.

This is my first post on stackoverflow, forgive my amateurism!

Edit: Here is the link to the txt-file, I want to convert into an array: http://whereverywhere.com/males.txt


Source: (StackOverflow)

How do i get noise to work in basil.js?

I dont manage to make b.noise work in basil.js. I allways get the error "ReferenceError: Uint8Array does not have a constructor". What am I doing wrong?

function draw() {  

var xoff = 0.0;
var xincrement = 0.01;

xoff += xincrement;
var n = b.noise(xoff);
b.println(n); 

}

b.go();

Source: (StackOverflow)