Git Product home page Git Product logo

basil.js's Introduction

basil.js

An attempt to port the spirit of the Processing visualization language to Adobe InDesign.

For tutorials, examples and documentation go to the official website: http://basiljs.ch. Follow us on twitter @basil_js for news and updates

Founders Ted Davis, Benedikt Groß, Ludwig Zeller

Contributors Philipp Adrian, be:screen GmbH, Ken Frederick, Stefan Landsbek, Timo Rychert, Fabian Morón Zirfas

basil.js was conceived and is generously supported by The Visual Communication Institute / The Basel School of Design Department of the Academy of Art and Design Basel (HGK FHNW)

http://thebaselschoolofdesign.ch

Please note: Big general parts e.g. random() of the basil.js source code are copy & paste of the fantasic processing.js by the Processing.js team. We would have had a hard time to figure all of that out on our own!

Supported Adobe InDesign versions: CS 5+

If you want use Sublime Text instead of Adobe's Extendscript Toolkit, use the buildscript here: [extras/Sublime Text/](extras/Sublime Text/)

basil.js's People

Contributors

b-g avatar fabiantheblind avatar ff6347 avatar ffd8 avatar frederickk avatar ludzeller avatar ph101pp avatar slandsbek avatar trych avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

basil.js's Issues

FAST_ENTIRE_SCRIPT: b.units() is broken

Calls to b.units() are still changing the units for basil.js, but some depending functions are not working anymore. I don't have an isolated example at hand, but please check the following ornaments generator. The program should fill the entire page. It does, if ENTIRE_SCRIPT is chosen instead. If the program is run again, the MM units are working properly, apparently since the default units stay changed then and are evaluated the next time...

includepath "~/Documents/;%USERPROFILE%Documents";

include "basiljs/bundle/basil.js";

function draw() {

var xCells = 30; // the amount of horizontal cells
var yCells = 30; // the amount of vertical rows
var center = false; // whether to center items in cells or not

// check if shapes is existing
if(b.items(b.layer("shapes")).length === 0) b.error("Nothing found on layer 'shapes'. Put something there first.");

b.units(b.MM);

var cellWidth = b.width / xCells; // calculate cell dimensions
var cellHeight = b.height / yCells;

for( var y = 0; y < yCells; y++) { // loop through rows

for( var x = 0; x < xCells; x++) { // loop through cells

  var shape = getRandomShape(); // get one of the shapes on the "shapes" layer, note that b. is not necessary for own functions

  b.layer("generated"); // set or create the layer "generated" as target

   b.rotate( b.random(b.TWO_PI / xCells) );  // set rotation for new item, 2 x Pi is a full rotation

//~ b.scale( 1.001 ); // set scaling for new item

  var newShape = b.duplicate(shape); // create a copy of the shape

  if(center == true) {
    // move new shape to position in the grid
    // cellHeight multiplied by y it gives the right y position. Same for the x axis.
    // add half of cell size to center in cell
    // substract half of object size to center at cell center
    b.itemX( newShape, cellWidth * x + cellWidth / 2 - b.bounds(newShape).width / 2 ); 
    b.itemY( newShape, cellHeight * y + cellHeight / 2 - b.bounds(newShape).height / 2 ); 
  } else {
    // without centering
    b.itemX( newShape, cellWidth * x ); 
    b.itemY( newShape, cellHeight * y ); 
  }

}

}

}

// this is a custom made function
function getRandomShape() {

var shapesLayer = b.layer("shapes"); // get the layer called "shapes"
var shapesItems = b.items(shapesLayer); // get all the items on that layer as an array

var randomIndex = b.floor(b.random( shapesItems.length )); // get a random number between 0 - shapesItems.length and round it down

return shapesItems[ randomIndex ]; // get the shape at the calculated random position in the array and return it

}

b.go(); // the actual starting point of the sketch, go() is calling the draw() function

b.addToStory() doesn't work in b.MODEHIDDEN

