Automating Kanzi Studio tasks

You can execute Kanzi Studio commands by running a script from the command line interface. This enables you to automate repetitive tasks in Kanzi Studio or Kanzi Studio tasks that you must execute on a large number of Kanzi Studio projects. For example, consider making a script to update a Kanzi Engine plugin that you use in many Kanzi Studio projects, or to export kzb files from many Kanzi Studio projects.

For example, you can automate:

For the list of available commands, see Kanzi Studio command reference .

To automate Kanzi Studio tasks:

  1. In a text editor create a script where you define what commands you want Kanzi Studio to run.
    For example, add to the script the commands in this step and save the script as MyScript.txt.
    1. Open a Kanzi Studio project.
      # Open the project named MyProject.
      # To create a new project use NewProject.
      # For example, NewProject "C:\KanziWorkspace\Projects\MyNewProject\Tool_project\MyNewProject.kzproj"
      LoadProject "C:\KanziWorkspace\Projects\MyProject\Tool_project\MyProject.kzproj"
    2. Add more commands to automate Kanzi Studio tasks.
      For the list of available commands see Kanzi Studio command reference .
    3. Save and close the project.
      # Save the project.
      # The second parameter sets whether Kanzi Studio continues working in the directory where you opened the project.
      # When you save the project to a different location, set the second parameter to false.
      # For example, SaveProject "C:\KanziWorkspace\Projects\MyOtherProject\Tool_project\MyOtherProject.kzproj" false
      SaveProject "C:\KanziWorkspace\Projects\MyProject\Tool_project\MyProject.kzproj" true
      
      # Close the project.
      # To close Kanzi Studio use ExitApplication.
      CloseProject
      
  2. Open the command line interface in the <KanziInstallation>/Studio/Bin directory and run the KanziStudio.exe file with the /Script flag pointing to the script you created in the previous step.
    For example, on the command line interface run
    KanziStudio.exe /Script="C:\Users\username\Documents\MyScript.txt"

Exporting kzb files using a script

Kzb files contain contents of your Kanzi Studio projects. To run your Kanzi application on a device, you need to export it as a kzb file. See Using kzb files.

To export kzb files using a script:

  1. In a text editor create a script that opens a project, exports a kzb file, and closes Kanzi Studio.
    # Open the project named MyProject.
    LoadProject "C:\KanziWorkspace\Projects\MyProject\Tool_project\MyProject.kzproj"
    
    # Export the kzb file to the location set in the Project > Properties in the Binary Export Directory property.
    # To export the kzb file to another location use: ExportBinary "Path\to\directory\MyProjectBinary.kzb"
    ExportBinary
    
    # Close Kanzi Studio. If you want to continue using Kanzi Studio after the script executes, comment out this line.
    ExitApplication

    The ExportBinary command takes these optional parameters:

    For example, to export both the theme and locale resources to separate kzb files, and the kza file:

    # Export the theme and locale resources and the kza file.
    ExportBinary true true

  2. Open the command line interface in the <KanziInstallation>/Studio/Bin directory and run the KanziStudio.exe file with the script you created in the previous step.
    KanziStudio.exe /Script="C:\Users\username\Documents\MyScript.txt"

Building Kanzi applications for Android using a script

To build Kanzi applications for Android using a script:

  1. In a text editor create a script that opens a project, sets the configuration for the Android build, builds the APK file, and closes the project.
    # Open the project named MyProject.
    LoadProject "C:\KanziWorkspace\Projects\MyProject\Tool_project\MyProject.kzproj"
    
    # Before you build the APK file, set whether to install the APK file to your Android device and launch the application.
    # In the Library > Applications > MyProject disable the Install to Device property.
    SetProperty "/Resource Files/Applications/MyProject" BuildConfigurationInstallToDevice false
    # In the Library > Applications > MyProject disable the Launch Application property.
    SetProperty "/Resource Files/Applications/MyProject" BuildConfigurationRunApplication false
    
    # Build the APK file using the Library > Applications > MyProject application configuration.
    # If the project contains images that use texture compression,
    # the second parameter sets whether Kanzi Studio compresses these images.
    ExportApk "/Resource Files/Applications/MyProject" true
    
    # Close the project.
    # To close Kanzi Studio use ExitApplication.
    CloseProject
  2. Open the command line interface in the <KanziInstallation>/Studio/Bin directory and run the KanziStudio.exe file with the script you created in the previous step.
    KanziStudio.exe /Script="C:\Users\username\Documents\MyScript.txt"

