使用 Access 2007 中的 VBA 在 AutoCAD (dwg) 文件中搜索

发布于 2024-12-06 03:47:41 字数 468 浏览 0 评论 0原文

我有数百个 DWG、AutoCAD 文件,我想将它们搜索并编录到 MS Access 数据库中。

基本上,我想搜索 DWG 并提取标题框中的任何描述以及日期,并将所有内容转移到 Access 中,使其成为可搜索的目录。

例如,我有一个文件名为 T-25682.DWG,其标题为 Machine Spacer,创建于 01/20/2010。

我将从 DWG 文件中提取该信息并将其插入到 Access 数据库中,如下所示:

== ID ==    == DESCRIPTION ==    == CREATED ON ==    == FILENAME ==

    1       Machine Spacer       01/20/2010          T-25682.dwg

我该如何处理并解决这个问题?是否有可以与 Access 一起使用的 AutoCAD 库?如何在 DWG 文件中搜索?

I have hundreds of DWG, AutoCAD files that I would like search and catalog into an MS Access Database.

Basically, I would like to search the DWG's and extract whatever description is in the Title box as well as the Date and bring everything over to Access making it a searchable catalog.

For example, I have a file name T-25682.DWG, which is titled Machine Spacer and created 01/20/2010.

I would extract that info form the DWG file and insert it into the Access database as such:

== ID ==    == DESCRIPTION ==    == CREATED ON ==    == FILENAME ==

    1       Machine Spacer       01/20/2010          T-25682.dwg

How can I approach and solve this problem? Is there an AutoCAD library I can use with Access? How can I search in a DWG file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

疧_╮線 2024-12-13 03:47:41

我会完全避免使用 VBA,AutoLISP 可以轻松完成这项工作。具体方法如下:

在 AutoLISP 文件内创建“数据提取和写入 Access”功能。免费提供的 ADOLisp 库将使写入 Access 变得轻而易举,如果失败,或者您无法做到这一点,您始终可以只写入 csv 文件...

一旦您能够为单个文件执行此操作dwg 文件,创建一个脚本(使用任何可以复制和打开文件的工具,AutoLisp 也可以)来执行以下操作:

  1. 将该 lisp 文件复制到 dwg 文件所在的目录中,将该文件命名为 acaddoc.lsp。
  2. 依次打开目录中的每个 dwg。打开后,acaddoc.lsp 将运行并执行其操作。
  3. 从该目录中删除 acaddoc.lsp (否则每次您在其中打开 dwg 时它都会运行)。
  4. 对您希望在其中编目的 dwg 文件的每个目录重复此操作。

注意:

  1. 确保 acaddoc.lsp 在完成后关闭图形(或使 AutoCAD 退出,具体取决于打开文件的方式)。
  2. 为此,您的标题栏必须可靠,请确保添加一些错误检查。您可以使用该脚本将发现的任何问题记录到文本文件中...

AutoLisp 真的非常简单,如需学习帮助,请访问 AutoLISP 初学者教程

有关提出问题和搜索以前回答的问题中的代码片段的最佳位置,请参阅 Visual LISP、AutoLISP 和常规自定义

I would avoid VBA altogether, AutoLISP can do the job for with far less pain. Here's how:

Create the "data extraction and writing to Access" functionality inside an AutoLISP file. The freely available ADOLisp library will make it a breeze writing to Access, if that fails, or you aren't able to do it you can always just write to a csv file...

Once you're able to do that for a single dwg file, create a script (using anything that can copy and open files, AutoLisp works too) to do the following:

  1. Copy that lisp file into a directory where your dwg files are, naming the file as acaddoc.lsp.
  2. Sequentially open every dwg in the directory. Upon opening, acaddoc.lsp will run and do its stuff.
  3. Delete acaddoc.lsp from that directory (else it will run every time you open a dwg in there).
  4. Repeat for every directory you have dwg files in which you wish to catalog.

Notes:

  1. Make sure that acaddoc.lsp closes the drawing when its done (or makes AutoCAD quit, depending on how you're opening the files).
  2. For this to work, your title blocks need to be reliable, make sure you add some error checking. You can use the script to log any issues to a text file as they find them...

AutoLisp is really really easy, for help with learning go to AutoLISP Beginners' Tutorials.

For the best place to ask questions and search for code snippets from previous answered questions, see Visual LISP, AutoLISP and General Customization.

尹雨沫 2024-12-13 03:47:41

如果您有完整版本的 AutoCAD,您可以尝试数据提取向导。这对于属性块来说非常有效。如果这不好,最好的尝试地方是 Swamp 或 AutoCAD 论坛或 AUGI。

VBA 在 AutoCAD 的最后 3 个版本中已被弃用,取而代之的是 .NET API,仅供参考

+edit+
查看有关 AutoCAD 外部数据库连接的(免费)章节< /a>.

If you have a full version of AutoCAD you can try the Data Extraction Wizard. This works quite well for attributed blocks. If this is no good, the best places to try are the Swamp or the AutoCAD forums or AUGI.

VBA is deprecated in the last 3 versions of AutoCAD in favour of the .NET API, FYI

+edit+
Have a look at this (free) chapter on AutoCAD external database connectivity.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文