Python使用pyautocad+openpyxl處理cad文件示例
本文實(shí)例講述了Python使用pyautocad+openpyxl處理cad文件。分享給大家供大家參考,具體如下:
示例1:
from pyautocad import Autocad
import openpyxl
wb=openpyxl.load_workbook('./cads.xlsx')
sheet=wb.get_sheet_by_name('Sheet1')
data=[]
pset=[]
acad=Autocad(create_if_not_exists=True)
acad.prompt('hello this is python in')
for text in acad.iter_objects('Text'):
data.append(text.TextString)
from pyautocad import APoint
for text in acad.iter_objects('Text'):
pset.append(APoint(text.InsertionPoint))
print len(data)
for d in range(1,len(data)):
sheet['A'+str(d)].value=data[d]
sheet['B'+str(d)].value=str(pset[d].x)
sheet['C'+str(d)].value=str(pset[d].y)
wb.save('aabb1.xlsx')
print 'success aabb1.xlsx'
其實(shí)pyautocad中有關(guān)于table的api
示例2:
from pyautocad import Autocad
import openpyxl
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
wb=openpyxl.load_workbook('./aabb.xlsx')
sheet=wb.get_sheet_by_name('Sheet1')
data=[]
acad=Autocad(create_if_not_exists=True)
acad.prompt('hello this is python in')
for text in acad.iter_objects('Text'):
data.append(text.TextString)
print len(data)
for d in range(1,len(data)):
if(str(data[d])[0:4]=="BM30" or str(data[d])[0:4]=="BM65"):
sheet['A'+str(d)].value=data[d]
wb.save('ky1.xlsx')
print 'success ky1.xlsx'
截取了BM30和BM65的數(shù)據(jù)
示例3:
import openpyxl
from pyautocad import Autocad,APoint
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
wb=openpyxl.load_workbook("a.xlsx")
sheet=wb.get_sheet_by_name("Sheet1")
data=[]
px=[]
py=[]
acad=Autocad(create_if_not_exists=True)
acad.prompt("hello this is mt")
for text in acad.iter_objects('Text'):
data.append(text.TextString)
#print text.TextString
px.append(APoint(text.InsertionPoint).x)
py.append(APoint(text.InsertionPoint).y)
#print text.InsertionPoint
print len(data)
print "eof"
for d in range(1,len(data)):
if(str(data[d])[0:4]=="Vigi" or str(data[d])[0:4]=="iC65" or str(data[d])[0:3]=="CVS" or str(data[d])[0:3]=="PRD" or str(data[d])[0:4]=="DDZY"):
sheet['A'+str(d)]=data[d]
sheet['B'+str(d)]=px[d]
sheet["C"+str(d)]=py[d]
# print data[d]
wb.save("kv.xlsx")
print "success"
#or str(data[d])[0:3]=="CVS" or str(data[d])[0:3]=="PRD" or str(data[d])[0:4]=="DDZY"
更多關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Python文件與目錄操作技巧匯總》、《Python文本文件操作技巧匯總》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》及《Python入門與進(jìn)階經(jīng)典教程》
希望本文所述對(duì)大家Python程序設(shè)計(jì)有所幫助。
相關(guān)文章
Python?reflect單例模式反射各個(gè)函數(shù)
這篇文章主要介紹了Python?reflect單例模式反射各個(gè)函數(shù),文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值需要的小伙伴可以參考一下2022-06-06
python中的scapy抓取http報(bào)文內(nèi)容
這篇文章主要介紹了python中的scapy抓取http報(bào)文內(nèi)容方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-08-08
使用Python實(shí)現(xiàn)Excel表格轉(zhuǎn)圖片
在數(shù)據(jù)處理與信息分享過程中,Excel表格作為一種強(qiáng)大的數(shù)據(jù)管理工具被廣泛應(yīng)用,這篇文章主要為大家詳細(xì)介紹了如何使用Python將Excel表格轉(zhuǎn)換為圖片,需要的可以參考下2024-04-04
python 遞歸調(diào)用返回None的問題及解決方法
這篇文章主要介紹了python 遞歸調(diào)用返回None的問題,本文通過實(shí)例代碼給大家記錄了解決方案,代碼簡(jiǎn)單易懂,非常不錯(cuò)對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-03-03
Keras官方中文文檔:性能評(píng)估Metrices詳解
這篇文章主要介紹了Keras官方中文文檔:性能評(píng)估Metrices詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來(lái)看看吧2020-06-06

