3

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?

  • Do you really need to convert the VB code to ExtendScript? If that's not a fixed requirement, the easiest alternative is to actually use the Adobe Illustrator CS4 COM API, which is roughly the same API available to ExtendScript. Taking this approach you do all the drawing via the COM API rather than the ExtendScript API command equivalents and can stick with VB/VBScript, and thus still retain ability to work with database from VB. Note that for whatever reason, Adobe labels the (API) scripting reference as for "VBScript" rather than "COM". – David Apr 14 '15 at 21:51

5 Answers5

4

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.

Lukasz
  • 926
  • 3
  • 14
  • 22
  • please consider up voting or accepting this answer if this is sufficient answer. – Lukasz May 07 '12 at 17:38
  • FYI, this may also be helpful for reading CSV in ExtendScript: https://github.com/fabiantheblind/extendscript.csv – David Apr 14 '15 at 21:46
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.
  • do you have any more information or links about your second method? – Brian Boatright Jul 28 '09 at 05:09
  • yes it does, you can do HTTP request http://old.code.zhdk.ch/projects/CERNRepository/browser/eBulletin/Submission/InDesignJS/HttpLibrary.jsx or you can read a file locally as CSV – Lukasz Apr 27 '12 at 02:28
  • I just wanted to point out, that by scripting engine, we mean the native ExtendScript engine for Adobe apps. Because all the Adobe apps (on Windows) also expose a COM API/engine that can be used by VBScript, and other COM compatible languages. Although we don't know if the OP specifically needed ExtendScript only option. – David Apr 14 '15 at 21:53
2

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).

Adi
  • 21
  • 1
1

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

  • I'm a bit confused about this option, although I overlooked it earlier. Which scripting engine for Adobe/ExtendScript is this for? I notice looking at Illustrator CS6 scripting reference docs, that doScript is available to VBScript and Applescript, and that for VBScript there is do doJavascript (to execute ExtendScript code). ExtendScript which is typically Javascript (for Adobe apps) did not mention doScript() in the docs. Which doc mentions this? Or did you mean something else to clarify? – David Apr 14 '15 at 21:44
0

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).

Community
  • 1
  • 1
David
  • 3,223
  • 3
  • 29
  • 41