airtable+baserow batch
This commit is contained in:
parent
6def135bbc
commit
d4738c62e5
1 changed files with 80 additions and 88 deletions
|
|
@ -1115,32 +1115,36 @@ class ExecSliceNode_DatabaseSubmit(ExecSliceNode):
|
||||||
|
|
||||||
def init(self, context):
|
def init(self, context):
|
||||||
self._init_exec()
|
self._init_exec()
|
||||||
self.add_input("SLICESOCK_Gcode")
|
self.add_multi_input("SLICESOCK_Gcode", "Gcode")
|
||||||
self.add_input("SLICESOCK_String", "Filename")
|
|
||||||
|
|
||||||
def draw_buttons(self, context, layout):
|
def draw_buttons(self, context, layout):
|
||||||
super().draw_buttons(context, layout)
|
super().draw_buttons(context, layout)
|
||||||
layout.prop(self, "record_id")
|
layout.prop(self, "record_id")
|
||||||
|
|
||||||
def _prepare_submission(self, operator=None) -> tuple[str, str, dict[str, str]]:
|
def evaluate(self, operator=None):
|
||||||
|
from ...infra.networking.bgcode import convert_to_bgcode
|
||||||
|
from ...infra.networking.gcode_utils import get_gcode_name_from_metadata
|
||||||
|
import tempfile
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
gcodes: str = self.resolve_multi_input("Gcode")
|
||||||
|
|
||||||
|
for gc in gcodes:
|
||||||
import re
|
import re
|
||||||
import json
|
import json
|
||||||
gcode: str = resolve_input(self.inputs.get("Gcode"))
|
|
||||||
if not gcode:
|
|
||||||
if operator: operator.report({'ERROR'}, "No Gcode to send")
|
|
||||||
return '', '', {}
|
|
||||||
|
|
||||||
filename: str = resolve_input(self.inputs.get("Filename")) or "output.gcode"
|
if not gc:
|
||||||
if not filename.endswith(".gcode"):
|
if operator: operator.report({'ERROR'}, "No Gcode to send")
|
||||||
filename += ".gcode"
|
continue
|
||||||
|
|
||||||
# Parse Metadata from Gcode
|
# Parse Metadata from Gcode
|
||||||
fields = {}
|
fields = {}
|
||||||
part_name = filename.split(".")[0]
|
part_name = get_gcode_name_from_metadata(gc)
|
||||||
fields["Part ID / Name"] = part_name
|
fields["Part ID / Name"] = part_name
|
||||||
|
|
||||||
# 1. Time per print (decimal hours)
|
# 1. Time per print (decimal hours)
|
||||||
time_match = re.search(r"; estimated printing time \(normal mode\) = (.*)", gcode)
|
time_match = re.search(r"; estimated printing time \(normal mode\) = (.*)", gc)
|
||||||
if time_match:
|
if time_match:
|
||||||
time_str = time_match.group(1)
|
time_str = time_match.group(1)
|
||||||
h = re.search(r"(\d+)h", time_str)
|
h = re.search(r"(\d+)h", time_str)
|
||||||
|
|
@ -1153,7 +1157,7 @@ class ExecSliceNode_DatabaseSubmit(ExecSliceNode):
|
||||||
fields["Time per print"] = round(total_hours, 2)
|
fields["Time per print"] = round(total_hours, 2)
|
||||||
|
|
||||||
# 2. Parts per print
|
# 2. Parts per print
|
||||||
parts_match = re.search(r"; objects_info = (.*)", gcode)
|
parts_match = re.search(r"; objects_info = (.*)", gc)
|
||||||
if parts_match:
|
if parts_match:
|
||||||
try:
|
try:
|
||||||
info = json.loads(parts_match.group(1))
|
info = json.loads(parts_match.group(1))
|
||||||
|
|
@ -1161,26 +1165,14 @@ class ExecSliceNode_DatabaseSubmit(ExecSliceNode):
|
||||||
except Exception: pass
|
except Exception: pass
|
||||||
|
|
||||||
# 3. Weight per print
|
# 3. Weight per print
|
||||||
weight_match = re.search(r"; total filament used \[g\] = ([\d\.]+)", gcode)
|
weight_match = re.search(r"; total filament used \[g\] = ([\d\.]+)", gc)
|
||||||
if weight_match:
|
if weight_match:
|
||||||
fields["Weight per print"] = int(float(weight_match.group(1)))
|
fields["Weight per print"] = int(float(weight_match.group(1)))
|
||||||
|
|
||||||
return gcode, filename, fields
|
|
||||||
|
|
||||||
def evaluate(self, operator=None):
|
|
||||||
from ...infra.networking.bgcode import convert_to_bgcode
|
|
||||||
import tempfile
|
|
||||||
import os
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
gcode, filename, fields = self._prepare_submission(operator)
|
|
||||||
if not gcode: return 'error'
|
|
||||||
|
|
||||||
# Detect binary trigger in gcode comments
|
# Detect binary trigger in gcode comments
|
||||||
is_binary = "; binary_gcode = 1" in gcode
|
is_binary = "; binary_gcode = 1" in gc
|
||||||
|
|
||||||
name_part = filename.split('.')[0]
|
filename = part_name + ".bgcode" if is_binary else ".gcode"
|
||||||
filename = name_part + ".bgcode" if is_binary else ".gcode"
|
|
||||||
|
|
||||||
token_path = getattr(self, self._token_prop_name, "")
|
token_path = getattr(self, self._token_prop_name, "")
|
||||||
token = ""
|
token = ""
|
||||||
|
|
@ -1203,12 +1195,12 @@ class ExecSliceNode_DatabaseSubmit(ExecSliceNode):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if is_binary:
|
if is_binary:
|
||||||
content = convert_to_bgcode(gcode, name_part, True)
|
content = convert_to_bgcode(gc, part_name, True)
|
||||||
with open(temp_path, "wb") as f:
|
with open(temp_path, "wb") as f:
|
||||||
f.write(content)
|
f.write(content)
|
||||||
else:
|
else:
|
||||||
with open(temp_path, 'w', encoding='utf-8') as f:
|
with open(temp_path, 'w', encoding='utf-8') as f:
|
||||||
f.write(gcode)
|
f.write(gc)
|
||||||
|
|
||||||
record_id = self._submit_to_db(token, fields, temp_path)
|
record_id = self._submit_to_db(token, fields, temp_path)
|
||||||
if operator: operator.report({'INFO'}, f"Submitted to {self._db_name} (Record: {record_id})")
|
if operator: operator.report({'INFO'}, f"Submitted to {self._db_name} (Record: {record_id})")
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue