Добавлен импорт требований через json

This commit is contained in:
Mark Voltov 2023-06-27 16:51:02 +03:00
parent 6983c833f2
commit ed70c47b7c

View file

@ -108,3 +108,80 @@ def run_BoM_list():
sortedParts = uniquePartsSort(labelParts)
countedParts = countForUniques(sortedParts)
fillInBoMList(sheet, countedParts)
def printETACounter(partLabel):
import os
import requests
import time
import FreeCAD
from FreeCAD import Base
def export_to_stl(doc, filename):
mesh = doc.getObjectsByType("Mesh")[0]
mesh.exportStl(filename)
def upload_to_octoprint(file_path, api_key, octoprint_url):
headers = {
"X-Api-Key": api_key
}
files = {
"file": open(file_path, "rb")
}
response = requests.post(octoprint_url + "/api/files/local", headers=headers, files=files)
if response.status_code == 201:
print("Файл успешно загружен в OctoPrint.")
return response.json()["name"]
else:
print("Ошибка при загрузке файла в OctoPrint:", response.text)
return None
def get_print_duration(file_name, api_key, octoprint_url):
headers = {
"X-Api-Key": api_key
}
response = requests.get(octoprint_url + "/api/files/local/" + file_name, headers=headers)
if response.status_code == 200:
return response.json()["gcodeAnalysis"]["estimatedPrintTime"]
else:
print("Ошибка при получении информации о файле из OctoPrint:", response.text)
return None
# Путь к документу FreeCAD
doc_path = "/path/to/your/file.FCStd"
# Путь для сохранения STL-файла
stl_path = "/path/to/your/output.stl"
# Настройки OctoPrint
octoprint_api_key = "your_octoprint_api_key"
octoprint_url = "http://localhost:5000"
# Открываем документ FreeCAD
doc = FreeCAD.open(doc_path)
# Экспортируем модель в STL-файл
export_to_stl(doc, stl_path)
print("STL-файл успешно создан.")
# Загружаем STL-файл в OctoPrint
uploaded_file_name = upload_to_octoprint(stl_path, octoprint_api_key, octoprint_url)
if uploaded_file_name is not None:
# Получаем информацию о длительности печати
print_duration = get_print_duration(uploaded_file_name, octoprint_api_key, octoprint_url)
if print_duration is not None:
print("Оценочная длительность печати: {} секунд.".format(print_duration))
else:
print("Не удалось получить информацию о длительности печати.")
else:
print("Загрузка файла в OctoPrint не удалась.")
# Закрываем документ FreeCAD
FreeCAD.closeDocument(doc)