hi jörg,

could you look into this?

i always get this error if i try to call the b.addToStory() function while a script is in b.MODEHIDDEN ...

addtostorybug

i suppose the problem are the two lines in pub.addToStory():

app.select(itemOrString);
app.cut();

any idea how to get the functionality of the function working in b.MODEHIDDEN?

thanks + best,
benedikt

ps. here is a script which shows the issue (basically examples/document/story.jsx):

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

function draw() {
  // create two textframes
  var txtFrameA = b.text("hi this is txtFrameA! ",0,0,300,100);
  var txtFrameB = b.text("this is text from txtFrameB! ",100,150,300,100);
  b.println( b.storyCount() ); // 2, because we have two unlinked textframes, each has its own story

  // link both textframes into one story
  b.linkTextFrames(txtFrameA, txtFrameB);
  b.println( b.storyCount() ); // 1, because txtFrameB is now part of txtFrameA's story

  // add something to the story of txtFrameA
  for (var i = 0; i < 20; i++) {
    var tmpRect = b.rect(0,0,30,30); // position of rect is ignored
    b.addToStory(txtFrameA.parentStory, tmpRect);
    b.addToStory(txtFrameA.parentStory, " | ");
  };

  b.addToStory(txtFrameA.parentStory, " - and some text at the end --> ");

  // You can control the position of the insert via the last parameter. 
  // It accepts either an InsertionPoint or one the following constants: b.AT_BEGINNING and b.AT_END.
  b.addToStory(txtFrameA.parentStory, "<-- some text at the front - ", b.AT_BEGINNING);
}

// b.go();
b.go(b.MODEHIDDEN);

sublime build system error

Hi I tried running the sublime build system and i got this error while trying to build the script from sublime. /Users/admin/Library/Application Support/Sublime Text 2/Packages/Basiljs/run_idscript_6.0.scpt:151:199: execution error: Adobe InDesign CS6 got an error: I/O error (52)

Any idea what's wrong?

why was default pasteboardPrefs set?

Just realized via a few students that 1.08 introduced a change to their preferred pasteboardMargins [line 202 under setCurrDoc in core.js]:

currDoc.pasteboardPreferences.pasteboardMargins = ["1000pt", "1000pt"];

This wasn't there previously and messes up the layout/settings for some people who always have their custom prefs when working on files. They can try to override it within their script- but then that's extra code for every student to add, especially since I also noticed that it causes MAJOR gaps in the view of one page to the next because it's such a large distance.. one has to scroll for a long ways to reach next page. Why's it there.. does it need to be?

visual of issue:
twopages_basiljs_v108

b.arc does not create anything

I tried using the b.arcbut it does not create anything.

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

function draw(){
    var arc = b.arc(10, 10, 100,100,b.PI,b.HALF_PI, b.OPEN);
}

b.go();

b.MODEHIDDEN forgets current active page

  • create a document with 2 pages
  • go to page 2
  • draw something to the page e.g.:
#includepath "~/Documents/;%USERPROFILE%Documents";
#include "basiljs/bundle/basil.js";

function draw() {
  b.rect(0,0,300,300);
}

// b.go();
// b.go(b.MODESILENT);
b.go(b.MODEHIDDEN);

