Easiest way to convert ~500 '.obj' files to '.bgeo'?

   6517   11   4
User Avatar
Member
48 posts
Joined: Feb. 2017
Offline
Just trying to get some geometry from another programme into Houdini's native format.
User Avatar
Staff
2591 posts
Joined: July 2005
Offline
import sys, os
for f in os.listdir("."):
    if f.endswith('.obj'):
        geo = f.replace('.obj', '.bgeo')
        cmd = 'gconvert %s %s' % (f, geo)
        print cmd
        if os.system(cmd):
             print 'Error running command'
             break
User Avatar
Staff
727 posts
Joined: Oct. 2012
Offline
You can use Houdini's gconvert command line tool to convert between formats (e.g. ‘gconvert file.obj file.bgeo’)
User Avatar
Member
48 posts
Joined: Feb. 2017
Offline
Where should I run the script? I just pasted into a ‘.py’ file in the folder where the geometry is, but ‘gconvert’ is not recognised.
User Avatar
Member
7 posts
Joined: April 2015
Offline
Did you run it from the Houdini terminal?
User Avatar
Member
48 posts
Joined: Feb. 2017
Offline
Oluf Andrews
Did you run it from the Houdini terminal?

No, not sure how I would do that.
User Avatar
Member
7 posts
Joined: April 2015
Offline
When you installed Houdini, one of the applications that was also installed was Houdini Terminal. That opens a terminal with all the environment / path settings set correctly. I'm on my mac right now with 15.5 so I can't confirm PC, but the application here is actually named “Houdini Terminal”.
User Avatar
Member
48 posts
Joined: Feb. 2017
Offline
I'm on Windows, using the apprentice edition of Houdini. Can't find such a ‘Houdini Terminal’ programme.
User Avatar
Member
74 posts
Joined:
Offline
In Windows it is called “Command Line Tools”. You find it in your Houdini installation path in the “Utilities” folder.
User Avatar
Member
48 posts
Joined: Feb. 2017
Offline
Thank you very much, the script worked. Here is a more friendly version for others to see:

Copy and paste this to a text file and save as a ‘.py’ instead of ‘.txt’. Be warned, this will overwrite existing ‘.bgeo’ files if they have the same name as the ‘.obj’ file.

# Converts all the '.obj' files in a folder to '.bgeo' files, using the
# 'gconvert' Houdini command, as such this script requires Houdini to be
# installed.
# Run using 'Command Line Tools' on Windows, and  'Houdini Terminal' on
# OSX.
import sys, os
folder = "." # If the script is in another folder to the '.obj' files, put
             # the path in this string.
for file in os.listdir(folder):
    if file.endswith('.obj'):
        path = folder + "/" + file
        geo = folder + "/" + file.replace('.obj', '.bgeo')
        command = 'gconvert %s %s' % (path, geo)
        print(command)
        if os.system(command):
            print('Error running command.')
            break
Edited by KalciferKandari - March 23, 2017 14:39:44
User Avatar
Member
182 posts
Joined: April 2009
Offline
If you're on Windows, then you can create a simple batch script and put it in your “Send To” rightclick menu ( On windows 7 at least ).

Hit the windows key and type shell:sendto
It should open a folder >> C:\Users\your.username\AppData\Roaming\Microsoft\Windows\SendTo

Create a new textfile like _convert_to_bgeo, rename .txt to .bat and edit it:
( also change the path to your gconvert.exe )
@echo off
for %%i in (%*) do (
echo "converting %%~ni to bgeo.sc ..."
START /WAIT "" "C:\Program Files\Side Effects Software\Houdini 16.0.556\bin\gconvert.exe" "%%~nxi" "%%~dpi\%%~ni.bgeo.sc"
echo "done."
)

Now select your OBJ files and right click > Send To > _convert_to_bgeo.bat.
Your files will now be converted one by one to bgeo.sc.
If you take out the /WAIT then it will launch a new process for each file.
This might be a bad idea with 500 files, but it's certainly faster if you have the resources.

You can do the same thing with textures to .rat files with iconvert.exe
Edited by blackpixel - March 25, 2017 03:02:04
User Avatar
Member
11 posts
Joined: April 2018
Offline
Apologies for reviving an old thread here. I'm wondering if it would be possible to amend this script to make it work inside a series of folders, not just a single directory?
I have a workflow which will generate a large series of folders with .obj sequences inside each - is there a way I can make this script look inside each subfolder and make the conversion to everything in one go?

Thanks for any advice
Edited by JH12345 - Sept. 1, 2019 04:16:09
  • Quick Links