Problems automating x2egg

I can’t be the only one to think of automating the conversion process, so hopefully there’s a solution to this…

What I’m trying to do should be fairly simple: Run x2egg.exe in python and pass it all the files in a folder to convert.

Problem is, I can’t even get it to run with an explicit file name and path, let alone a folders worth.

Here’s what I’ve tried so far, (not all at once mind you):

subprocess.call(['x2egg.exe', 'cube.x', 'cube.egg'])

os.system('x2egg.exe cube.x cube.egg')

subprocess.call(['.\\x2egg.exe', 'cube.x', 'cube.egg'])

os.system('.\\x2egg.exe cube.x cube.egg')

subprocess.call(['.\\x2egg.exe', 'cube.x', '-o', 'cube.egg'])

os.system('.\\x2egg.exe cube.x -o cube.egg')

subprocess.call(['.\\x2egg.exe', '-o', 'cube.egg', 'cube.x'])

os.system('.\\x2egg.exe -o cube.egg cube.x')

etc.

All of the above just return negative numbers like -1073741515 and don’t do a thing however. (I used print to check what it was returning)
I have a dummy.x file in the same folder as the .py and x2egg.exe. I’ve manually converted the file to an .egg using the command line, so the file is fine.

I did a sanity check and tried running another .exe file copied to the directory, which ran just fine… so I have no idea what could be wrong.

Here’s the .x file, in case that’s relevant. I’ve tried this with a few others, this one is just a small cube

xof 0303txt 0032

Frame Root {
  FrameTransformMatrix {
     1.000000, 0.000000, 0.000000, 0.000000,
     0.000000,-0.000000, 1.000000, 0.000000,
     0.000000, 1.000000, 0.000000, 0.000000,
     0.000000, 0.000000, 0.000000, 1.000000;;
  }
  Frame Cube {
    FrameTransformMatrix {
       1.000000, 0.000000, 0.000000, 0.000000,
       0.000000, 1.000000, 0.000000, 0.000000,
       0.000000, 0.000000, 1.000000, 0.000000,
       0.000000, 0.000000, 0.000000, 1.000000;;
    }
    Mesh { // Cube mesh
      8;
      -1.000000;-1.000000;-1.000000;,
      -1.000000; 1.000000;-1.000000;,
       1.000000; 1.000000;-1.000000;,
       1.000000;-1.000000;-1.000000;,
      -1.000000;-1.000000; 1.000000;,
      -1.000000; 1.000000; 1.000000;,
       1.000000; 1.000000; 1.000000;,
       1.000000;-1.000000; 1.000000;;
      6;
      4;0,1,5,4;,
      4;1,2,6,5;,
      4;2,3,7,6;,
      4;3,0,4,7;,
      4;3,2,1,0;,
      4;4,5,6,7;;
      MeshNormals { // Cube normals
        6;
        -1.000000; 0.000000; 0.000000;,
         0.000000; 1.000000;-0.000000;,
         1.000000; 0.000000;-0.000000;,
         0.000000;-1.000000; 0.000000;,
        -0.000000; 0.000000;-1.000000;,
        -0.000000; 0.000000; 1.000000;;
        6;
        4;0,0,0,0;,
        4;1,1,1,1;,
        4;2,2,2,2;,
        4;3,3,3,3;,
        4;4,4,4,4;,
        4;5,5,5,5;;
      } // End of Cube normals
    } // End of Cube mesh
  } // End of Cube
} // End of Root

If you want to convert only one file:

import subprocess
spam = subprocess.check_output(['x2egg', 'box.x', 'box.egg'])
print spam

Also check this out: [url]Models converter].

Following code will find all models in /models directory, it gona add them to list and then pass to x2egg.exe

import subprocess
import os

directory = 'models'

x_models_list = []

def x2egg():

    for filename in os.listdir(directory):
        if filename.endswith('.x'):
            x_models_list.append(filename)

    for model_name in x_models_list:
        try:
            print 'Working on: ' + model_name
            
            converted_model = os.path.splitext(model_name)[0]
            infile = directory + '\\' + model_name
            outfile = directory + '\\' + converted_model + '.egg'

            return_code = subprocess.check_output(['x2egg', infile, outfile])
            print return_code
        
        except:
            print 'error'

x2egg()

example.7z (33.7 KB)