BasicOperations/ImportWithNamespace.py

BasicOperations/ImportWithNamespace.py
1 # Copyright 2009 Autodesk, Inc. All rights reserved.
2 # Use of this software is subject to the terms of the Autodesk license agreement
3 # provided at the time of installation or download, or which otherwise accompanies
4 # this software in either electronic or hard copy form.
5 #
6 # Script description:
7 # Shows how to specify namespace of importation for Load/Merge of
8 # native MB file or for FBX file generated from a FBX plugin
9 #
10 # Topic: FBApplication, FBFbxOptions
11 #
12 
13 from pyfbsdk import *
14 import os
15 import os.path
16 
17 app = FBApplication()
18 sys = FBSystem()
19 
20 #Utility function to get the name of a file without extension
21 def getFileName(f):
22  d, filename = os.path.split(f)
23  if filename:
24  return os.path.splitext(filename)[0]
25  else:
26  return "unknown"
27 
28 # some constants for better clarity
29 NO_LOAD_UI_DIALOG = False
30 APPEND = False
31 MERGE = True
32 OPTIONS_FOR_LOAD = True
33 
34 #### These tests are design to test the load/Merge
35 #### of Native MB scene. It shows how to specify a namespace
36 #### of importation for all objects in the scene.
37 nativeFile = os.path.abspath( os.path.join( sys.ApplicationPath, r"..\system\primitives\Cube.fbx"))
38 print "Source File Path", nativeFile
39 
40 # set the namespace of importation to the name of the scene
41 options = FBFbxOptions(OPTIONS_FOR_LOAD)
42 options.NamespaceList = getFileName(nativeFile)+ "_open"
43 
44 # Open a file with a custom namespace appended to all objects
45 app.FileOpen( nativeFile, NO_LOAD_UI_DIALOG, options )
46 
47 # Append the same files with the same namespace appended. The renaming mecanims
48 # will rename the namespace instead of the objects.
49 options.NamespaceList = getFileName(nativeFile)+ "_append"
50 app.FileAppend( nativeFile, NO_LOAD_UI_DIALOG, options )
51 
52 # We want to merge so change the FBElementAction of all options.
53 options.NamespaceList = getFileName(nativeFile)+ "_open"
54 options.SetAll(FBElementAction.kFBElementActionMerge, True)
55 
56 # Merge with the objects loaded with the FileOpen
57 app.FileMerge( nativeFile, NO_LOAD_UI_DIALOG, options )
58