Collada Export via a Java-Tool

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
armandokengne
Posts: 0
Joined: Mon Aug 19, 2013 2:25 pm

Collada Export via a Java-Tool

Post by armandokengne » Fri Aug 23, 2013 4:57 pm

Hello,
i wrote this Java Tool to Export WRL-Format to DAE-Format but doesn't work!! Only Blender ist started, and nothing else. And I don't no why. Someone can help me please

Java-Code:

Code: Select all


    public class Converter {

       /**
        * @param args
        */
       public static void main(String[] args) {
          Runtime rt = Runtime.getRuntime();
          String[] callAndArgs1 = {"C:\\Program Files\\Blender Foundation/Blender/blender.exe", "C:\\Users\\Desktop\\Scripting.py" };
          try {
          Process child = rt.exec(callAndArgs1);
          child.waitFor();
          System.out.println("Blender:: Process exit code is:" +  child.exitValue());
          }
          catch(IOException e) {
          System.err.println(
           "Blender:: IOException starting process!");
          }
          catch(InterruptedException e) {
          System.err.println(
           "Blender:: Interrupted waiting for process!");
          }
    }
The Py-Data "Scripting.py":

Code: Select all

    # -*- coding: utf-8 -*-
    import bpy
    bpy.ops.object.select_all(action='TOGGLE')
    bpy.ops.object.delete(use_global=False)
    bpy.ops.import_scene.x3d(filepath="C:\\3D-Data\\test.wrl", filter_glob="*.wrl", axis_forward='Y', axis_up='Z')
    bpy.ops.wm.collada_export(filepath="C:\\3D-Data\\test.dae")
    bpy.ops.file.execute()
    bpy.ops.wm.quit_blender()

What ist wrong in these Codes? :( :roll:
-------------------------------------------------------------------------------

Another Question: How cann I export via Scripting (Python command) with Blender all drawings (with the same format (WRL)) from a odner together to a new format (DAE) and keep the same original filename (drawingname)? how can i do it? (please, which commands(scripting))

Thanks!!

Armand

stiv
Posts: 0
Joined: Tue Aug 05, 2003 7:58 am
Location: 45N 86W

Post by stiv » Fri Aug 23, 2013 6:32 pm

String[] callAndArgs1 = {"C:\\Program Files\\Blender Foundation/Blender/blender.exe", "C:\\Users\\Desktop\\Scripting.py" };
Looks like you have the executable name (blender), the script to run (scripting.py), but no flags or switches to tell blender what to do with that file.

Run 'blender -h' at the command line to see all the options. Hint: -P is your friend.

armandokengne
Posts: 0
Joined: Mon Aug 19, 2013 2:25 pm

Post by armandokengne » Tue Aug 27, 2013 1:29 pm

Hi Stiv, thank you,
I don't know how can I add a Flag to the Codes. Can you tell me how I cann do it? or give me some example.

Armand

stiv
Posts: 0
Joined: Tue Aug 05, 2003 7:58 am
Location: 45N 86W

Post by stiv » Wed Aug 28, 2013 6:51 am

The endgame here is to end up with a complete command like "blender -P some_script.py"

In python, you can do something like:

Code: Select all

mport os

cmd = 'blender'
flags = ' -P '
script = 'some script.py'
space = '  '

# our final cmd is 'blender -P some_script.py'
os.system( cmd + space + flags + space + script )
The Java code looks like it take a string array, so likely you can put any necessary flags ( the -P in our case) as a separate string.

geeky notes:

* It looks like java provides an interface to the C function exec() that takes a command and a set of arguments

* real pythoneers would write " ".join( (cmd, flags, script) to get the final command

Post Reply