本文實(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)容感興趣的讀者可查看本站專(zhuān)題:《Python文件與目錄操作技巧匯總》、《Python文本文件操作技巧匯總》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》及《Python入門(mén)與進(jìn)階經(jīng)典教程》
希望本文所述對(duì)大家Python程序設(shè)計(jì)有所幫助。
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元
