How to activate/run another processing script using controlp5 button

115 Views Asked by At

My current folder structure is like

- Parent
   - Child1
      - Child1.pde 
   - controlp5_GUI
      - controlp5_GUI.pde
  

I plan to use controlp5 inside controlp5_GUI.pde. My final objective is to run child1.pde when the user clicks "Activate Script" button. Is this doable in controlp5? If so, how?

1

There are 1 best solutions below

8
On

You can use exec() to call the processing-java command line utility to launch Child1.pde. e.g.

Process sketch = exec("processing-java","--sketch=/absolute/path/to/yourSketch.pde","--run");

In your case controlp5_GUI.pde would call something like:

Process sketch = exec("processing-java","--sketch=/Users/mac/Desktop/xxx/Child1","--run");

There are a couple of caveats to take into account:

  1. You need processing-java to be included into the PATH environment variable (otherwise you will need provide the absolute path to processing-java which lives in the same folder as the processing executable (in the folder where you've installed Processing).
  2. The --sketch path needs to be absolute.

This similar answer might be helpful too.

If you need to control a sketch from another sketch using P5 you might find ControlP5's frame example useful.