feat: 完善一级关系参数化建模与参数导出
This commit is contained in:
@@ -144,6 +144,24 @@ def _execute(model: StepModel, operation: str, args: list[object]) -> str:
|
||||
raise ValueError(f"Unsupported isolated edit operation: {operation}")
|
||||
|
||||
|
||||
def _load_request_model(path: Path, file_format: str) -> StepModel:
|
||||
if file_format == "brep":
|
||||
return StepModel.load_internal_brep(path)
|
||||
if file_format == "step":
|
||||
return StepModel.load(path)
|
||||
raise ValueError(f"Unsupported isolated edit input format: {file_format}")
|
||||
|
||||
|
||||
def _export_response_model(model: StepModel, path: Path, file_format: str) -> None:
|
||||
if file_format == "brep":
|
||||
model.export_internal_brep(path)
|
||||
return
|
||||
if file_format == "step":
|
||||
model.export_all(path)
|
||||
return
|
||||
raise ValueError(f"Unsupported isolated edit output format: {file_format}")
|
||||
|
||||
|
||||
def run_request(request: str | Path) -> int:
|
||||
request_path = Path(request)
|
||||
response_path = request_path.with_suffix(".response.json")
|
||||
@@ -153,10 +171,12 @@ def run_request(request: str | Path) -> int:
|
||||
output_path = Path(str(request["output_path"]))
|
||||
operation = str(request["operation"])
|
||||
args = list(request.get("args") or [])
|
||||
input_format = str(request.get("input_format") or "step").strip().lower()
|
||||
output_format = str(request.get("output_format") or input_format).strip().lower()
|
||||
|
||||
model = StepModel.load(input_path)
|
||||
model = _load_request_model(input_path, input_format)
|
||||
message = _execute(model, operation, args)
|
||||
model.export_all(output_path)
|
||||
_export_response_model(model, output_path, output_format)
|
||||
response_path.write_text(
|
||||
json.dumps(
|
||||
{
|
||||
@@ -164,6 +184,7 @@ def run_request(request: str | Path) -> int:
|
||||
"message": message,
|
||||
"stats": model.stats().__dict__,
|
||||
"output_path": str(output_path),
|
||||
"output_format": output_format,
|
||||
},
|
||||
ensure_ascii=False,
|
||||
indent=2,
|
||||
|
||||
Reference in New Issue
Block a user