Python 3 API: Upgrading Vortex Files

The following functions are available in the Vortex Python API. They are helper functions that perform the upgrade of existing Vortex files to the current version of Vortex.

For example, the part document has been removed in 2020b, any parts will be saved properly into their parent Assembly. VHL Interfaces were removed from the Assembly and replaced with a Linking interface.

Listing children files: getFiles()

From a document e.g. scene, list the files used by that definition e.g. mechanisms, assemblies.

This can be done by using either the parent fileName of the object itself if it is already loaded.

  • Vortex.getFiles('my_scene.vxscene')
  • Vortex.getFiles(my_sceneObject)

The return value is a list of ObjectFileInfo, containing the following information: 

  • fileName: Name of the child file
  • fileInfo: Version of the software when the file was saved
  • error: Any error encountered during the processing


# Getting the child file information from my scene file.
files = Vortex.getFiles('my_scene.vxscene')
for f in files:
	print(f.fileName)



Upgrading to the latest version 

Upgrading a single document and its children: upgradeObject()

From a document e.g. scene, upgrade the file and it's children used by that definition e.g. mechanisms, assemblies.

This can be done by using either the parent fileName of the object itself if it is already loaded.

  • Vortex.upgradeObject('my_scene.vxscene')
  • Vortex.upgradeObject(my_sceneObject)

The return value is a list of ObjectFileInfo, containing the following information: 

  • fileName: Name of the file upgraded
  • fileInfo: Version of the software saved
  • error: Any error encountered during the processing


# Getting the child file information from my scene file.
files = Vortex.upgradeObject('my_scene.vxscene')
for f in files:
	print(f.fileName + ' has been saved to the latest version')


Upgrading a single document: upgradeFiles()

Upgrade a list of files to the latest version.

This can be done by using either the return value of getFiles() or passing a list os file name.

  • Vortex.upgradeFiles(listOfReturnValueOfMultiplesCallsToGetFiles())
  • Vortex.upgradeFiles(listOfFiles)

The return value is a list of ObjectFileInfo, containing the following information: 

  • fileName: Name of the file upgraded
  • fileInfo: Version of the software saved
  • error: Any error encountered during the processing


# processing all files in a directory
def processDirectory(directory)
	allfiles = []
	for file in directory	
		allfiles.append(Vortex.getFiles(file))

	return allfiles; 

#... get the directory information
filesToProcess = processDirectory(d)

# ... display information or use some algorithm to filter out some file
filesProcessed = Vortex.upgradeFiles(filesToProcess)

# ... display information       
        


Upgrading a Python 2 script extension to Python 3 dynamics script extension

It is also possible to upgrade Python 2 extension to the new python 3 dynamics extension.

Like the Vortex Editor Tool, the conversion does not actually convert the code but otherwise, the extension is effectively replaced.

To get a list of the files with one or more Python 2 extensions, do the following:

# Getting the all files with a Python 2 extensions.
files = Vortex.getFilesWithSimulationScript(rootDir)
for f in files:
	print(f.fileName)



Then, each content file with a Python 2 script can be upgraded

Contrary to the editor, this process cannot be undone.
Also, if the Python 2 Script extension had an external script file (.py), the Dynamics Script extension will use the same file.


# Getting the all files with a Python 2 extensions.
files = Vortex.getFilesWithSimulationScript(rootDir)
for f in files:
	fileInfo = Vortex.upgradeSimulationScripts(f.fileName)
    # Print upgrade log
    print(fileInfo.details)