Tutorial :database use with ExtendScript (for Adobe Illustrator)



Question:

I want to refactor a VB program into ExtendScript to automate some drawing in Adobe Illustrator CS4, but have a requirement to read from a database. Is it possible to read from a database using ExtendScript? How?


Solution:1

yeah, ES can read CSVs. just format your database using comma delineation.

here is a function that should do the trick:

function readPref (thePath) {      if (File(thePath).exists == true) {        var file = File(thePath);      file.open("r");      file.encoding= 'BINARY';      var theText = file.read();      file.close();      return String(theText).split(",")        }  };  

should return an array with what you need. have VB export a database and just use that to read it. donezo.


Solution:2

Illustrator scripting engine doesn't provided any mechanism to read external data directly, but you have several ways to do this...

  1. Write an external program which connecting database to generate VB script, and use Illustrator to exec the 'generated' script, which is the old way I have done.
  2. The new ScriptUI since cs3 provides to open a Window, containing a flash swf as a interface to drive Illustrator JS engine. You can read xml, call webservices, Flash Remoting inside flash content. I am not sure if you are comfortable to these toolsets.


Solution:3

I have a bit of a different solution I have been using successfully : Create a webservice that has access to your DB and then from ExtendScript use http connection to consume the services (and from there on you can do pretty much whatever you'd like).


Solution:4

My understanding is that you would need to use ExtendScript to 'doScript()' with your VB code. ExtendScript doesn't have any real database connection of its own. But I'm familiar with people that have VB code to connect to databases and return results. ExtendScript has that doScript method to run the VB code. The trick, it seams, is to find a way to get the data back to ExtendScript to tell the Adobe applications what to do. .doScript doesn't, to my knowledge, have a nice way to accept the results of the embedded code. So what I've heard people do is one of several things:

  • Have the VB code write a text file that the ExtendScript code can read and parse.
  • Have the VB code add a 'ScriptLabel' to your Adobe Illustrator document. Then use ExtendScript to read that same label. This is really the same as writing a text file, but there just isn't a file.

HTH

Jon S. Winters, ExtendScript Support, electronic publishing support


Solution:5

Whether or not you need to refactor VB to ExtendScript 100% (no VB code, all ExtendScript), I would say the simplest solution is something like this:

Have a VB/VBScript wrapper that calls ExtendScript, and this wrapper handles the database interaction and passes the data back & forth to ExtendScript. This allows you to keep the database code simple reusing what you have in VB and keep the ExtendScript simple.

You can call ExtendScript from VB/VBScript using the Adobe app's COM API, which has all the methods for drawing that you get from ExtendScript plus doJavascript() method for executing javascript (or more realistically ExtendScript) code. This same doJavascript() method can be used to pull in ExtendScript JSX files rather than a snippet of javscript code. You can find more details in a related SO post:

Is it possible to execute JSX scripts from outside ExtendScript?

look at the answers that are Windows specific. Taking this question & solution further it can work for other platforms as well (Mac, Python, Perl, etc.) it doesn't have to be for VB and Windows, the same approach can be used to interact with ExtendScript externally via COM on Windows or Applescript on Mac, and that will work with any language that is COM/Applescript compatible (or interfacing).


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »