We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › CMD line pde-->java converter
Page Index Toggle Pages: 1
CMD line pde-->java converter (Read 2623 times)
CMD line pde-->java converter
Sep 22nd, 2009, 6:33am
 
I'm looking for a way to convert (in batch, from the shell) a large set of .pde sketches to .java. I know that I could do it manually by exporting the sketch, but I would like to do it automatically through programming.

I remember the courseware in the ALPHA, I would think Reas and Fry came with a way to do it. I'm not able to find a way proper way to do it.

I was thinking to something like
Code:
java processing --convertToJava mySketch.pde 



or maybe someone could suggest something better?
Re: CMD line pde-->java converter
Reply #1 - Sep 22nd, 2009, 8:23am
 
That's not automated, but you can already look at the temporary files generated by Processing when you run a sketch: among them, there are .java files, which are what you are looking for.

I can imagine some automating tool (eg. AutoHotkey for Windows) running the PDE and fetching the files...

PDE is supposed to have a command line interface, but last time I checked it wasn't finished/working. Perhaps it needs just a little work to put it in shape.

You can also study Processing source and see how it does the pre-processing stuff (adding default imports, changing color to int, int() or float() to function calls, adding F after literal number with decimal points, wrapping raw code inside a setup(), wrapping the whole in a class, etc.), which is what you need.
Re: CMD line pde-->java converter
Reply #2 - Sep 22nd, 2009, 8:54am
 
Browse the source (under the "app" folder) for Commander - that's the guy that does it, and the source code is all the docs you're likely to find.

I'll use MS .bat file syntax for example, modify as req for your os.  Go to processing's home directory and create a "compile.bat" file.  (i think it's currently required you run it from here due to problems finding preferences.txt otherwise)  Start by specify the relevant paths, (because it helps clarify the the command line example yet to come)  for example:

set JDKHOME=x:\jdk16
set P5HOME=x:\processing-1.0.6
set SKETCH=x:\sketches\nameofsketchtocompile

Then, the command line, for example:

%JDKHOME%\bin\java.exe -cp %JDKHOME%\lib\*;%P5HOME%\lib\* processing.app.Commander --sketch=%SKETCH% --export-applet --output=%SKETCH%\applet

(pass "--help" to the Commander for other options if "--export-applet" wasn't what you're after)
Re: CMD line pde-->java converter
Reply #3 - Sep 22nd, 2009, 6:03pm
 
Thank you very much both, this is what I was looking for.

Code:
out.println("Processing " + Base.VERSION_NAME + " rocks the console."); 

It rocks... Wink

This comes from: http://dev.processing.org/source/index.cgi/trunk/processing/app/src/processing/app/Commander.java?rev=5608&view=markup

I not able to make it run yet (I still don't have jdk6 on this WIN machine, and I think I'm having issues with "c:/long names"). I can run it, but he can't find the preferences file. I'll try again tomorrow on Ubuntu.

Code:
java -cp pde.jar;jna.jar;ecj.jar;core.jar;antlr.jar;"C:\Program Files\Java\jdk1.5.0_04\lib\tools.jar"  processing.app.Commander --sketch=C:\fullPath\toSketch\ --export-applet --output="C:\fullPath\toSketch\applet" 



Here's the help dump:
Code:
Processing 0163 rocks the console.

--help   Show this help text.

--sketch=<name> Specify the sketch folder (required)
--output=<name> Specify the output folder (required and
  cannot be the same as the sketch folder.)

--preprocess   Preprocess a sketch into .java files.
--build  Preprocess and compile a sketch into .class files.
--run    Preprocess, compile, and run a sketch.
--present Preprocess, compile, and run a sketch full screen.

--export-applet Export an applet.
--export-application Export an application.
--platform     Specify the platform (export to application only).
  Should be one of 'windows', 'macosx', or 'linux'.

--preferences=<file> Specify a preferences file to use (optional).
Re: CMD line pde-->java converter
Reply #4 - Sep 23rd, 2009, 8:47am
 
Will rock one day...
http://dev.processing.org/bugs/show_bug.cgi?id=1048

It seems that command line is not working yet. No luck on linux. I still have:
Code:
Exception in thread "main" java.lang.NullPointerException
at processing.app.Sketch.preprocess(Sketch.java:1417)
at processing.app.Sketch.build(Sketch.java:1473)
at processing.app.Sketch.exportApplet(Sketch.java:1514)
at processing.app.Commander.<init>(Commander.java:214)
at processing.app.Commander.main(Commander.java:95)


for
Code:
java processing.app.Commander --sketch=/sketch/mySketch --export-applet --output=/sketch/mySketch/applet 



I'm using the processing.sh for importing class and jars.

But, magically, processing crash just after the preprocessor (after creating the JAVA file). This is what I was looking for at the end. The complete applet is not created.
Re: CMD line pde-->java converter
Reply #5 - Sep 24th, 2009, 4:36am
 
On Linux, I got it working (for an application)

Code:

> cd /your/processing/installation
> java -cp lib/antlr.jar:lib/core.jar:lib/ecj.jar:lib/pde.jar:java/lib/tools.jar  processing.app.Commander --sketch=/sketch/mySketch --export-application --output=/sketch/mySketch/export

Notice the ":"s between the jar paths, that's a Linux thing.

Now make it executable and off you go
Code:

> chmod u+x /sketch/mySketch/export/mySketch
> /sketch/mySketch/export/mySketch
Re: CMD line pde-->java converter
Reply #6 - Sep 24th, 2009, 6:32am
 
gll wrote on Sep 22nd, 2009, 6:03pm:
Code:
java -cp pde.jar;jna.jar;ecj.jar;core.jar;antlr.jar;"C:\Program Files\Java\jdk1.5.0_04\lib\tools.jar"  processing.app.Commander --sketch=C:\fullPath\toSketch\ --export-applet --output="C:\fullPath\toSketch\applet" 


I tried on Windows as well. I don't have spaces in my paths...
I did:
Code:
java -cp lib/pde.jar;lib/jna.jar;lib/ecj.jar;lib/core.jar;lib/antlr.jar;C:/Java/jdk1.6.0_13/lib/tools.jar processing.app.Commander --sketch=E:/Dev/PhiLhoSoft/Processing/Bezier --export-applet --output=E:/Dev/PhiLhoSoft/Processing/Bezier/applet 

in the Processing install dir (C:/Java/processing-1.0.5) and it worked.
You can simplify by copying tools.jar in the lib dir. Or quote the whole cp parameter, not just one path.
Re: CMD line pde-->java converter
Reply #7 - Sep 24th, 2009, 8:09am
 
fwiw, i install jdk to a simple path like "\jdk16" to avoid long paths in -cp or CLASSPATH (plus it's easier to type!).  and, worth repeating, currently you HAVE to run this from processing home (processing's "lib" subfolder needs to appear local for several reasons).  hth
Page Index Toggle Pages: 1