Windows下Python + AutoCAD 多義線繪圖小結


簡介

在windows下台下, 使用comtypes庫, 通過ActiveX操作autocad, 從而讀取AutoCAD數據

  • comtypes.client

AutoCAD ActiveX

  • GetActiveObject('AutoCAD.Application')
  • Document
  • ModelSpace

1. 得到AutoCAD對象

import comtypes.client
# 得到AutoCAD應用程序對象
acad = comtypes.client.GetActiveObject('AutoCAD.Application')
# 得到當前文檔
doc = acad.ActiveDocument
# 得到當前文檔模型空間
model_space = doc.ModelSpace

2. 創建2維多義線(LightWeightPolyline)

import array
points = array.array('d', range(10))
acad.ActiveDocument.ModelSpace.AddLightWeightPolyline(points)

3. 讀取2維多義線(LightWeightPolyline)

apline = comtypes.client.GetBestInterface(apline)
print(apline.Coordinates)

4. 添加多義線完整的例子

#!/usr/bin/env python
# -*- coding:utf-8 -*-

# 導入標准庫
import comtypes.client
import array

# 得到AutoCAD應用程序對象
acad = comtypes.client.GetActiveObject('AutoCAD.Application')
# 得到當前文檔
doc = acad.ActiveDocument
# 得到當前文檔模型空間
model_space = doc.ModelSpace

# 生成多義線點
points = array.array('d', range(10))
# 添加多義線
model_space.AddLightWeightPolyline(points)

 



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM