与 ExtendScript 一起使用数据库(适用于 Adobe Illustrator)
我想将 VB 程序重构为 ExtendScript,以自动在 Adobe Illustrator CS4 中进行一些绘图,但需要从数据库中读取数据。 是否可以使用 ExtendScript 从数据库中读取数据? 如何?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
是的,ES 可以读取 CSV。 只需使用逗号分隔格式化数据库即可。
这是一个应该可以解决问题的函数:
应该返回一个包含您需要的数组。 让 VB 导出一个数据库并用它来读取它。 多涅佐。
yeah, ES can read CSVs. just format your database using comma delineation.
here is a function that should do the trick:
should return an array with what you need. have VB export a database and just use that to read it. donezo.
Illustrator脚本引擎没有提供任何直接读取外部数据的机制,但是您有几种方法可以做到这一点...
Illustrator scripting engine doesn't provided any mechanism to read external data directly, but you have several ways to do this...
我已经成功使用了一些不同的解决方案:
创建一个可以访问您的数据库的 Web 服务,然后从 ExtendScript 使用 http 连接来使用服务(从那里开始您几乎可以做任何您想做的事情)。
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).
我的理解是,您需要在 VB 代码中使用 ExtendScript 来“doScript()”。 ExtendScript 本身没有任何真正的数据库连接。 但我熟悉有 VB 代码来连接数据库并返回结果的人。 ExtendScript 有 doScript 方法来运行 VB 代码。 看起来,诀窍是找到一种方法将数据返回到 ExtendScript,以告诉 Adobe 应用程序要做什么。 据我所知,.doScript 没有一个很好的方法来接受嵌入代码的结果。 因此,我听说人们所做的是以下几件事之一:
乔恩·S·温特斯(HTH
Jon S. Winters),
扩展脚本支持,
电子出版支持
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:
HTH
Jon S. Winters,
ExtendScript Support,
electronic publishing support
无论您是否需要将 VB 重构为 100% ExtendScript(没有 VB 代码,全部是 ExtendScript),我想说最简单的解决方案是这样的:
拥有一个调用 ExtendScript 的 VB/VBScript 包装器,并且该包装器处理数据库交互和将数据传回& 转到 ExtendScript。 这使您可以重用 VB 中的代码来保持数据库代码简单,并保持 ExtendScript 简单。
您可以使用 Adobe 应用程序的 COM API 从 VB/VBScript 调用 ExtendScript,该 API 具有从 ExtendScript 获得的所有绘图方法以及用于执行 javascript(或更实际的 ExtendScript)代码的 doJavascript() 方法。 同样的 doJavascript() 方法可用于引入 ExtendScript JSX 文件,而不是 JavaScript 代码片段。 您可以在相关的 SO 帖子中找到更多详细信息:
是可以从外部 ExtendScript 执行 JSX 脚本吗?
查看 Windows 特定的答案。 回答这个问题& 解决方案进一步,它也可以适用于其他平台(Mac、Python、Perl 等),它不必适用于 VB 和 Windows,相同的方法可以用于通过 Windows 上的 COM 或 Applescript 与外部 ExtendScript 交互Mac,并且可以与 COM/Applescript 兼容(或接口)的任何语言一起使用。
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).