Importing and updating Kanzi Engine plugins using a script

Kanzi Engine plugins extend the functionality of Kanzi Engine. Kanzi Engine executes these plugins on target platforms. See Kanzi Engine plugins.

You can import and update Kanzi Engine plugins using a script. See:

Importing a Kanzi Engine plugin using a script

When you want to use a Kanzi Engine plugin in a Kanzi Studio project, you must import that Kanzi Engine plugin to your Kanzi Studio project.

To import a Kanzi Engine plugin using a script:

  1. In a text editor create a script that opens a project, imports a Kanzi Engine plugin, and saves and closes the project.
    # Open the project named MyProject.
    LoadProject "C:\KanziWorkspace\Projects\MyProject\Tool_project\MyProject.kzproj"
    
    # Import the Kanzi Engine plugin DLL MyPluginProject\Application\lib\Win32\GL_vs2015_Debug_DLL\MyPluginProject.dll.
    # Kanzi Studio adds to the Library > Kanzi Engine Plugins a reference to the Kanzi Engine plugin DLL that you import.
    ImportEnginePlugin "C:\KanziWorkspace\Projects\MyPluginProject\Application\lib\Win32\GL_vs2015_Debug_DLL\MyPluginProject.dll"
    
    # Save the project.
    # The second parameter sets whether Kanzi Studio continues working in the directory where you opened the project.
    # When you save the project to a different location, set the second parameter to false.
    # For example, SaveProject "C:\KanziWorkspace\Projects\MyOtherProject\Tool_project\MyOtherProject.kzproj" false
    SaveProject "C:\KanziWorkspace\Projects\MyProject\Tool_project\MyProject.kzproj" true
    
    # Close the project.
    # To close Kanzi Studio use ExitApplication.
    CloseProject
    
  2. Open the command line interface in the <KanziInstallation>/Studio/Bin directory and run the KanziStudio.exe file with the script you created in the previous step.
    KanziStudio.exe /Script="C:\Users\username\Documents\MyScript.txt"

Updating a Kanzi Engine plugin using a script

When you want to use a new version of a Kanzi Engine plugin that you use in a Kanzi Studio project, you must update that Kanzi Engine plugin in your Kanzi Studio project.

To update a Kanzi Engine plugin using a script:

  1. In a text editor create a script that opens a project, updates the Kanzi Engine plugin, and saves and closes the project.
    # Open the project named MyProject.
    LoadProject "C:\KanziWorkspace\Projects\MyProject\Tool_project\MyProject.kzproj"
    
    # Update the XML_data_source Kanzi Engine plugin in the project.
    # You leave the first parameter empty because you do not import a new plugin to the project.
    ImportEnginePlugin "" "/Kanzi Engine Plugins/XML_data_source"
    
    # Save the project.
    # The second parameter sets whether Kanzi Studio continues working in the directory where you opened the project.
    # When you save the project to a different location, set the second parameter to false.
    # For example, SaveProject "C:\KanziWorkspace\Projects\MyOtherProject\Tool_project\MyOtherProject.kzproj" false
    SaveProject "C:\KanziWorkspace\Projects\MyProject\Tool_project\MyProject.kzproj" true
    
    # Close the project.
    # To close Kanzi Studio use ExitApplication.
    CloseProject
    
  2. Open the command line interface in the <KanziInstallation>/Studio/Bin directory and run the KanziStudio.exe file with the script you created in the previous step.
    KanziStudio.exe /Script="C:\Users\username\Documents\MyScript.txt"

Updating all Kanzi Engine plugins in a project or solution using a script

When you want to use a new version of a Kanzi Engine plugin that you use in a Kanzi Studio project, you must update that Kanzi Engine plugin in your Kanzi Studio project.

You can update all Kanzi Engine plugins in your Kanzi Studio project using a script. If your Kanzi Studio project contains project references, you can update all Kanzi Engine plugins in the solution which includes that project and all referenced projects. See Combining Kanzi Studio projects into a Kanzi application.

