(args, extra_args)
| 140 | |
| 141 | |
| 142 | def cmd_foreach(args, extra_args): |
| 143 | try: |
| 144 | model = ifcopenshell.open(args.ifc_file) |
| 145 | except Exception as e: |
| 146 | print(f"Error: Could not open IFC file: {e}", file=sys.stderr) |
| 147 | sys.exit(1) |
| 148 | |
| 149 | parts = args.function_path.split(".") |
| 150 | if len(parts) != 2: |
| 151 | print("Error: function path must be 'module.function' (e.g. root.create_entity)", file=sys.stderr) |
| 152 | sys.exit(1) |
| 153 | module, function = parts |
| 154 | |
| 155 | raw_kwargs_template = _parse_extra_args(extra_args) |
| 156 | |
| 157 | try: |
| 158 | stdin_data = json.load(sys.stdin) |
| 159 | except json.JSONDecodeError as e: |
| 160 | print(f"Error: Could not parse JSON from stdin: {e}", file=sys.stderr) |
| 161 | sys.exit(1) |
| 162 | |
| 163 | if not isinstance(stdin_data, list): |
| 164 | print("Error: stdin must be a JSON array", file=sys.stderr) |
| 165 | sys.exit(1) |
| 166 | |
| 167 | result = run_foreach(model, module, function, raw_kwargs_template, stdin_data) |
| 168 | |
| 169 | if result["ok"]: |
| 170 | output_path = args.output or args.ifc_file |
| 171 | model.write(output_path) |
| 172 | |
| 173 | print(format_output(result, args.output_format)) |
| 174 | if not result["ok"]: |
| 175 | sys.exit(1) |
| 176 | |
| 177 | |
| 178 | def cmd_quantify(args, extra_args): |
no test coverage detected