File Import
CAD Import using the Model Tree and a File Import Object
A File Import object is used to display a file browser with an associated input field for browsing to a file or entering its path and name. It is used to enable file import by the user of an application at run time, when the file is not available in the application beforehand. You can directly link a File Import object to a file Import node in the model tree; for example, a CAD Import node. Consider an application where a CAD file can be selected and imported at run time, as shown by the figure below.
The corresponding File Import object is shown in the figure below.
The Settings window for the File Import object has a section File Destination. In this section, you can select any tree node that allows a filename to be input. This is shown in the figure below, where the Filename for the Import node is selected.
CAD Import using a Button and Command Sequence
If you do not wish to use a File Import object, you can directly reference a Filename from a button or an item in a menu, ribbon, or toolbar, or alternatively create a method that calls the built-in method importFile as an event, for example
importFile("file1");
assuming there is a file declaration file1.
The figures below shows a ribbon item used for geometry import together with its Settings window.
In the Settings window above, the command Import file to Import 1 will open a file browser for the user to select a file, as shown in the figure below.
The preceding command Set Type of Import allows you to filter the file extensions displayed in the file browser. The available arguments are: file, mesh, native, cad, and ecad.
The subsequent commands build and plot the geometry and zoom out using zoom extents.
For more information on the File Import object, see File Import.
File Import in Methods
Continuing the example of the previous section, assume that we click Convert to New Method in the Settings window. The corresponding lines of code show how CAD import can be accomplished from a method:
importFile(model.geom("geom1").feature("imp1"), "filename");
useGraphics(model.geom("geom1"), "main/graphics1");
zoomExtents("main/graphics1");
The first line illustrates using the built-in method importFile. For more information on the method importFile and other methods for file handling, see File Methods and the Application Programming Guide.
File Access and File Declarations
At the bottom of the Settings window of a File Import object, you can see which file scheme syntax to use to access an imported file from a method (next to Access using:). The figure below shows an example where a File Destination and Filename are used.
The file scheme syntax, upload:///geom1/imp1/filename, needs to be used whenever accessing this file.
As an alternative, you can use a File declaration under the Declarations node. (However, File declarations are primarily used for file import from method code.) In this case, the file chosen by the user can be referenced in a form object or method using the syntax upload:///file1, upload:///file2, and so on. The filename handle (file1, file2, and so on.) can then be used to reference an actual filename picked by the user at run time. See also File.
This syntax can also be used in any file browser text fields within the Model Builder nodes. The figure below shows a file reference used in the Filename field of the Import model tree node for a model using geometry import.
When you enter upload:///file1, it is automatically replaced with a reference to the file location as file1. If you use the upload file scheme, the text field converts the entry into a link. You can access the underlying source by selecting Show Location in the Auxiliary Data window.
However, a quicker way is to link a file import object directly to the Filename field, as described previously in the section CAD Import using the Model Tree and a File Import Object.
Importing Experimental Data in General
The Application Builder offers multiple ways to import experimental data. The following sections highlight a few easy-to-implement methods. For additional file handling options, refer to and the Application Programming Guide. The guide also includes examples of how Java methods can be used to import arbitrary files, whether in binary or text format.
Importing Experimental Data Using a File Import Object
The following example is from the Response Spectrum Generator app, available in the Application Libraries under the Structural Mechanics Module. The figure below shows the user interface of the app with a file import object used to browse to a file with experimental data.
The figure below shows the settings window of the corresponding File Import object. The object links to the Filename property of an interpolation function, defined in the embedded model. In general, each interpolation function added to a model will have the Filename property available for use in an app.
In this application, the File types table specifies that only certain file types are allowed.
More information on file import can be found in the Application Programming Guide. There you will, for example, find information on customized parsing of arbitrary file types.
Importing Experimental Data to a Table
Using a table object provides another way to import experimental, or other tabulated, data. The following example is from the Li-Ion Battery Impedance app, available in the Application Libraries under the Battery Design Module. The figure below shows part of the app’s user interface featuring a table object used to import and export the data.
The Load from File button in the toolbar below the table can be used to load data from file. The figure below shows the corresponding Table settings window. The imported data is here stored in a set of 1D double arrays, one per column.