To update all Kanzi Engine plugins in a project or solution using a script:

  1. In a text editor create a script that opens a project, updates the Kanzi Engine plugins, and saves and closes the project.
    # Open the project named MyProject.
    LoadProject "C:\KanziWorkspace\Projects\MyProject\Tool_project\MyProject.kzproj"
    
    # Update all the Kanzi Engine plugins in the project.
    # To update the Kanzi Engine plugins in that project and all referenced projects use UpdateSolutionEnginePlugins.
    UpdateProjectEnginePlugins
    
    # Save the project.
    # The second parameter sets whether Kanzi Studio continues working in the directory where you opened the project.
    # When you save the project to a different location, set the second parameter to false.
    # For example, SaveProject "C:\KanziWorkspace\Projects\MyOtherProject\Tool_project\MyOtherProject.kzproj" false
    SaveProject "C:\KanziWorkspace\Projects\MyProject\Tool_project\MyProject.kzproj" true
    
    # Close the project.
    # To close Kanzi Studio use ExitApplication.
    CloseProject
    
  2. Open the command line interface in the <KanziInstallation>/Studio/Bin directory and run the KanziStudio.exe file with the script you created in the previous step.
    KanziStudio.exe /Script="C:\Users\username\Documents\MyScript.txt"

Creating and updating data sources using a script

Use data sources to separate the user interface from the application data and to remove the dependencies between a Kanzi Studio project and the application code which define the Kanzi application. See Data sources.

You can create and update data sources using a script. See:

Creating a data source using a script

When you want to use a Kanzi Engine data source plugin in a Kanzi Studio project, you must create a data source in your Kanzi Studio project.

To create a data source using a script:

  1. In a text editor create a script that opens a project, imports a Kanzi Engine data source plugin, creates and updates the data source, and saves and closes the project.
    # Open the project named MyProject.
    LoadProject "C:\KanziWorkspace\Projects\MyProject\Tool_project\MyProject.kzproj"
    
    # Import the Kanzi Engine data source plugin DLL MyDataSource\Application\lib\Win32\GL_vs2015_Release_DLL\MyDataSource.dll.
    # The MyDataSource plugin defines the CustomDataSourceType data source type.
    # Kanzi Studio adds to the Library > Kanzi Engine Plugins a reference to the Kanzi Engine data source plugin DLL that you import.
    ImportEnginePlugin "C:\KanziWorkspace\Projects\MyDataSource\Application\lib\Win32\GL_vs2015_Release_DLL\MyDataSource.dll"
    
    # Create a data source named Cluster of the type CustomDataSourceType.
    CreateDataSource "Cluster" "CustomDataSourceType"
    # To create data objects from the Cluster data source, update the data source.
    UpdateDataSourceContents "/Data Sources/Cluster/"
    
    # Save the project.
    # The second parameter sets whether Kanzi Studio continues working in the directory where you opened the project.
    # When you save the project to a different location, set the second parameter to false.
    # For example, SaveProject "C:\KanziWorkspace\Projects\MyOtherProject\Tool_project\MyOtherProject.kzproj" false
    SaveProject "C:\KanziWorkspace\Projects\MyProject\Tool_project\MyProject.kzproj" true
    
    # Close the project.
    # To close Kanzi Studio use ExitApplication.
    CloseProject
  2. Open the command line interface in the <KanziInstallation>/Studio/Bin directory and run the KanziStudio.exe file with the script you created in the previous step.
    KanziStudio.exe /Script="C:\Users\username\Documents\MyScript.txt"

Updating a data source using a script

If the Kanzi Engine plugin that defines your data source does not update your data source, you can update the data source using a script.

To update a data source using a script:

  1. In a text editor create a script that opens a project, updates the data source, and saves and closes the project.
    # Open the project named MyProject.
    LoadProject "C:\KanziWorkspace\Projects\MyProject\Tool_project\MyProject.kzproj"
    
    # Update the Cluster data source in the project.
    UpdateDataSourceContents "/Data Sources/Cluster/"
    
    # Save the project.
    # The second parameter sets whether Kanzi Studio continues working in the directory where you opened the project.
    # When you save the project to a different location, set the second parameter to false.
    # For example, SaveProject "C:\KanziWorkspace\Projects\MyOtherProject\Tool_project\MyOtherProject.kzproj" false
    SaveProject "C:\KanziWorkspace\Projects\MyProject\Tool_project\MyProject.kzproj" true
    
    # Close the project.
    # To close Kanzi Studio use ExitApplication.
    CloseProject
  2. Open the command line interface in the <KanziInstallation>/Studio/Bin directory and run the KanziStudio.exe file with the script you created in the previous step.
    KanziStudio.exe /Script="C:\Users\username\Documents\MyScript.txt"

