您的位置:首页 > 理论基础

python处理计算机辅助设计软件文字信息并实现排序输出

2017-02-16 21:21 956 查看
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=[]
pxy=[]

acad=Autocad(create_if_not_exists=True)
acad.prompt("hello this is mt")
for text in acad.iter_objects('Text'):
pxy.append((APoint(text.InsertionPoint).x,APoint(text.InsertionPoint).y))

def zuobiaopaixu(a):
b=[]
l=len(a)
for i in range(l):
j=i
for j in range(l):
if (a[i][0]<a[j][0]):
a[i],a[j]=a[j],a[i]
if (a[i][1]>a[j][1]):
a[i],a[j]=a[j],a[i]

for k in range(len(a)):
b.append(a[k])
return b

zb=zuobiaopaixu(pxy)
for i in range(len(zb)):
for text in acad.iter_objects('Text'):
if(APoint(text.InsertionPoint).x==zb[i][0] and APoint(text.InsertionPoint).y==zb[i][1]):
data.append(text.TextString)
#创建分割符###
for d in range(0,len(data)):
if(str(data[d])[0:3]=="tex" or str(data[d])[0:3]=="###"):
sheet["A"+str(d+1)]=data[d]

wb.save("aabb.xlsx")
print "success"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: