diff --git a/tools/cal_weight.py b/tools/cal_weight.py index 2cd5bbd..0194643 100644 --- a/tools/cal_weight.py +++ b/tools/cal_weight.py @@ -6,7 +6,6 @@ else: sys.path.append('/data/deploy/make3d/make2/libs/') import config, libs, libs_db -import pandas as pd def bmesh_copy_from_object(obj, transform=True, triangulate=True, apply_modifiers=False): """Returns a transformed, triangulated copy of the mesh""" @@ -74,31 +73,11 @@ def main(action, pid, sizes,orderId=0): bpy.ops.object.transform_apply(location=True, rotation=True, scale=True) print(f'模型{pid}的体积与克重估算信息:') arrData = {} - excel_file = 'weights.xlsx' # 替换为你的文件路径 - df = pd.read_excel(excel_file) - new_data = { - 'pid': [pid], # 假设新的 pid 是 '002' - '6cm': [0], # 新的 6cm 数据 - '7cm': [0], # 新的 7cm 数据 - '8cm': [0], # 新的 8cm 数据 - } - for size in sizes: size = float(size) weight = cal_weight(obj, size) size = str(size/10)+"cm" arrData[size] = str(weight)+"g" - - if size+"cm" in df.columns: - new_data[size+"cm"] = [weight] - - # 更新数据 - # 将新数据转换为 DataFrame - new_df = pd.DataFrame(new_data) - # 将新数据附加到原始 DataFrame 中 - df = pd.concat([df, new_df], ignore_index=True) - # 保存更新后的 Excel 文件 - df.to_excel(excel_file, index=False) #请求接口进行更新数据 arrParams = {"pid":pid,"order_id":orderId} diff --git a/tools/cal_weight_excel.py b/tools/cal_weight_excel.py index 253359c..150940c 100644 --- a/tools/cal_weight_excel.py +++ b/tools/cal_weight_excel.py @@ -63,10 +63,11 @@ def cal_weight(obj, size): # bpy.ops.wm.save_as_mainfile(filepath=os.path.join(config.workdir, action, pid, f'{pid}-{size/10}cm.blend')) model_info = {} bm = bmesh_copy_from_object(obj) - # 计算体积 保留两位小数 - model_info['volume'] = round(bm.calc_volume() / 1000,2) + # 计算体积 保留两位小数 + print(f"{pid},尺寸={size} 计算出来的体积= {bm.calc_volume()}") + model_info['volume'] = round(bm.calc_volume(),2) model_info['weight'] = round(model_info['volume'] * 1.226,2) - print(f'{size/10}cm:体积 {model_info["volume"]}cm³, 克重 {model_info["weight"]}g') + print(f'{size}cm:体积 {model_info["volume"]}cm³, 克重 {model_info["weight"]}g') return model_info["weight"] def main(action, pid, sizes,realHeight,orderId=0): @@ -114,7 +115,7 @@ def main(action, pid, sizes,realHeight,orderId=0): arrData[arrSize[1]] = str(weight)+"g" if arrSize[1] in df.columns: - new_data[arrSize[1]+"尺寸"] = [str(size/10)+"cm"] + new_data[arrSize[1]+"尺寸"] = [str(size)+"cm"] new_data[arrSize[1]] = [str(weight)+'g'] # 更新数据