- 积分
- 298
- 明经币
- 个
- 注册时间
- 2012-3-11
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2022-6-14 14:52:26
|
显示全部楼层
python调用win32com操作CAD,识别图元:长度分层统计(直线、多段线)
def get_line_long(self,txt):
self.ftyp = [0, 100, 410, 8]
self.ftdt = ['*Line','AcDb*','Model','*'+str(txt)+'*']
SSetTemp = self.shaixuan_cad()
dicc={}
for n,ent in enumerate(SSetTemp):
try:
print(n,':::',ent.layer)
if ent.EntityName == 'AcDbPolyline':
FirstPoint = ','.join([str('%.3f' % i) for i in ent.Coordinates[0:2]])+',0.000'
SecondPoint = ','.join([str('%.3f' % i) for i in ent.Coordinates[2:4]])+',0.000'
elif ent.EntityName == 'AcDbLine':
FirstPoint=','.join([str('%.3f' % i) for i in ent.StartPoint])
SecondPoint=','.join([str('%.3f' % i) for i in ent.EndPoint])
dic = {'CAD_Name': self.doc.Name,
'No.': n + 1,
'Layer': ent.layer,
'Length': round(ent.Length,3),
'color': ent.color,
'FirstPoint': FirstPoint,
'SecondPoint': SecondPoint,
}
except:
continue
key = dic['Layer']
name=re.sub(r'[^A-Za-z0-9_一-龢-]','_',key)
if dic['Layer'] not in dicc.keys():
dicc[key] = dic['Length']
self.out_excel('新图层', [name, list(dic.keys())])
else:
dicc[key] += dic['Length']
self.out_excel('dv', [name, list(dic.values())])
self.out_excel('k', ['Layer', 'Length'])
for k, v in dicc.items():
self.out_excel('v', [k,v])
time.sleep(0.1)
print('所长的温馨提示:', '程序已运行结束,请注意查看已存储到Excel文件!By所长_WCEO QQ121841879') |
|