running the script with b.go() or b.go(b.MODESILENT) will draw the rect to page 2, whereas b.go(b.MODEHIDDEN) to page 1 :(

@bescreen could you look into this?

performance issues..?

when trying to run a code over 10 pages that contains b.lines + b.words over large text blocks, it was going fine for the first 3 pages then slows to a CRAWL. i had also tried disabling the redraw:

app.scriptPreferences.enableRedraw = false;

but that still didn't help, which leads me to believe it is with this undo history we are storing? perhaps that is really eating away the ram and slowing to a crawl after adding x thousand lines..

i'll have a look into this - and hope it's that buffer, which should be disabled when ready to process LOTS.

Questions on Basil.js

Here there guys. I've been working with Basil for the last month and I was thinking of incorporating it deeper into my next seminar. I have some questions though:

  • How do I disable the error handling? It is great for beginners to not have the std ID error messages but to pinpoint problems it makes it harder.
  • How do you test new features before merging them into master? It would be great to have some guidance for developers.
  • Is there a roadmap for basil? Where is it heading?
  • Are you still using it in your curriculum?

Last but not least. You did a awesome job with it. 👍 Great work.

Image placing with only x coordinate does not work as expected

As mentioned in issue #26 placing an image file (or .ai) does not work when using just the x coordinate as parameter.

#includepath "~/Documents/;%USERPROFILE%Documents";
#include "basiljs/bundle/basil.js";
function draw() {
  //b.image("test.png",0); // does not work as expected 0 should be x of newly created container
  b.image("test.ai", 0, 0, 100, 100); // works as expected
  var rect = b.rect(0, 100, 100, 100); // create a rectangle to place the image in
  b.image("test.ai", rect); // works as expected
}
b.go();

Attached is a test setup for this.
basil-place-ai-file.zip

b.clear() also for objects?

i think we should allow obj's to be thrown into b.clear() - because at the moment, the only way to get rid of an object is to use the native indesign obj.remove(); <- which is quite different than our own method.

basil.js image api doesn't allow importing of vector files

It would be really great to be able to import and place images that are vectorized, such as SVG (or .ai files directly) with the image API. Is that possible? I haven't been able to do so and can't quite parse the InDesign docs for instructions on doing so.

Thanks!

basil.js doesn't work in osx 10.10 (and InDesign CC)

When I create the alias in "Script Panel"-Folder. Indesign displays it as following.
screen shot 2014-11-27 at 09 49 25
Hovering above it reveals: "The file is not executable by any supported script language".
I guess Indesign or the OS (Mac OS Yosemite 10.10 in my case) don't support paths via Aliases properly.

My hackaround was to add the "basil.js"-folder into the "Documents"-folder, as well as into Indesign's scripting folder – However even then not everything was working.

Enabling code linting?

When writing scripts I normally use eslint with the Sublime linter package for it. I also use the Sublime Text CodeFormatter. Together they make up a strict and continuous coding style. Now a problem for eslint is the ExtendScript #include 'path/to/file' statement. It breaks the parsing. Fortunately there is an undocumented feature in ExtendScript for a different include statement:

//@include 'path/to/file';

Or

// @include 'path/to/file';

Or even

//@include 'path/to/file';

Also the target application can be set like this.

//@target 'InDesign';

This would allow:

  • to run eslint against user scripts
  • to run eslint against the Basil source
  • to enforce a strict coding style by adding a .eslintrc to the repo which contains rules suited for Basil.

The next step would be running eslint against the whole project(examples and core). Be aware that this might change a lot of the current formatting. So I would do that but only if you guys want this to happen.

First question for doing this is:

  • single or double quotes? (It's some kind of religion 😏) I use single quotes. Throughout Basil there are double quotes. Single quotes make embedding double quotes for messages much easier.

How to approach the refactoring?

I think the best way would be formatting it file by file and test if nothing breaks.

I would create a PR for each file.

b.download + /data folder

the b.download function rocks! but i just ran into one issue. similar to the style of b.saveStrings - it is by default downloading the file in the same folder as the indesign file.. however once you want to use the image with b.image - it's by default searching for the /data dir - if you don't save the image with /data - then you'll never find it = shouldn't that be the base location? if someone wants to get more organized and sort images into special folders like "trees/tree_01.jpg" for the path, then the end path is actually "data/trees/tree_01.jpg" - and they can grab the image by using b.image("trees/tree_01.jpg", 0, 0);

Otherwise, awesome work and time to create a book from EVERY google image...

Windows Support

It looks like all the include paths are for OSX. Any easy way to get it to run on Windows?

ES6 support?

Rewrite Basil to be real ES6 modules. Can be done using ExtendScript/extendscriptr. The user would still write plain old ExtendScript but Basil itself would be easier to handle

set and get object properties

There should be an easy way to set and get properties of an object. it makes no sense to implement a own getter and setter for all the things you can do in InDesign but there needs to be a way to set things like the pageWidth with a simple call. e.g.

b.property(b.doc(), "pageWidth", value);

and

b.property(b.doc(), "pageWidth");

The biggest challenge is the nesting of these properties. The InDesign API call is

app.activeDocument.documentPreferences.pageWidth

How do I correctly set up basil.js for development?

Hi there,
so I would like to start contributing now, however, as I am new to Github, I have issues, at wrapping my head around how to set it up correctly. I read the Wiki, I forked and then cloned the project to my local drive, and set it up in Sublime, that all works fine.

However, what I do not understand: Do I have to install my "development version" of basil.js alongside the regularly installed version or do I have to install it instead of the regularly installed version? Specifically, I do not understand how to hook up my cloned version into InDesign in a way that I can run any basil scripts. As they all require the basil.js file to sit exactly at USER_FOLDER/Documents/basiljs/bundle/basil.js, how does this work with my cloned repository (which is by default a folder named basil.js that does not contain a bundle folder, i.e. the result is that the basil.js file is not at USER_FOLDER/Documents/basiljs/bundle/basil.js)?

tldr: Since my "development basil.js" file is not at USER_FOLDER/Documents/basiljs/bundle/basil.js, I cannot run any of my "development basil.js" scripts, so how do I work around that?

Thanks!

Edit: This all refers to OS X, in case that matters.

b.typo() doesn't work as getter

hi stefan, could yo please quickly look into it. the typo function is your masterpiece ... use this for reproducing the prob:

includepath "~/Documents/;%USERPROFILE%Documents";

include "basiljs/bundle/basil.js";

function draw() {
var t = b.text("hi!", 50,50,50,50);
b.println( b.typo(t, "appliedFont") );

}

b.go();

changing document from portret to landscape gives offset problems.

I have quite a lot of code and no time to isolate the problem.
Thing is, i have a master page with content, i changed the format.
If i run the script the master pages get unlocked but they have a huge offset.

I could provide the whole script if you want or wait 8 weeks and isolate it then.

Just a little nitpick in terms of credit

Hi, I was looking at basil.js (congrats!), but noticed this line

https://github.com/basiljs/basil.js/blob/master/basil.js#L29

We keep running into this... yes, John did a proof of concept of it back in 2009 (with the help of Al McDonald, at the time working at Bocoup) and then left it at that. It was a minimal implementation of parts of the Processing API, and wouldn't be anywhere near web-useful, just a neat project, if it'd been shelved. John went on to work on other things. He only recently came back to using Processing(.js), but only as a user, due to his involvement with the Khan Academy.

The real driving force behind Processing.js has been Seneca college picking up the project and making students of David Humphrey's open source course work on the code, leading to a team of developers (most from Seneca, some volunteer contributers) that worked on Processing.js over the last four years. It'd be nice to get recognition for all the effort we put in to make Pjs a useful library, rather than seeing people credit John =(

  • Mike "Pomax" Kamermans
    Pjs developer

Possible roadmap additions / feature suggestions

Hi there,
as this is getting lively here, I would like to add some ideas for the road map that I collected. I probably forgot a few now, but no harm in adding them later, once I remember them. ;)

(And yes, I know we want to get rid of the b. , but as long as it's still there, I'll use it here ;) )

  1. b.collides(object, object) -> Collision detection between two objects. I know there is several levels of collision detection from detection of bounding box collision to collision of more complex shapes to collision of several glyphs. I could imagine that this could be implemented in a simple way in the beginning and then become more complex and advanced over time, if somebody wants to give it a try. Could also work to hold arrays of objects instead of just an object.

  2. b.spreadWidth -> to return the spread width, no matter how many pages the spread contains

  3. b.interpolateShape(object1, object2, interpolationValue) -> interpolates the path points of a shape or path to a certain value and creates a new interpolated object. I am not sure, how easily objects with a different amount of path points could be interpolated, but maybe this can be done in several steps as well. First allow interpolation of objects with the same amount of path points only, and then later, if somebody wants to tackle it, do a more advanced interpolation. This should allow for extrapolation as well of course.

  4. b.beginLog() -> could write all b.print() and b.println() statements that follow to a log_YYYYMMDD_HHMMSS.txt file next to the document. This makes debugging easier for beginners, as they can compare logs to each other and they can also more conveniently send their logs to others for debugging help

  5. b.startTimer(timerName), b.takeTime(timerName) -> starts a timer with a certain name and takes the time of this timer. This could be a great learning tool for beginners, as they can learn how changes in their code influence the time that stuff takes. My first steps with basil.js (and with scripting in general) lead to a few scripts that would run for hours or even days. With such a tool this risk could be minimized. ;)

  6. generally I think there should be more example scripts and the scripts should be more consistent. I think there should be a sample script for EVERY single method from the reference. As a beginner, I remember, I had to poke around a lot and often thought it would be great to have more sample scripts. I would be willing to have a closer look at this to define what "more consistent" could mean and then to come up with some missing sample scripts. As I am totally new to Github, I think this might be a good place for me to start to learn about the Github workflow.

  7. fix that every time a basil.js script is run, the past board becomes overly large. I am not sure, why this is handled in such a way? Is this a feature? Is it there to prevent objects leaving the pasteboard area? All I know it gets really annoying for documents with more than one spread, you can't really navigate them that easily anymore. Could somebody tell me what the purpose of this enlargement of the past board is? :)

  8. Generally I have the feeling there could be more "book related" functions (as in: stuff that does not only happen on one page, but continues over several spreads). I believe that since the project was inspired by Processing that this was not the main focus, but as InDesign offers this possibility, we should include some "book related features". Problem is, I remember that I had some ideas about that in the past, but I forgot them all now. So for now, I will keep looking for them and update you, once I remember what I was thinking. ;)

