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

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

问题描述

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

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.

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

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?

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

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

推荐答案

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

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

该脚本仅用于打开每个图形,加载并加载运行适当的AutoLISP程序,然后保存&关闭图形,然后再移至下一个图形文件.

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.

由于AutoLISP在Document名称空间中运行,因此当另一个图形变为活动状态时,评估将停止;但是,AutoCAD脚本文件将继续运行,直到发出脚本中的所有命令或脚本被中止为止.

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

以上内容可以另存为MyScript.scr,并可以使用AutoCAD SCRIPT命令在空白的新图形中运行.

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

当然,还可以合并其他错误检查,例如在评估之前检查AutoLISP程序是否已成功加载等.

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

有关一般上AutoCAD脚本文件的更多信息,我整理了此基本教程 AutoCAD脚本.

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

为此,有几个现有的应用程序:ScriptPro是众所周知的,并且我还创建了自己的不久前Script Writer 应用程序提供了一个基本界面,允许用户键入Script文件的第一行,然后程序构造其余的行.

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.

要提供一个现有示例,我的批处理属性编辑器应用程序也基于此技术使用AutoLISP应用程序构建AutoCAD脚本文件,然后将其用于评估多个选定工程图上的AutoLISP功能.

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.

简而言之,尽管您明确声明使用Python来执行此任务,但我认为在这种情况下这不是必需的,因为非常简单的脚本文件(.scr)就足够了.

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批量运行au​​toLISP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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