Allows a script to communicate with the container the show_object() method is exposed to CQ scripts, to allow them to return objects to the execution environment
| 322 | |
| 323 | |
| 324 | class ScriptCallback(object): |
| 325 | """ |
| 326 | Allows a script to communicate with the container |
| 327 | the show_object() method is exposed to CQ scripts, to allow them |
| 328 | to return objects to the execution environment |
| 329 | """ |
| 330 | |
| 331 | def __init__(self): |
| 332 | self.outputObjects = [] |
| 333 | self.debugObjects = [] |
| 334 | |
| 335 | def show_object(self, shape, options={}, **kwargs): |
| 336 | """ |
| 337 | Return an object to the executing environment, with options. |
| 338 | |
| 339 | :param shape: a cadquery object |
| 340 | :param options: a dictionary of options that will be made available to the executing environment |
| 341 | """ |
| 342 | options.update(kwargs) |
| 343 | |
| 344 | o = ShapeResult() |
| 345 | o.options = options |
| 346 | o.shape = shape |
| 347 | self.outputObjects.append(o) |
| 348 | |
| 349 | def debug(self, obj, args={}): |
| 350 | """ |
| 351 | Debug print/output an object, with optional arguments. |
| 352 | """ |
| 353 | s = ShapeResult() |
| 354 | s.shape = obj |
| 355 | s.options = args |
| 356 | self.debugObjects.append(s) |
| 357 | |
| 358 | def describe_parameter(self, var_data): |
| 359 | """ |
| 360 | Do Nothing-- we parsed the ast ahead of execution to get what we need. |
| 361 | """ |
| 362 | pass |
| 363 | |
| 364 | def add_error(self, param, field_list): |
| 365 | """ |
| 366 | Not implemented yet: allows scripts to indicate that there are problems with inputs |
| 367 | """ |
| 368 | pass |
| 369 | |
| 370 | def has_results(self): |
| 371 | return len(self.outputObjects) > 0 |
| 372 | |
| 373 | |
| 374 | class InvalidParameterError(Exception): |