使用 Python 批量运行 autoLISP [英] Batch run autoLISP with Python

查看:27
本文介绍了使用 Python 批量运行 autoLISP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对多个 CAD 文件(例如文件夹中的所有文件)运行 autoLISP.基本上,打开文件(DWG),运行 LISP(包括保存文件)并关闭.我是 LISP 的新手,但对 Python 不太陌生.

是否可以使用 Python 运行批处理?我知道如何用 Python 程序打开文件,但不知道如何运行 LISP.或者,有人知道如何使用 LISP 运行批处理吗?

到目前为止,我发现的解决方案涉及第三方软件和 C#.另外,我正在运行 AutoCAD-MEP 2018 和 Python 3.5.

解决方案

根据我的经验,批处理多个文件的最佳方法是使用 AutoCAD 脚本文件 (.scr).

脚本只是用来打开每张图,加载&运行适当的 AutoLISP 程序,然后保存 &关闭绘图,然后移至下一个绘图文件.

由于 AutoLISP 在 Document 命名空间中运行,当另一个图形变为活动时,计算停止;但是,AutoCAD 脚本文件将继续运行,直到脚本中的所有命令都已发出或脚本已中止.

<小时>

这种脚本的基本结构是:

_.open C:Drawing1.dwg (load "MyProgram.lsp" nil) (c:MyCommand) _.qsave _.close_.open C:Drawing2.dwg (load "MyProgram.lsp" nil) (c:MyCommand) _.qsave _.close_.open C:Drawing3.dwg (load "MyProgram.lsp" nil) (c:MyCommand) _.qsave _.close...

以上可以保存为 MyScript.scr 并使用 AutoCAD SCRIPT 命令从空白的新图形中运行.

当然,也可以加入额外的错误检查,例如在评估之前检查 AutoLISP 程序是否已成功加载等.

有关 AutoCAD 脚本文件的更多信息,我已将本基础教程放在一起AutoCAD 脚本.

<小时>

考虑到上述情况,下一步是自动构建脚本文件本身(而不是手动编写几乎相同的每一行).

为此,有几个现有的应用程序:ScriptPro 是众所周知的,我还创建了自己的 Script Writer 前段时间的应用程序,它提供了一个基本的界面,允许用户输入脚本文件的第一行,然后程序构建其余部分.

举一个现有的例子,我的批量属性编辑器应用程序也基于这种技术使用 AutoLISP 应用程序构建 AutoCAD 脚本文件,然后使用该文件在多个选定的图形上评估 AutoLISP 功能.

<小时>

简而言之,尽管您特别说明使用 Python 来执行此任务,但我认为在这种情况下不需要这样做,因为一个非常简单的脚本文件 (.scr) 就足够了.

I want to run an autoLISP on multiple CAD files (e.g. all files in a folder). Basically, open file (DWG), run LISP (including, save file) and close. I'm new to LISP, but less new to Python.

Is it possible to run the batch with Python? I know how to open a file with a program in Python, but not how to run the LISP. Alternatively, anybody know how to run the batch with LISP?

The solutions I've found so far involve third party software and C#. Also, I'm running AutoCAD-MEP 2018 and Python 3.5.

解决方案

In my experience, the best way to batch-process multiple files is using an AutoCAD Script file (.scr).

The Script is merely used to open each drawing, load & run an appropriate AutoLISP program, and then save & close the drawing, before moving onto the next drawing file.

Since AutoLISP runs in the Document namespace, evaluation ceases when another drawing becomes active; however, an AutoCAD Script file will continue to run until all commands in the script have been issued, or the script has been aborted.


The basic structure of such a Script would be:

_.open C:Drawing1.dwg (load "MyProgram.lsp" nil) (c:MyCommand) _.qsave _.close
_.open C:Drawing2.dwg (load "MyProgram.lsp" nil) (c:MyCommand) _.qsave _.close
_.open C:Drawing3.dwg (load "MyProgram.lsp" nil) (c:MyCommand) _.qsave _.close
...

The above could be saved as MyScript.scr and run from within a blank new drawing using the AutoCAD SCRIPT command.

Of course, additional error checking could also be incorporated, such as checking whether the AutoLISP program has loaded successfully prior to evaluation etc.

For more information on AutoCAD Script files in general, I have put together this basic tutorial surrounding AutoCAD Scripts.


With the above in mind, the next step is automating the construction of the Script file itself (as opposed to writing each near identical line manually).

For this, there are several existing applications: ScriptPro is quite commonly known, and I have also created my own Script Writer application some time ago, which provides a basic interface to allow the user to type the first line of the Script file and the program construct the rest.

To offer an existing example, my Batch Attribute Editor application is also predicated on this technique of using an AutoLISP application to construct an AutoCAD Script file, which is then used to evaluate an AutoLISP function on several selected drawings.


In short, although you specifically state the use of Python to perform this task, I don't believe this is necessary in this circumstance, as a very simple Script file (.scr) will suffice.

这篇关于使用 Python 批量运行 autoLISP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