Vizard 7 » Reference » Publishing as an EXE » Publishing as an EXE
7.6

Publishing as an EXE

Introduction

Publishing your simulation as an executable is a new bundled feature that “compiles” your simulation—including all scripts and resource files—into a single .EXE package. The compiled package will work as a fully functional Vizard script with the notable difference being that it can run on any machine without Vizard being installed. There is a restriction, though; “compiled” simulations cannot be edited or modified (i.e., scripts or resource files changed) without recompiling on a licensed Vizard development machine.

 

Accessing and using this feature is easy as it's built into the Vizard development environment. Simply follow the next steps:

 

Under the file menu, you will find "Publish as EXE". A Wizard will walk you through the necessary steps. The compiler has two steps:

  1. The first step requires that you run your script so that all dependencies (across your project files, Vizard modules, Python, etc) can be identified.
  2. The second step compresses everything together into a single EXE that can be distributed royalty-free.

Resources

There are some cases where Vizard might not be able to automatically detect all resource dependencies of your script. In this case you can manually add the files using the publish wizard (described on the next page) or you can specify them in your script.

 

You can force Vizard to add a file to the published EXE by using the viz.res.addPublishFile() command in your script:

#Add resource.dat to publish EXE
viz.res.addPublishFile('resource.dat')

You can also force Vizard to add an entire directory of files to the published EXE by using the viz.res.addPublishDirectory() command:

#Add all files in 'data' directory to publish EXE
viz.res.addPublishDirectory('./data')

#Add all jpg files in 'images' directory to publish EXE
viz.res.addPublishDirectory('./images','*.jpg')

Vizard uses separate DLL files to support loading various image/model file formats, and these DLLs are not loaded until they are needed. You can tell Vizard that your published EXE should support certain file formats by using the viz.res.addPublishFileLoader() command:

# Support loading PNG images  
viz.res.addPublishFileLoader('png')

# Support loading FBX models
viz.res.addPublishFileLoader('fbx')

There are cases where you might want to exclude certain files from the published EXE. You can use the viz.res.addPublishFilter() command to filter out files from the published EXE. This command can either accept a string or a callback function. If a string is specified, then all files in the published EXE matching the string pattern will be excluded. If a callback function is specified, then the callback function will be passed a filename and should return True if the file should be removed from the published EXE. The following code shows how to filter out all files containing '.svn' in the name using both the string and callback methods:

# Exclude all files containing .svn
viz.res.addPublishFilter('*.svn*')

# Create callback equivalent to above filter
def svn_filter(filename):
    return '.svn' in filename
viz.res.addPublishFilter(svn_filter)

When a published EXE is executed, it runs inside a virtual directory. If you need to access files that are in the same directory as the published EXE, then use the viz.res.getPublishedPath() command:

"""
Get full path to 'output.dat' file in publish EXE directory.
For example, if the published EXE is in 'C:\User\John\Desktop',
the following command will return 'C:\User\John\Desktop\output.dat'.
"""
filename = viz.res.getPublishedPath('output.dat')

Note: Using the viz.res.getPublishedPath() command when NOT running inside a published EXE will simply return the unmodified filename.

Limitations

See also

This section:

Using the publish wizard

Publish with protection

Customizing Published EXEs