使用来自Python 3.5的AutoCAD的LISP应用程序



i有6000多个.gml文件,可以保留有关会计颗粒的信息。我也有一个.LSP应用程序(我没有编写代码),该应用程序读取.gml文件并在.dxf文件中绘制粒子。问题在于,应用程序只能将一个.GML文件作为输入,因此手动完成它的工作太多了。

我编写了脚本以下载来自Python 3.5的服务器的所有.GML文件。应用?谢谢您的阅读。

autoCAD可以通过com自动化控制。Python可以使用Mark Hammond的pywin32软件包来执行此操作(尽管名称,可以使用64位构建)。

您最终会得到

之类的东西
import glob
import win32com.client
GML_FILES = r"c:usersmariodocumentsgml*.gml"
# For other versions of AutoCAD see
# http://help.autodesk.com/view/OARX/2018/ENU/?guid=GUID-0EDC04D5-2ACB-4555-B5AC-936D54A9FF61
acad = win32com.client.Dispatch("AutoCAD.Application.22")   # AutoCAD 2018
for gml_file in glob.glob(GML_FILES):
    # I spent quite a while trying to fill this in,
    # but (a) the documentation is very short on examples,
    # and (b) I don't have a copy of AutoCAD
    # which makes it very hard to test - sorry!

您将要参考http://help.autodesk.com/view/oarx/2018/enu/?guid=guid-86e444444f95-2372-461d-861d-862c-426038a6a6a24f

有一个称为pyautocad的软件包,它将帮助您进行AutoCAD COM交互。https://pypi.python.org/pypi/pyautocad/。可以使用PIP安装:

pip install pyautocad

因此,您的LISP脚本可称为命令。所以我想你正在使用

GMLIMPORT "PATHTOGML"

当您的LISP脚本称为gmlimport时。您可以以这种方式自动化

from pyautocad import Autocad
acad = Autocad()
for gml in gmls:
  acad.doc.SendCommand("GMLIMPORT " + gml)

这需要AutoCAD运行。检查Pyautocad文档以启动AutoCAD(如果不运行)。

最新更新