test.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import os
  2. import time
  3. import requests
  4. import yaml
  5. import ezdxf
  6. from DictManager import DictManager
  7. from drawer.Tun2dDrawer import Tun2dDrawer
  8. url_2d = "http://192.168.183.216:8008/python/tunCAD"
  9. url_3d = "http://192.168.183.216:8008/tunLt"
  10. model_id = 1868855086453813249
  11. def request_graph_point(url):
  12. response = requests.get(url, timeout=10)
  13. print(f"请求耗时 {response.elapsed.total_seconds()} 秒")
  14. cad_json = {}
  15. if response.status_code == 200:
  16. cad_json = response.json() # 将响应内容解析为JSON格式
  17. else:
  18. print(f"请求失败,状态码:{response.status_code}")
  19. return cad_json
  20. with open('config/buertai/global-2d.yaml', 'r', encoding='utf-8') as file:
  21. config = yaml.safe_load(file)
  22. original_data = request_graph_point(f'{url_2d}?modelid={model_id}')
  23. dm = DictManager(original_data,'2d')
  24. default_template_file = "template/last/default_2d.dxf"
  25. if os.path.exists(default_template_file):
  26. doc = ezdxf.readfile(default_template_file)
  27. else:
  28. doc = ezdxf.new('R2013')
  29. doc.styles.add("msyh", font="config/msyh.ttc")
  30. for layer in dm.layer_dict.values():
  31. doc.layers.new(name=f'图层{layer.layer_id}')
  32. msp = doc.modelspace()
  33. for tun in dm.tun_2d_dict.values():
  34. t2d = Tun2dDrawer(obj=tun,msp=msp)
  35. t2d.draw()
  36. path = f'save/{str(time.time())}.dxf'
  37. doc.saveas(path)
  38. print(f'保存文件{os.path.abspath(path)}')