【问题标题】:using the lisp application from AutoCAD with Python 3.5使用 AutoCAD 的 lisp 应用程序和 Python 3.5
【发布时间】:2018-06-10 07:32:24
【问题描述】:

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

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

【问题讨论】:

    标签: python lisp autocad gml autolisp


    【解决方案1】:

    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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 我已经只用 lisp 语言解决了这个问题,但是这个信息对于其他项目来说真的很有用。谢谢!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-02-06
      • 1970-01-01
      • 1970-01-01
      • 2011-05-06
      • 1970-01-01
      • 1970-01-01
      • 2017-11-15
      相关资源
      最近更新 更多