Load and export files¶
import_export.py¶
1# @@YEAR@@ Autodesk, Inc. All rights reserved.
2#
3# Example to show how to import and export files
4#
5# vrFileIOService is used to load a WRL file
6# vrFileIOService is used to load a OSB file
7# vrFileIOService is used to export nodes as FBX file as different FBX file versions
8# vrdFileExportSettings is used to configure export settings
9#
10
11# Start with an empty scene
12newScene()
13
14# Import file names
15theLogo = "/geo/alpha.wrl"
16theTeddyBear = "/geo/teddy.osb"
17
18# Node names of loaded files
19theTeddyName = "Teddy_Bear"
20theLogoName = "alpha"
21
22# Export file template name
23theExport = "/export{}.fbx"
24
25# All FBX file version
26theVersions = ["FBX-2020", "FBX-2019", "FBX-2018", "FBX-2016+2017", "FBX-2014+2015", "FBX-2013", "FBX-2012", "FBX-2011"]
27
28# All FBX file version ids, same order as in theVersions
29theVersionIDs = [0, 2019, 2018, 2016, 2014, 2013, 2012, 2011]
30
31# Load a file from the examples
32def loadFromExampleFolder(theName):
33 theDir = vrFileIO.getVREDExamplesDir()
34 theFile = theDir + theName
35 return vrFileIOService.loadFile(theFile)
36
37
38# Load the Teddy and the Logo example and add them to the scene
39def loadExamples():
40 # Import two files from example directory
41 if not loadFromExampleFolder(theLogo):
42 vrLogError("Can't load WRL file.")
43 return False
44 if not loadFromExampleFolder(theTeddyBear):
45 vrLogError("Can't load OSB file.")
46 return False
47 return True
48
49
50# Export a FBX file with different FBX file version to the VRED data directory
51# We assume that the two files have already been loaded sucessfully
52def exportFile(theName, theVersionID):
53 global theTeddyName
54 global theLogoName
55
56 # Build the file path
57 theDir = vrFileIO.getVREDDataDir()
58 theFile = theDir + theName
59 vrLogInfo("Save FBX file " + theFile)
60
61 # Query the top level nodes from the two loaded files
62 theTeddy = vrNodeService.findNode(theTeddyName)
63 theLogo = vrNodeService.findNode(theLogoName)
64 theNodes = [ theTeddy, theLogo ]
65
66 # First query the current export settings for this file type
67 theSettings = vrFileIOService.getExportSettings(vrCADFileTypes.FileType.FBX)
68
69 # Apply changes to the FBX settings
70 theSettings.setExportEnvironmentGeometries(False)
71 theSettings.setFbxVersionId(theVersionID)
72
73 # After the export settings have been changed, you need to write the changed settings
74 # back to the file I/O service
75 vrFileIOService.setExportSettings(vrCADFileTypes.FileType.FBX, theSettings)
76
77 # Export all nodes from the two loaded files
78 return vrFileIOService.exportNodes(theFile, theNodes)
79
80
81# Now we load the two example files and then export them as different FBX format versions
82if loadExamples():
83 # Export as a FBX file with different FBX file version settings
84 for i in range(len(theVersions)):
85 theFile = theExport.format(theVersions[i])
86 exportFile(theFile, theVersionIDs[i])