Any thoughts on these ideas?

Thanks!
trych

replacing #includes with @includes

This should also be an own issue. Does not need any work from your side right now. Just for reference and further discussion. See also #33 #34

pros:

  • allows usage of linters
  • is JS style

cons:

  • would need to refactor all the examples if we want consistency in the whole project

items is twice to much for images

If I place rectangles for example it's fine.
If I place images i always have twice as much.

    var items = b.items(b.layer("s_images"));
    b.println("items.length: "+items.length);

I think it both reports the content and the frame.

MAX_FLOAT etc

It would be nice to have b.MAX_FLOAT, b.MIN_FLOAT etc. to be a bit more equal to processing.

progressPanel makes indesign become a stroboscope disco

seems something wrong with the update ...

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

function draw() {
  b.println('hello');
  for (var i = 0; i < 100; i++) {
    b.println(i+' '+b.random());
  };
  b.println('done');
}

b.go(b.MODESILENT);

savePDF() and filePath() not working properly

The following code does not work. app.activeDocument.filePath() returns spaces as "%20" encoded and references the user home as "~" in the beginning. Unfortunately, app.activeDocument.exportFile(ExportFormat.PDF_TYPE, myFile) does not accept this notation.

Goal: Being able export a PDF next to the InDesign document.

include "../../basil.js/basil.js";

var width = 100;
var height = 100;

function draw(){
b.units(b.MM);
b.text( "hello world", b.width / 2 - width / 2, b.height / 2 - height / 2, width, height );
savePDF(app.activeDocument.filePath + "/test.pdf");
}

function savePDF(myFile){
b.println(myFile);
app.activeDocument.exportFile(ExportFormat.PDF_TYPE, myFile);
}

b.go();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.