(self, p)
| 289 | p.t(0, -ah) |
| 290 | |
| 291 | def apply_script(self, p): |
| 292 | from runpy import run_path |
| 293 | from tempfile import NamedTemporaryFile |
| 294 | |
| 295 | res = None |
| 296 | if self.st2.script_mode == "FILE" and self.st2.script_file: |
| 297 | try: |
| 298 | res = run_path(self.st2.script_file, init_globals=dict(bpy=bpy)) |
| 299 | except Exception as e: |
| 300 | print("Could not run script", e) |
| 301 | elif self.st2.script_mode == "BLOCK": |
| 302 | try: |
| 303 | script_text = bpy.data.texts[self.st2.script_block].as_string() |
| 304 | if script_text: |
| 305 | tmp_path = None |
| 306 | with NamedTemporaryFile("w", suffix=".py", delete=False) as tf: |
| 307 | tf.write(script_text) |
| 308 | tmp_path = Path(tf.name) |
| 309 | try: |
| 310 | res = run_path(tmp_path) |
| 311 | except Exception as e: |
| 312 | print("Could not run block", e) |
| 313 | finally: |
| 314 | tmp_path.unlink() |
| 315 | except KeyError: |
| 316 | print("No block with that name") |
| 317 | |
| 318 | if res: |
| 319 | if "modify" in res: |
| 320 | fn = res["modify"] |
| 321 | arg_count = len(inspect.signature(fn).parameters) |
| 322 | |
| 323 | def fe(i): |
| 324 | duration = bpy.context.scene.frame_end - bpy.context.scene.frame_start |
| 325 | fc = bpy.context.scene.frame_current |
| 326 | fa = (fc+i)%duration |
| 327 | return fa/duration |
| 328 | |
| 329 | funcs = ModifyFunctions(fe) |
| 330 | |
| 331 | args = [self.st2] |
| 332 | if arg_count > 1: |
| 333 | try: |
| 334 | args.append(eval(f"dict({self.st2.script_kwargs})")) |
| 335 | except Exception as e: |
| 336 | print(e) |
| 337 | print("failed to parse kwargs") |
| 338 | args.append({}) |
| 339 | |
| 340 | if arg_count > 2: |
| 341 | args.append(p) |
| 342 | |
| 343 | if arg_count > 3: |
| 344 | args.append(funcs) |
| 345 | |
| 346 | return fn(*args) |
| 347 | #if output is not None: |
| 348 | # txtObj.draw(output, set_origin=False, fill=False) |
no test coverage detected