29 lines
1.8 KiB
Bash
Executable File
29 lines
1.8 KiB
Bash
Executable File
#!/bin/zsh
|
|
set -eu
|
|
cd -- "${0:A:h}"
|
|
if (( $# )); then
|
|
source_dir=$1
|
|
else
|
|
source_dir=$(osascript -e 'POSIX path of (choose folder with prompt "选择包含编号部位文件夹的零件父目录")') || exit 0
|
|
fi
|
|
source_dir=${source_dir:A}
|
|
output_dir="${source_dir}-装配输出-$(date +%Y%m%d-%H%M%S)"
|
|
extra_files=("$source_dir"/**/[0-9]*附加*.glb(N))
|
|
extra_args=()
|
|
whole_models=("$source_dir"/*.glb(N) "$source_dir"/*.GLB(N))
|
|
if (( ${#whole_models} != 1 )); then
|
|
reference_file=$(osascript -e 'POSIX path of (choose file with prompt "选择与这些零件对应的整机 GLB")') || exit 0
|
|
extra_args+=(--reference "$reference_file")
|
|
fi
|
|
play_mode=$(osascript -e 'button returned of (display dialog "按目录和标记装配:按部位编号安装,支持小组件和 +、-、!、#。\n\n部件预装后总装:最后一个文件夹之前依次合装已完成的部件。" buttons {"取消", "部件预装后总装", "按目录和标记装配"} default button "按目录和标记装配" cancel button "取消" with title "选择装配流程")') || exit 0
|
|
if [[ "$play_mode" == "部件预装后总装" ]]; then
|
|
final_group=$(node --input-type=module -e 'import fs from "node:fs"; const groups=fs.readdirSync(process.argv[1],{withFileTypes:true}).filter(e=>e.isDirectory()).map(e=>Number(/^\d+/.exec(e.name)?.[0])).filter(Number.isFinite); console.log(Math.max(...groups));' "$source_dir")
|
|
extra_args+=(--final-group "$final_group")
|
|
fi
|
|
if (( ${#extra_files} )); then
|
|
extra_position=$(osascript -e 'text returned of (display dialog "每个部位的附加件要插在哪个步号之前?填写步号,或填写 end 放在各组末尾。" default answer "" with title "附加件的顺序")') || exit 0
|
|
extra_args+=(--extra-before "$extra_position")
|
|
fi
|
|
npm run assembly:generate -- "$source_dir" "$output_dir" "${extra_args[@]}"
|
|
open "$output_dir"
|