HG-4000: Create an Export Template

In this tutorial, you will learn how to export template language, register the template, and export plot data to a file.

Export Template
A file that contains instructions for exporting curve data into files. The instructions contained in an Export Template file are in an uncompiled type of programming language called Export. An Export Template tells the program in which format the data should be written into the file.
Templex and Export Template Language Statements:
The language of Export Templates follows a mixture of Templex commands plus some additional special statements. For the export of curves only a few statements are needed, as shown below:
Table 1. Templex Commands
indexofmin(i) Index of the minimum of a vector (not the minimum itself).
numpts(x) Dimension of the vector X.
table() Export of vectors organized in columns.
for – endloop Loop
if – else – endif Logics
Table 2. Special Export Commands
cr() New line
curvex(i) X vector of curve i.
curvey(i) Y vector of curve i.
curvelabel(i) Export of the legend of curve i.
list Export of vectors in rows.
margins(0,30) Length of a line.
numcurves() Number of curves in a window.
; End of a command (except loops and logics).
Registering an export template
The format selection list in the Export Curves... panel contains, by default, ten formats. Via the preferences file, registered templates are added to this list. Registration is done using the preferences file or via the Tools menu.
  1. Go to <installation directory>\hw\prefinc.
  2. Open preference_plot.mvw and add the following command that registers an export template with a session.

    Above is a small sample of a preference_plot.mvw file that registers a new template (madymo_export.tpl) with a session.

    This file allows the user to customize sessions by specifying defaults or defining external files that should be able to interact with the user’s session.

    Note: The content of the parameter par1 is the name that shows up in the selection list. The parameter par2 specifies the extension of the files that is used for exporting the data: export.par2.

Create a Template for a MADYMO Function File Format

Add the commands below to a text file named madymo_export.tpl.
The statement on the right is an explanation of the command.
Row_1="!vehicle acceleration"; Set variable for the comment in line1.
nc = numcurves(); Set number of curves
lc = nc - 1  
for (i = 0; i < nc; i++) Loop for the number of curves
x = curvex(i); Set the x-vector of curve i
y = curvey(i); Set the y-vector of curve i
t = numpts(x); Set the number of points
if (!numpts(x)) If curve is switched off don’t export
Row_1; cr(); Output for Line 1, label
t, %5i; cr(); Output for Line 2, number of points
table(x, y, "%10.6f %11.6f", 0, t - 1); Output Line 3 to t-1 with the table command
if (i != lc) After every exported curve set an empty line

Register the Export Template

  1. From Tools menu, select Readers, Writers, and Functions….
  2. Go to Export Templates tab.
  3. Browse the template created for MADYMO.
  4. Give the template a name.
  5. Click Register… and OK.
    Figure 1.

Export Plot Data

  1. From the File menu, select Export > Curves.
  2. Enter a file name for the destination file.

    Select an existing file using the file browser.

    Figure 2.
  3. For Format, select the file you just registered.
  4. Specify a range of pages.
  5. Click Apply.
    Plot data from the specified pages are exported to the file.
    The below data file is created after exporting curves in this MADYMO format:
    !vehicle acceleration
      0.000000   13.591910
      1.000000   12.144580
      2.000000   10.850770
      3.000000   10.180930
      4.000000    9.921851
      5.000000    9.995111
      6.000000   10.342690
      7.000000   11.209030
    147.000000  132.563400
    148.000000  130.487300
    149.000000  129.073800
    150.000000  127.332800