| 216 | } |
| 217 | |
| 218 | def run(self): |
| 219 | |
| 220 | options = self.options |
| 221 | content = self.content |
| 222 | state_machine = self.state_machine |
| 223 | |
| 224 | # only consider inline snippets |
| 225 | plot_code = "\n".join(content) |
| 226 | |
| 227 | # Since we don't have a filename, use a hash based on the content |
| 228 | # the script must define a variable called 'out', which is expected to |
| 229 | # be a CQ object |
| 230 | out_svg = "Your Script Did not assign call build_output() function!" |
| 231 | |
| 232 | try: |
| 233 | result = cqgi.parse(plot_code).build() |
| 234 | |
| 235 | if result.success: |
| 236 | out_svg = exporters.getSVG( |
| 237 | exporters.toCompound(result.first_result.shape) |
| 238 | ) |
| 239 | else: |
| 240 | raise result.exception |
| 241 | |
| 242 | except Exception: |
| 243 | traceback.print_exc() |
| 244 | out_svg = traceback.format_exc() |
| 245 | |
| 246 | # now out |
| 247 | # Now start generating the lines of output |
| 248 | lines = [] |
| 249 | |
| 250 | # get rid of new lines |
| 251 | out_svg = out_svg.replace("\n", "") |
| 252 | |
| 253 | txt_align = "left" |
| 254 | if "align" in options: |
| 255 | txt_align = options["align"] |
| 256 | |
| 257 | lines.extend((template % locals()).split("\n")) |
| 258 | |
| 259 | lines.extend(["::", ""]) |
| 260 | lines.extend([" %s" % row.rstrip() for row in plot_code.split("\n")]) |
| 261 | lines.append("") |
| 262 | |
| 263 | if len(lines): |
| 264 | state_machine.insert_input(lines, state_machine.input_lines.source(0)) |
| 265 | |
| 266 | return [] |
| 267 | |
| 268 | |
| 269 | class cq_directive_vtk(Directive): |