manage paths in Adobe Extend-Script

Adobe Exten-Script (source: internet)
Adobe Exten-Script (source: internet)

Managing paths obtained from Adobe Extend-Script, Specially when you want to share these paths with an external 3th application (to do things which aren’t possible with just ExtendScript) is kind of difficult!
For instance let’s say we want to get the Path of an In-Design file being opened (and in front) in in-Design, we may simply do:

And get:


But there is obviously 3 (+1 not obvious here!) possible problems with this path (even if you can transfer that variable as easily as shout it out in an alert! look at #3):

  1. the Tilde (~) character at the beginning, an environment variable meaning “Home Directory“, which is not a recognizable standard character in all the different programing environments (for instance it’d be %~dp0 in Batch scripting and user.home, (more or less!) in Java) although it is supposed to be the absolute path using above code!
  2. existence of Slash characters (/) in the path instead of Backslash (\), making it hard (not so much tho!) to send it through a JSON package for example (or save it in a batch file -again- for instance), be-cause in most environments it’d be considered as a escape character and not a path level separator.
  3. It is an object and not a string (apparently!) and you can send, save or sometimes even use the myPath variable for instance directly! (it will give you an [object] instead of the path, which I guess should be the parent File object itself)
  4. in addition if our file wasn’t in our Desktop folder and was in a disk drive instead, we would have this problem too:

    as you can see, an additional Slash character (/) before the Drive letter (c)! which is incomprehensible to me why it is!! but it seems that Extend-Script itself doesn’t have any problem with it, but as I said when you want o communicate with 3th party apps it will become a problem immediately!

  5.     So as you may guess there is a lot of solutions for any and each of mentioned problems, but here I just wanted to suggest the most convenient one I figured out after trying a lot of different shenanigan techniques!
    Here we used Regular Expression Patterns to Replace() all (by using the g pseudo) the Slashes with Backslashes and by using fsName instead of filePath eliminating other problems (like getting “relative paths” (or fake absolutes!) instead of absolutes and the beginning slash character)
    And the result:

    alert(app.activeDocument.fullName.parent.fsName).toString().replace(/\\/g, '/');
    alert(app.activeDocument.fullName.parent.fsName).toString().replace(/\\/g, ‘/’);

    Awesome! 😀
    Please let me know if you have a better idea to this or if you see a problem or something, I appreciate it 😉

working with measurement units in adobe extendScript

measurement_units (img from internet)
measurement_units (img from internet)

While working with Adobe ExtendScript to extend Adobe CS features (through scripts and/or plugins), there is a good chance you need to get or set an elements dimensions (document dimensions for instance).
When you ask the Software about the dimensions, it will give you back a number, but this number could be in a lot of different units (Points, Picas, Inches, Inches Decimal, Millimeters, Centimeters, Ciceros, Agates, Pixels, etc.) and it’s gonna be the same when you set a number as well.
There is a lot of different ways to handle this issue, like getting the unit as well and trying to convert them etc. but it may add a huge overload on your code, your time and a lot of unnecessary complexity which can make your code harder to debug as-well.

Here I’ll put a simple solution I use in my own codes which may come helpful to you too (This code is written for In-design but should work less or more for the whole CS collection -maybe with a bit of tweaking- ):

I just get the current document units (for both Vertical and Horizontal measurement units in In-Design), keep them in a (pair of) variable(s) (I check to see if the variable is defined before and set it if it isn’t defined already, doing this we can be sure that even if we forgot to remove the vars later on, we don’t set them to our newly defined units again), change the units (for the whole document) and run my code and then when I was done with it change it back to original units and remove the created variables.
I found this technique to be the easiest, cleanest, fastest and the most performant way to handle the units issue in extend-script.

Here is the simple code I use; two functions, one to run before the main script and one when the script was done to set everything back to what they were before we run the script:

Note: here I use the very front document but you can easily pass desired document to the function through an argument as well.

A Simple Spatial Hashing (HashGrid) for processing-2

download, contribute or fork this project here!

SPatial Hash Grid System
Testing the functionality of the class

Continuing from our last post, We were just ready to create our grid “buckets”!
Buckets are small rectangles forming the grid; objects corresponding to each bucket location will be saved (a reference to them) in that bucket.
To create buckets (and our grid) we need to divide the size of our target canvas (it can be our stage size or a virtual stage) to create smaller rectangles, then we will need just to check each object against other objects only in the same bucket or neighbor buckets which will dramatically reduce the required number of iterations. but it’s important to decide about the bucket sizes according to our needs (number of objects, desired distance to check…) and since variables affecting or decision here aren’t constant, it’s better to make it flexible so we can decide about the bucket size later! we will start with defining a float variable that will dictate desired size of our bucket to the class, if it’s not defined when calling the class it can be created automatically according to number of objects and requested distance check etc. but for now … let’s keep simple!
Also, we would want (I imagine at this point) two methods:
1. obj.set() –> Objects will declare their position to class and get referenced in corresponding buckets.
2. obj.get() –> which will return an array of references in all the neighbors in the  requested distance.

Here to check the functionality of our Spatial hash grid class I’ll use a simple class I wrote before, which just generates bunch of random point objects on the stage, so we can put our class under some definable load, the Points class is simple (and anyway not the subject of this topic, but let me know if you want know more about it!):

So! here is the structure of our HashGrid class:
Here we just declared the class and bunch of variables and methods we know we’re gonna need.
There is also a displayGrid() function that will just draw our grid for us on the display so it’d be easier to understand and to debug.
But we have defined another class inside the HashGrid class as well (a nested class) near the end of this code snippet, Buckets class. that’s because in Java you should define the array type in declaration time and since our array will keep reference to Objects and there is not such a primitive called “Object” you need to define the object to be able to declare an array of that kine of objects, so we create a nested class called buckets to keep our bucket arrays and an array of our buckets in it!
Also you may notice that I hard coded another object type in my HashGrid class (The Points) which is not the best practice since we want to be able to use this class everywhere with no modifications, but for now and to keep it as simple as possible we are gonna leave it like that, but later on (in another post hopefully if I could) we will make it more abstract by using an interface or some other techniques.

Now we need to create an array of buckets, create an array in each bucket (to keep our object references) and populate our set() and get() functions:
Now our HashGrid class is all functional! awesome! but there is a few things still we need to do, some of them are relatively easy to implement, like adding the functionality to be able to define the desired distance to check (checking neighbors as well as the bucket itself) and also the Interface, we are gonna work on these later-on (hopefully!) in another post. But now to test our class we can create a new processing file (tab) and put this code on it:
Yep! it works! you can download, contribute or fork the whole project here at Github:

Fête de la Musique 2014 – Paris!

It was 21 June of 2012, when I was already packed my small world in my big back-pack to get in the night-train and go back to Paris from my short, 3 days trip, to Toulouse (a trip for a small meeting with people at ESMA (Ecole supérieure des métiers artistiques), campus Toulouse).

I remember the date because (without me knowing it) it was a special date! It was Fête de la Musique and it was awesome! I got out from the small youth hostel (La Petite Auberge de Saint-Sernin) I had for two nights, at noon and decided to just wonder around and visit the beautiful city of Toulouse till midnight when I had a night train to Paris at around 1 AM. it was a very hot day at Toulouse and despite the beautiful architecture and all the red bricks and of course  kind people from Toulouse ( Les Toulousaines! ) I was really ready for the day to end and get in the train!

But, by the beginning of evening, the face of the city start to change! streets were being crowded and sounds started to raise! this transformation happened so fast that I didn’t understand how I got between thousands of people and hundreds of bands playing and dancing in every corner of the city!
That afternoon I had a lot of fun and even made a few good friends! it was so fun and it gone so fast that I was regretting the fact that I had to leave a bit before the very last minute of the event to get in the train station!

It was my first experience in Fête de la musique and it happened that I was in Toulouse but in train I was wondering how it could have been in Paris if it was this much fun in Toulouse?!!
Well… I got my answer 2 years later! last night! 21 June of 2014! Fête de la musique in Paris!

I should say that it was incredible and awesome, but…, I don’t know if my expectations were high or… I just feel it was a little bit more awesome (!) in Toulouse! but you should definitely try to be in France for fête de la musique! it is soooo goood! 😀
Anyway! here you can see a little video I made, filming a few bands who were playing last night in Paris at the top of this post, and also you can find some of the videos I took of that night in Toulouse! here, and here and here and here and here and here and here and here and here and here!!! brrrrrr!!! :/

Bon fête de la musique everybody! 😉


Ah! by the way I finished the spatial hash grid class and I’ll post it up in first chance! 😉

A Simple Spatial Hashing (HashGrid) for processing-1

Spatial HashGrid projected on a sphere
Image Source: Wikimedia.

While working on bunch of sketches to create visuals for one of my documents, I was thinking to implement it with a simple Spatial Hash grid, but since performance wasn’t that important in that particular project, I just did it the simple way (checking every node against all the others in each iteration which means —> n² checks / frame (90K check for 300 prticle points for example!)) and it worked just fine! but strangely enaugh it was bothering me that I didn’t do it the right way! and since I’m gonna to reuse the code in another projects for sure and since I’ll need to implement this technique anyway sooner or later in one of my “things”! I tried to give it a try and do it the “right way”.
I started by just thinking and trying to analyze the way I’d imagine it works, I wanted something simple and minimal, so I did bunch of sketches on paper like these one (which probably make sense just to myself!):

Spatial hash first sketches
primitive sketches on paper to define spatial grid I wanted to have to myself!

The concept behind spatial grids is simple: you keep track of each target object by keeping a reference to that object in the grid bucket beneath it (in a 2D scenario (which is expandable to a 3D one respectivly easy)), so each bucket is an array of references to objects located on that bucket’s position (on the grid), of course it can be further developed I think to a more efficient algorithm combining a quad-tree system for scenarios where objects are placed mostly not evenly on the grid ( buckets will have a limit size (let’s say 3) and then (if there is more than 3 objects located there) they’ll divide to 4 buckets…), but we don’t need that here since my objects will be scattered on space by a random perlin noise algorithm (almost evenly placed on enough large spaces). Doing a bit of research I found out some interesting libraries which would do the job just fine, like HashGrid class in giCentre Utiles library:

hashGrid = new HashGrid(width,height,10);

But first of all, I wanted it to be simple and just do a few things that I need it to do and secondly (and more important for me) I wanted to do it myself so I’d understand it and I’d be able to use the technique whenever and wherever (let’s say in my simple JS Canvas game) I wanted to, and all in all it looked like easy to implement! (surly enough, just to do the basic and probably not in the best way possible?!) So anyway I started to write the class:
(Ah btw, unfortunately, their source code is not available to public! (just a broken link on their Google repo site) and I didn’t find any other essay to do this on internet so I was (or am) pretty much on myself to figure it out! wish me luck!)

class HashGrid{
// It is just a simple class declaration so far!
 HashGrid(/*defined vars*/){
// constructor

To keep reference to objects there is ArrayList class/ interface available in JAVA (and Processing) which is very convenient since it resizes dynamically according to the number of objects in it, but is slower than a simple array of objects, so it’d be better if we can have simple arrays but then we should think about a mechanism to add AND remove (There is a confusion for me though since in Java these methods doesn’t exist! but apparently they exist in Processing (as it explain in the reference page: Decreases an array by one element and returns the shortened array. (Also look at this snippet))) (EDIT: I further investigated this issue and found out that (as I guessed) the append and shorten methodes in processing are pretty ineficient and actually just create a new array, with one member more or less and copy the old one to it, and don’t respect Java specs, all in all, seems better to avoid them (after all we can do the same thing if we need and keep the code more reusable in another Java envirenment)) items manually to and from the array (which happens automatically using ArrayList) but due to Java Array limitations the length of Array can not be changed, … since our concern is performance here (that’s why we want to create a hashGrid in the first place!) we should obviously go with standard arrays. (I’ll make this decision later on, be cause although Arrays are faster but: 1.we need to allocate a considerable amount of memory to them either we use that space or not, and 2. it may bring more and in-neccesary complexity to the process when we need to itterate each bucket array to get references to objects… (EDIT: it turned out that it wasn’t that complicated! so I used simple Arrays finally, Although I guess other implementations, including the GiCentre Utiles, are using arrayLists, so I guess my methode should be a lot faster than other ones specially when the number of elements is higher) ), let’s go and start by creating out buckets:

. . .

Auto generated cover page using Processing

An auto generated Cover Page (using processing)
An auto generated Cover Page (using processing)

Here is a gist of the code (Processing sketch) I used to create the auto-generated cover pages for the business plan I was talking about for Paris Incubators , feel free to check it out, use it or modify it if you want to and leave in comments any questions you might have! 😉


The Gist:




PS: I recommend this site/ program to ppl like myself who are interested in Processing and data-visualization both! I may talk about them later on as well! 😉

You need a plan to write a business plan!

Grand Paris Project (Europa City)
Grand Paris Project (Europa City), Souce:

So Paris Incubators and Paris Region-lab and one of my good teacher/friends, Michel Agnola, wanted me to write a business plan to participate to their consours  of innovative start-ups in the region of Ile-de-France with one of my projects, Animetro which was one of my proposals to the team of new developments of the city of Paris in the super-project of Grand-Paris and my main project of my Masters 2 program in Paris 8 university!


So far, so good, but hey! what’s a business plan?!
To be honest it isn’t my first time writing a business plan, I did it bunch of times for different projects, some of them successful and other ones not so much, so I may be able to do it again; but this one have to be way smaller! something between 2-5 pages maximum! (they said 2-3 which I guess means 5 max in french! 😀 ); and I have just a few days to do it (3 days to be precise).

So I did a bit research to get inspired (and clear my mind from other project which I was working on for a while!) and start and since you need to know what exactly you need to do before starting to do it! here it is the results of my thoughts about how to write a quick and effective business plan: (work in progress)

You need a plan to write a business plan:

– keep it short
– keep it direct
– make it beautiful!
– make it for yourself!!

– Keep it short:
Because of the expansion of the universe, nowadays, time goes faster and yesterdays one day goes as fast as 1 hour in today’s time! and as a result, nobody has time to read your master-piece book of the legend of business planes and if you write it in hundreds of pages you won’t surly help them to be enough courageous to even open it!

– keep it direct:
be straight forward, give them what they need, nothing more, nothing less, (if you don’t know what they’d need look at the 4th item in this list: make it for yourself!!), don’t lie, write it for someone who doesn’t know what you are talking about (no abbreviations, no super-technical terms, no complex formulas and charts, no code!)

– Keep it beautiful!
Com’on! it’s! it doesn’t matter really anymore in which sector you work, your business proposal should have the minimum standards of visual aesthetics to be considered just readable and taken seriously! use simple charts, don’t fill the pages with long paragraphs, have a clear and logic sectioning in the document (starting from a short introduction (executive summary) to market strategy and analysis etc.)

– Write it to yourself!
Put yourself in the investers shoes (or whoever you are sending your business-plan to)! would you become interested to invest on your project just by reading current business-plane? … if your answer was immediately yes! throw it away and just ask somebody else write a new one for you, otherwise see how you can improve it to make it more interesting for yourself!


I’ll update this post later with my progress on it! 😛

1and1’s version of version control systemes (like git)!



It is just ridiculous!

1and1 is advertising preinstalled git SCM on their shared servers now for a while, but their version of this version control system is just unbelievably nonsensical (even sometimes stupid!)!

Problems with 1&1:

  • there would be JUST ONE SSH available for your WHOLE Package! that means even if you host 12 websites with them you’ll have 1 and only 1 SSH which have access to EVERYTHING, EVERYWHERE in your server!! which means:
    • you can’t work with anybody else on your git projects except if you give them access to your WHOLE server to just be able to push or even pull to one repository!! Whats funny is that they tell you to do this if you want to work with other developers, on their “git” page!!! (Just UNBELIEVABLE!),
      I have the french version tho (another funny things about 1&1 is that you can’t change your CP Language! supper annoying!)

      1and1 git horrible suggestion!!!
      it is the worst thing a hosting company can say to their customers!
    • even if you want to have “single user” git (!), most certainly you don’t want that user (even if it’s yourself) have root access! which means taking a big, unnecessary risk to accidentally do something everywhere in your server rather than in your repository (I won’t give such an access even to myself, meaning having root access to work on a directory!) this makes it even more scary if you have several domains hosted with them and horrifying if some of those are for your clients!
    • you can’t have a git web interface for your git!
    • having a git with no possibility of contribution (of more than one user) is like having a big bus with no door or windows! then it’d be more like putting yourself in a moving jail in form of a bus!
  • No sudo is availale in 1and1
    • in contrary (to have SSH root access) you don’t have access to your root super user, No sudo in 1and1
    • that means you can’t have a lot of good/useful stuff available normally to a web-master, a good git interface to call one! and no, you can’t enable/install it!
    • this would really limit your options in certain level when you want to have something which is not available by default in their servers
    • using SSH is ridiculously useless then except of using this more ridicule version of single-user git since you can’t do anything more than you can using ftp!!
  • It is just ridiculous! the way they think (if they do by any chance) is really bizarre and incomprehensible, why would you do this? why 1and1?!!! It is just ridiculous, nonsense logic!

Anyway, unfortunately if you happened to caught in their servers too for the moment your one and only option to have a private git on your personal server is to not have it!
but fortunately there is some alternatives still, for example if you work with a small team (up to 5 person) you can have unlimited repos in Bitbucket, or if you can afford it you’ll be able to find lots of paid options (git-hub enterprise namely or Bit-bucket itself again or paid options in

Fair well and watch for 1&1!