1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- import os
- import time
- import requests
- import yaml
- import ezdxf
- from DictManager import DictManager
- from drawer.Tun2dDrawer import Tun2dDrawer
- url_2d = "http://192.168.183.216:8008/python/tunCAD"
- url_3d = "http://192.168.183.216:8008/tunLt"
- model_id = 1868855086453813249
- def request_graph_point(url):
- response = requests.get(url, timeout=10)
- print(f"请求耗时 {response.elapsed.total_seconds()} 秒")
- cad_json = {}
- if response.status_code == 200:
- cad_json = response.json() # 将响应内容解析为JSON格式
- else:
- print(f"请求失败,状态码:{response.status_code}")
- return cad_json
- with open('config/buertai/global-2d.yaml', 'r', encoding='utf-8') as file:
- config = yaml.safe_load(file)
- original_data = request_graph_point(f'{url_2d}?modelid={model_id}')
- dm = DictManager(original_data,'2d')
- default_template_file = "template/last/default_2d.dxf"
- if os.path.exists(default_template_file):
- doc = ezdxf.readfile(default_template_file)
- else:
- doc = ezdxf.new('R2013')
- doc.styles.add("msyh", font="config/msyh.ttc")
- for layer in dm.layer_dict.values():
- doc.layers.new(name=f'图层{layer.layer_id}')
- msp = doc.modelspace()
- for tun in dm.tun_2d_dict.values():
- t2d = Tun2dDrawer(obj=tun,msp=msp)
- t2d.draw()
- path = f'save/{str(time.time())}.dxf'
- doc.saveas(path)
- print(f'保存文件{os.path.abspath(path)}')
|