
import com.ptc.cipjava.*;
import com.ptc.pfc.pfcSession.*;
import com.ptc.pfc.pfcGlobal.*;
import com.ptc.pfc.pfcCommand.*;
import com.ptc.pfc.pfcModel.*;
import com.ptc.pfc.pfcSolid.*;
import com.ptc.pfc.pfcModelItem.*;

public class KickOff_VRML {

	public KickOff_VRML () {}

	private static Session curSession=null;
	private static final String VRMLdirectory = ".\\vrml";
	private static Model model;
	private static String file_name="";
	private static VRMLModelExportInstructions vrml_instrs;

	public static void start() {

		try {
			curSession = pfcGlobal.GetProESession();
		}
		catch (jxthrowable x) {
      		System.out.println ("Error Retrieving ProE: " + x);
      		x.printStackTrace ();
    	}
		try {
			UICommand inputCommand = curSession.UICreateCommand("Make VRML", new VRML_Listener());

			curSession.UIAddButton(inputCommand,
									"Applications",
									"Applications.psh_util_pproc",
									"Make_VRML",
									"Create_VRML",
									"vrml.txt");
		}
		catch(jxthrowable x) {
			System.out.println("Exception in UIAddButton():"+x);
			return;
		}
	}

	public static void stop() {}

	public static void MakeVRML() {

		ModelType modelType = ModelType.MDL_PART;

		try {
			model=curSession.GetCurrentModel();

			vrml_instrs = pfcModel.VRMLModelExportInstructions_Create(VRMLdirectory);
			model.Export(file_name, vrml_instrs);
		}
		catch (jxthrowable x) {
			System.out.println ("Caught exception: "+x);
			x.printStackTrace ();
		}
	}
}

class VRML_Listener extends DefaultUICommandActionListener {

    public void OnCommand () {
		KickOff_VRML.MakeVRML();
	}
}
