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)文章
Python3實(shí)現(xiàn)的Mysql數(shù)據(jù)庫(kù)操作封裝類
這篇文章主要介紹了Python3實(shí)現(xiàn)的Mysql數(shù)據(jù)庫(kù)操作封裝類,涉及Python針對(duì)mysql數(shù)據(jù)庫(kù)的連接、查詢、更新及關(guān)閉連接等相關(guān)操作技巧,需要的朋友可以參考下2018-06-06淺談tensorflow中Dataset圖片的批量讀取及維度的操作詳解
今天小編就為大家分享一篇淺談tensorflow中Dataset圖片的批量讀取及維度的操作詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-01-01在Python 字典中一鍵對(duì)應(yīng)多個(gè)值的實(shí)例
今天小編就為大家分享一篇在Python 字典中一鍵對(duì)應(yīng)多個(gè)值的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-02-02用Python實(shí)現(xiàn)局域網(wǎng)控制電腦
大家好,本篇文章主要講的是用Python實(shí)現(xiàn)局域網(wǎng)控制電腦,感興趣的同學(xué)趕快來看一看吧,對(duì)你有幫助的話記得收藏一下2022-01-01python之json文件轉(zhuǎn)xml文件案例講解
這篇文章主要介紹了python之json文件轉(zhuǎn)xml文件案例講解,本篇文章通過簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-08-08