This functionality is only available for certain module packages.

You are here: Tutorial > Project generation per import > Part 4 - Importing a CSV file via an action

Part 4 - Importing a CSV file via an action

Requirements:

In addition to the system libraries, the library catalog contains the architecture T_Mechatronic_Architecture and the modular system T_Mechatronic_ModularSystem.

The Feeder project exists in the Project catalog.

The CSV file ParameterMap.csv is imported by means of an action in order to fill the ParameterMap parameter with key-value pairs in the existing configuration. To this purpose the template file Template_CSV.imx and the scheme file KeyValue.xsl are required.

With the same action the CSV file Parameter.csv is imported in order to set the values of the parameters ParameterBoolean, ParameterInteger, ParameterDouble and ParamterString. To this purpose the template file Template_csv.imx and the scheme file ParameterWithType.xsl are required.

To execute an action a link is inserted in a Form-UI of the Feeder component. The action starts the Engineering.ImportCsvCommand command.

Create a unit for actions:

  1. Mark the T_Mechatronic_ModularSystem library in the Library catalog.
  2. Select New > Unit in the shortcut menu.
  3. Enter Actions in the Name field.

Create the action ImportCsvAction:

  1. Mark the Actions unit in the T_Mechatronic_ModularSystem library in the Library catalog.
  2. Select New > Object... from the shortcut menu.
  3. Select Object > Action.
  4. Confirm with [Finish].
  5. Enter ImportCsvAction in the Name field.
  6. Open the Methods editor.
  7. Click the symbol (Add method).
  8. Add run in the Name field.
  9. If applicable, mark the Class method option.
  10. If applicable, select the language Sequence.
  11. Click the symbol (Add individual argument).
  12. Enter the name xslt for the new argument.
  13. Specify the Engineering String type for the new argument.
  14. Repeat Steps 11 and 13 with the following specifications:
  15. Name Type
    template Engineering.String
    project Engineering.Object
    csv Engineering.String
    delimiter Engineering.String
  16. Click the symbol (Add called method).
  17. Select Object > Command > FrameworkCommand > ImportCSVCommand.
  18. In the Suitable methods list select the method with the arguments String pathToXslt, String pathtoTemplate, String pathToCsv, String delimiter.
  19. Confirm with [Finish].

The result should have this appearance:

Create a Form-UI for the Feeder component:

  1. Open the Feeder component in the T_Mechatronic_ModularSystem library in the Library catalog.
  2. Open the UI configuration editor.
  3. If required, open the Source tab.
  4. Enter the following UI configuration. Adjust the paths to your installation accordingly.

Execute the action "Import CSV Data as key-value pairs" in Form-UI:

The created Form-UI is available directly after saving in the Feeder project component under the name Import.

  1. Open the Feeder component in the Project catalog.
  2. Open the Import editor.
  3. Click the link Import CSV Data as key-value pairs.

Result:

The result can be checked directly in the Feeder project component.

  1. Select the Parameters editor.

The Value column shows that the values from the columns A and B of the CSV file have been written as a key-value pair in the ParameterMap parameter.

Execute the action "Import CSV data as single parameter values" in Form-UI:

  1. Open the Import editor.
  2. Click the link Import CSV data as single parameter values.

Result:

The result can be checked directly in the Feeder project component.

  1. Select the Parameters editor.

The Values column shows that all the values from the CSV file have been imported with their own types.