MCPcopy Create free account
hub / github.com/IfcOpenShell/IfcOpenShell / cmd_foreach

Function cmd_foreach

src/ifcedit/ifcedit/__main__.py:142–175  ·  view source on GitHub ↗
(args, extra_args)

Source from the content-addressed store, hash-verified

140
141
142def 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
178def cmd_quantify(args, extra_args):

Callers 1

mainFunction · 0.85

Calls 9

run_foreachFunction · 0.90
printFunction · 0.85
_parse_extra_argsFunction · 0.85
openMethod · 0.80
splitMethod · 0.80
format_outputFunction · 0.70
exitMethod · 0.45
loadMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected