MCPcopy
hub / github.com/CadQuery/cadquery / run

Method run

cadquery/cq_directive.py:281–335  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

279 }
280
281 def run(self):
282
283 options = self.options
284 content = self.content
285 state_machine = self.state_machine
286
287 # only consider inline snippets
288 plot_code = "\n".join(content)
289
290 # collect the result
291 try:
292 result = cqgi.parse(plot_code).build()
293
294 if result.success:
295 if result.first_result:
296 shape = result.first_result.shape
297 else:
298 shape = result.env[options.get("select", "result")]
299
300 if isinstance(shape, Assembly):
301 assy = shape
302 elif isinstance(shape, Sketch):
303 assy = Assembly(shape._faces, color=Color(*DEFAULT_COLOR))
304 else:
305 assy = Assembly(shape, color=Color(*DEFAULT_COLOR))
306 else:
307 raise result.exception
308
309 except Exception:
310 traceback.print_exc()
311 assy = Assembly(Compound.makeText("CQGI error", 10, 5))
312
313 # add the output
314 lines = []
315
316 data = dumps(toJSON(assy))
317
318 lines.extend(
319 template_vtk.format(
320 data=data,
321 element="document.currentScript.parentNode",
322 txt_align=options.get("align", "left"),
323 width=options.get("width", "100%"),
324 height=options.get("height", "500px"),
325 ).splitlines()
326 )
327
328 lines.extend(["::", ""])
329 lines.extend([" %s" % row.rstrip() for row in plot_code.split("\n")])
330 lines.append("")
331
332 if len(lines):
333 state_machine.insert_input(lines, state_machine.input_lines.source(0))
334
335 return []
336
337
338def setup(app):

Callers

nothing calls this directly

Calls 8

AssemblyClass · 0.90
ColorClass · 0.90
toJSONFunction · 0.90
makeTextMethod · 0.80
extendMethod · 0.80
appendMethod · 0.80
buildMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected