使用AutoCAD 3.5中的lisp应用程序

问题描述 投票:0回答:2

我有6000多个.gml文件,其中包含有关cadastrial粒子的信息。我还有一个用于AutoCAD的.lsp应用程序(我没有编写代码),它读取.gml文件并在.dxf文件中绘制粒子。问题是应用程序只能将一个.gml文件作为输入,因此手动执行它的工作太多了。

当我编写脚本从Python 3.5中的服务器下载所有.gml文件时,我想知道是否有办法用Python运行ACAD应用程序,所以我可以遍历所有文件并运行应用程序?谢谢你的阅读。

python lisp autocad gml autolisp
2个回答
1
投票

有一个名为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。


0
投票

AutoCAD可以通过COM自动化进行控制。 Python可以使用Mark Hammond's pywin32 package执行此操作(尽管名称,64位版本可用)。

你会得到像这样的东西

import glob
import win32com.client

GML_FILES = r"c:\users\mario\documents\gml\*.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-86E44F95-2372-461D-862C-426038A6A24F

© www.soinside.com 2019 - 2024. All rights reserved.