Updating all data sources in a project or solution using a script

If the Kanzi Engine plugin that defines your data source does not update your data sources, you can update the data source using a script. If your Kanzi Studio project contains project references, you can update all data sources in the solution which includes that project and all referenced projects. See Combining Kanzi Studio projects into a Kanzi application.

To update all data sources in a project or solution using a script:

  1. In a text editor create a script that opens a project, updates the data sources, and saves and closes the project.
    # Open the project named MyProject.
    LoadProject "C:\KanziWorkspace\Projects\MyProject\Tool_project\MyProject.kzproj"
    
    # Update all data sources in the project.
    # To update the data sources in that project and all referenced projects use UpdateSolutionDataSources.
    UpdateProjectDataSources
    
    # Save the project.
    # The second parameter sets whether Kanzi Studio continues working in the directory where you opened the project.
    # When you save the project to a different location, set the second parameter to false.
    # For example, SaveProject "C:\KanziWorkspace\Projects\MyOtherProject\Tool_project\MyOtherProject.kzproj" false
    SaveProject "C:\KanziWorkspace\Projects\MyProject\Tool_project\MyProject.kzproj" true
    
    # Close the project.
    # To close Kanzi Studio use ExitApplication.
    CloseProject
    
  2. Open the command line interface in the <KanziInstallation>/Studio/Bin directory and run the KanziStudio.exe file with the script you created in the previous step.
    KanziStudio.exe /Script="C:\Users\username\Documents\MyScript.txt"

Creating nodes using a script

To create a node using a script:

  1. In a text editor create a script that opens a project, creates a node, saves the project, and closes the project.
    For example, to create in the RootPage node a Page node named My Page:
    # Open the project named MyProject.
    LoadProject "C:\KanziWorkspace\Projects\MyProject\Tool_project\MyProject.kzproj"
    
    # In the RootPage node create a Page node named My Page.
    # The last parameter sets whether Kanzi Studio selects the node that you created.
    CreatePage "MyProject/Screens/Screen/RootPage" "My Page" true
    
    # Save the project.
    # The second parameter sets whether Kanzi Studio continues working in the directory where you opened the project.
    # When you save the project to a different location, set the second parameter to false.
    # For example, SaveProject "C:\KanziWorkspace\Projects\MyOtherProject\Tool_project\MyOtherProject.kzproj" false
    SaveProject "C:\KanziWorkspace\Projects\MyProject\Tool_project\MyProject.kzproj" true
    
    # Close the project.
    # To close Kanzi Studio use ExitApplication.
    CloseProject
  2. Open the command line interface in the <KanziInstallation>/Studio/Bin directory and run the KanziStudio.exe file with the script you created in the previous step.
    KanziStudio.exe /Script="C:\Users\username\Documents\MyScript.txt"

Editing properties using a script

Properties provide the means to specify and examine the state, appearance, and behavior of nodes. For example, a property can define a color, indicate whether a button is pressed, or specify the alignment of an item. See Property types.

You can edit properties using a script. See:

Adding properties using a script

To add properties using a script:

  1. In a text editor create a script that opens a project, adds a property and sets the property value, saves the project, and closes the project.
    For example, to add the Description property to the RootPage node and set it to "This is the main page of the application":
    # Open the project named MyProject.
    LoadProject "C:\KanziWorkspace\Projects\MyProject\Tool_project\MyProject.kzproj"
    
    # In the RootPage node add the Description property and set it to "This is the main page of the application.".
    # To add in the RootPage node the Description property without setting the value of the property, use
    # AddProperty "MyProject/Screens/Screen/RootPage" Description
    AddProperty "MyProject/Screens/Screen/RootPage" Description "This is the main page of the application."
    
    # Save the project.
    # The second parameter sets whether Kanzi Studio continues working in the directory where you opened the project.
    # When you save the project to a different location, set the second parameter to false.
    # For example, SaveProject "C:\KanziWorkspace\Projects\MyOtherProject\Tool_project\MyOtherProject.kzproj" false
    SaveProject "C:\KanziWorkspace\Projects\MyProject\Tool_project\MyProject.kzproj" true
    
    # Close the project.
    # To close Kanzi Studio use ExitApplication.
    CloseProject
  2. Open the command line interface in the <KanziInstallation>/Studio/Bin directory and run the KanziStudio.exe file with the script you created in the previous step.
    KanziStudio.exe /Script="C:\Users\username\Documents\MyScript.txt"

