Start a new topic

convert flt to fbx using of api

This is kind of a duplicate of some questions previously posted in this forum, but the most relevant one doesn't have an answer.  I'd like to run a command line tool to convert from flt to fbx.  Using the code snipppets I get the following that does absolutely naught in terms of output:


 

######################################################
#
# script conversion flt to fbx
import os
import sys

# import OpenFlight API module
from mgapilib import *

# disable generic OFAPI messages (otherwise they echo)
######################################################

mgSetMessagesEnabled (MMSG_STATUS, MG_FALSE)
mgSetMessagesEnabled (MMSG_WARNING, MG_FALSE)
mgSetMessagesEnabled (MMSG_ERROR, MG_FALSE)

mgInit (None, None)

if sys.argv[-1]:
	f_input = sys.argv[-1]
	try:
		db = mgOpenDb (f_input)
		#print(type(db))
	except:
		print('unable to open db file!')
		msgbuf = mgGetLastError()
		print (msgbuf, "\n")
		mgExit()

base_f_name, f_ext = os.path.splitext(f_input)
# print(base_f_name, f_ext)

f_out = os.path.join(base_f_name + '.fbx')


paramBlock = mgGetParamBlockDbExporter ("D5637D1C-F499-4726-8CF9-333C68F68D8E")
mgParamSetBool (paramBlock, "Convert RGB Textures", MG_TRUE)
# set TRUE
mgParamSetBool (paramBlock, "Embed Textures", MG_TRUE)
mgParamSetBool (paramBlock, "Include External References", MG_FALSE)
mgParamSetString (paramBlock, "LOD Export Option", "All LODs")
mgParamSetString (paramBlock, "Output Format", "Binary")
mgParamSetString (paramBlock, "Switch Export Option", "Export Active Switches Only")
mgParamSetString (paramBlock, "Version Export Option", "")

mgExportDb (db, f_out, "D5637D1C-F499-4726-8CF9-333C68F68D8E", None, paramBlock)

ok = mgCloseDb(db)

mgExit()

 

Thanks!


One important element that is missing from this script is the mandatory line of code to point the API to the plugins folder. Basically, fbx inport and export is a plugin. This plugin needs to be loaded by the API or your mgExport will not work. Take a look at the OpenFlight user guide documents, they go into great detail about import and export using plugins. They key thing to do though is to set your plugin folder before you call mginit. If you are only using fbx plugin, then I would set the plugin folder to point only to the fbx plugin.


before line 17, try something like:

mgSetPluginFolder ('C:\\Presagis\\Suite22\\OpenFlight_API_22_0\\bin_x64\\release\\plugins\\fbx')

 

Thanks!  That did not seem to work for me.


D:\utils>dir C:\\Presagis\\Suite22\\OpenFlight_API_22_0\\bin_x64\\release\\plugins\\fbx

The specified path is invalid.

 


D:\utils>dir C:\Presagis\Suite22\OpenFlight_API_22_0\bin_x64\release\plugins\fbx

 Volume in drive C is System

 Volume Serial Number is 0A5A-C89E

 


 Directory of C:\Presagis\Suite22\OpenFlight_API_22_0\bin_x64\release\plugins\fbx


05/08/2023 12:42 PM <DIR> .

05/08/2023 12:42 PM <DIR> ..

02/14/2022 08:53 AM 7,299,072 fbx.dll

               1 File(s) 7,299,072 bytes

               2 Dir(s) 516,353,929,216 bytes free

  

######################################################
#
# script conversion flt to fbx
import os
import sys

# import OpenFlight API module
from mgapilib import *

# must specify plugin location per OFAPI
mgSetPluginFolder ('C:\\Presagis\\Suite22\\OpenFlight_API_22_0\\bin_x64\\release\\plugins\\fbx')
#mgSetPluginFolder ('C:\Presagis\Suite22\OpenFlight_API_22_0\bin_x64\release\plugins\fbx')


# disable generic OFAPI messages (otherwise they echo)
######################################################

mgSetMessagesEnabled (MMSG_STATUS, MG_FALSE)
mgSetMessagesEnabled (MMSG_WARNING, MG_FALSE)
mgSetMessagesEnabled (MMSG_ERROR, MG_FALSE)

mgInit (None, None)



if sys.argv[-1]:
	f_input = sys.argv[-1]
	try:
		db = mgOpenDb (f_input)
		#print(type(db))
	except:
		print('unable to open db file!')
		msgbuf = mgGetLastError()
		print (msgbuf, "\n")
		mgExit()

base_f_name, f_ext = os.path.splitext(f_input)
# print(base_f_name, f_ext)

f_out = os.path.join(base_f_name + '.fbx')


paramBlock = mgGetParamBlockDbExporter ("D5637D1C-F499-4726-8CF9-333C68F68D8E")
mgParamSetBool (paramBlock, "Convert RGB Textures", MG_TRUE)
# set TRUE
mgParamSetBool (paramBlock, "Embed Textures", MG_TRUE)
mgParamSetBool (paramBlock, "Include External References", MG_FALSE)
mgParamSetString (paramBlock, "LOD Export Option", "All LODs")
mgParamSetString (paramBlock, "Output Format", "Binary")
mgParamSetString (paramBlock, "Switch Export Option", "Export Active Switches Only")
mgParamSetString (paramBlock, "Version Export Option", "")

mgExportDb (db, f_out, "D5637D1C-F499-4726-8CF9-333C68F68D8E", None, paramBlock)

ok = mgCloseDb(db)

mgExit() 

  

flt
(14.7 KB)

Does that directory exist on your machine? I notice a D drive. could it be that the OpenFlight API's Plugin folder is somewhere other than the devault directory?


Hi Chris,


If I copy the text from the script windows says the folder doesn't exist, but single \ and it does.  I have both sets in the script.When I use single \ the script runs but fails to produce output.  It also doesn't print any errors.


Thx!

The problem is \ is a reserved character that triggers different characters in strings. so \t is a tab character. To avoid all this try converring all the \ characters to / characters.


 Like this:

mgSetPluginFolder ('C:/Presagis/Suite22/OpenFlight_API_22_0/bin_x64/release/plugins/fbx')

 

Hi Chris,


That 'works' - no errors when the script runs - but it doesn't actually do anything, ie. produce said fbx from the flt file.

Login to post a comment