starting contextfree from an external program(Java)

If you're having trouble using Context Free or don't understand the language, ask for help here.

Moderators: MtnViewJohn, chris, mtnviewmark

Post Reply
Veliko
Posts: 4
Joined: Sun Oct 16, 2011 5:36 am

starting contextfree from an external program(Java)

Post by Veliko »

Hello to all!

I would like to ask how can I execute code in CF from external program like Java and also command CF from Java to save a picture.
I succeeded to open CF from Java using
Process proc = Runtime.getRuntime().exec("C:/Program Files (x86)/OzoneSoft/ContextFree/ContextFree.exe");
The class Process can also be used with 2 arguments - the second argument is an array of Strings - instructions to the external program(see http://www.javaworld.com/javaworld/jw-1 ... tml?page=1) . The problem is that i don't know how to write the instructions ot CF in the String array.

Thanks in advance!

User avatar
MtnViewJohn
Site Admin
Posts: 882
Joined: Fri May 06, 2005 2:26 pm
Location: Mountain View, California
Contact:

Re: starting contextfree from an external program(Java)

Post by MtnViewJohn »

The command options for cfdg are :

Code: Select all

john@Aluminium   ~/Projects/CF3xc4
[1003] : ./cfdg -?
cfdg - 3.0beta(v13)

Usage: 
cfdg [options] input.cfdg [output.png/svg]
    or to pipe a cfdg file on standard input:
cfdg [options] - [output.png/svg]
If the output file name is omitted and the -o option and the -C option are not used
then the output will be sent to stdout.

Options: 
    -w num    width in pixels(png) or mm(svg) (default 500)
    -h num    height in pixels(png) or mm(svg) (default 500)
    -s num    set both width and height in pixels/mm
    -m num    maximum number of shapes (default none)
    -x float  minimum size of shapes in pixels/mm (default 0.3)
    -b float  border size [-1,2]: -1=-8 pixel border, 0=no border,
              1=8 pixel border, 2=variable-sized border
    -v str    set the variation code (default is random)
    -o str    set the output file name, supports variable expansion
              %f expands to the animation frame number,
              %v and %V expands to the variation code in lower or upper case,
              %% expands to %
    -a num    generate num animation frames (PNG only)
    -z        zoom out during animation
    -V        generate SVG (vector) output
    -c        crop image output
    -q        quiet mode, suppress non-error output
    -C        Check syntax, check syntax of cfdg file and exit
    -t        time output, output the time taken to render the cfdg file
    -?        show this message, then exit


john@Aluminium   ~/Projects/CF3xc4
[1004] : 
So the first string in the array would contain the path to the cfdg binary. The second string would be "-w". The third string would be the width. The fourth would be the string "-h". The fifth string would be the height. And so on... The second to last string would be the path to the cfdg file and the last string would be the path to the output file. Do not bother with the environment variable string array, cfdg does not pay attention to them.

Veliko
Posts: 4
Joined: Sun Oct 16, 2011 5:36 am

Re: starting contextfree from an external program(Java)

Post by Veliko »

MtnViewJohn wrote:The command options for cfdg are :

So the first string in the array would contain the path to the cfdg binary. The second string would be "-w". The third string would be the width. The fourth would be the string "-h". The fifth string would be the height. And so on... The second to last string would be the path to the cfdg file and the last string would be the path to the output file. Do not bother with the environment variable string array, cfdg does not pay attention to them.
Thank you for your assitance!
I tried to follow the instructions but it seems that i don't do something right. My program starts CF but doesn't produce any picture in the folder nor it draws in CF . Here is the code

import java.io.IOException;
public class start_CF_from_Java {
public static void main(String[] args) throws IOException{
String[] code=new String[11];
code[0]="C:/Program Files (x86)/OzoneSoft/ContextFree/ContextFree.exe";
code[1]="-w";
code[2]="100";
code[3]="-h";
code[4]="100";
code[5]="-o";
code[6]="picture.png";
code[7]="-m";
code[8]="200";
code[9]="D:/code1.cfdg";
code[10]="D:/picture.png";

Process proc = Runtime.getRuntime().exec(code);
}
}
Please take a look.
Thanks in advance.

User avatar
MtnViewJohn
Site Admin
Posts: 882
Joined: Fri May 06, 2005 2:26 pm
Location: Mountain View, California
Contact:

Re: starting contextfree from an external program(Java)

Post by MtnViewJohn »

Try this:
  • Eliminate code[5] and code[6], they are not useful for this situation
  • Maybe get rid of code[7] and code[8]. Setting such a low shape maximum seems kind of odd to me
  • Replace code[0] with "C:\\Program Files (x86)\\OzoneSoft\\ContextFree\\ContextFree.exe"
  • Replace code[9] with "D:\\code1.cfdg" and code[10] with "D:\\code1.png"

Post Reply