Removing properties using a script

To remove properties using a script:

  1. In a text editor create a script that opens a project, removes a property, saves the project, and closes the project.
    For example, to remove the Background Brush property from the RootPage node:
    # Open the project named MyProject.
    LoadProject "C:\KanziWorkspace\Projects\MyProject\Tool_project\MyProject.kzproj"
    
    # In the RootPage node remove the Background Brush property.
    RemovePropertyFromItem "MyProject/Screens/Screen/RootPage" Node2D.BackgroundBrush
    
    # Save the project.
    # The second parameter sets whether Kanzi Studio continues working in the directory where you opened the project.
    # When you save the project to a different location, set the second parameter to false.
    # For example, SaveProject "C:\KanziWorkspace\Projects\MyOtherProject\Tool_project\MyOtherProject.kzproj" false
    SaveProject "C:\KanziWorkspace\Projects\MyProject\Tool_project\MyProject.kzproj" true
    
    # Close the project.
    # To close Kanzi Studio use ExitApplication.
    CloseProject
  2. Open the command line interface in the <KanziInstallation>/Studio/Bin directory and run the KanziStudio.exe file with the script you created in the previous step.
    KanziStudio.exe /Script="C:\Users\username\Documents\MyScript.txt"

Setting property values using a script

To set property values using a script:

  1. In a text editor create a script that opens a project, sets the values of the properties, saves the project, and closes the project.
    For example, to set the size of the Screen node to 1200 x 720 pixels use this script:
    # Open the project named MyProject.
    LoadProject "C:\KanziWorkspace\Projects\MyProject\Tool_project\MyProject.kzproj"
    
    # In the Screen node set the Metrics Type property to Absolute.
    SetProperty "/Screens/Screen" Window.MetricsType Absolute
    # In the Screen node set the Width property to 1200.
    SetProperty "/Screens/Screen" WindowAbsoluteWidth 1200
    # In the Screen node set the Height property to 720.
    SetProperty "/Screens/Screen" WindowAbsoluteHeight 720
    
    # Save the project.
    # The second parameter sets whether Kanzi Studio continues working in the directory where you opened the project.
    # When you save the project to a different location, set the second parameter to false.
    # For example, SaveProject "C:\KanziWorkspace\Projects\MyOtherProject\Tool_project\MyOtherProject.kzproj" false
    SaveProject "C:\KanziWorkspace\Projects\MyProject\Tool_project\MyProject.kzproj" true
    
    # Close the project.
    # To close Kanzi Studio use ExitApplication.
    CloseProject
    
  2. Open the command line interface in the <KanziInstallation>/Studio/Bin directory and run the KanziStudio.exe file with the script you created in the previous step.
    KanziStudio.exe /Script="C:\Users\username\Documents\MyScript.txt"

Logging invalid project items using a script

Kanzi Studio marks invalid items in the Project and Library with red type.
For example:

See Finding invalid project items.

You can create and run a script to collect invalid items in your Kanzi Studio projects.

To log invalid project items using a script:

  1. In a text editor create a script that opens a project, prints invalid project items to the %USERPROFILE%\AppData\Local\Temp\KanziStudioLogs\KanziStudio.log file, and closes the project.
    # Open the project named MyProject.
    LoadProject "C:\KanziWorkspace\Projects\MyProject\Tool_project\MyProject.kzproj"
    
    # Print a list of invalid project items to the KanziStudio.log file.
    PrintDiagnosticReport MyProject
    
    # Close the project.
    # To close Kanzi Studio use ExitApplication.
    CloseProject
  2. Open the command line interface in the <KanziInstallation>/Studio/Bin directory and run the KanziStudio.exe file with the script you created in the previous step.
    KanziStudio.exe /Script="C:\Users\username\Documents\MyScript.txt"

See also

Kanzi Studio command reference

Using kzb files

Deploying Kanzi applications to Android

Kanzi Engine plugins

Combining Kanzi Studio projects into a Kanzi application

Data sources

Property types

Finding invalid project items