Batch verification of model

Overview

If you develop the Next Design extension, you can implement the function of displaying the error location by inputting the model information, implementing the arbitrary verification process.

In the following, we will add a UI button for model verification using the .NET DLL implementation method, and when that button is pressed, all models will be verified at once and an extension that displays the error location will be created.

  • Overall flow

    • Preparing .NET DLL development project
    • Manifest extension and extension point definition
    • Added ribbon UI icon file
    • Implementation of verification processing for all models

Goal image

Validation of model name

  • When you open the [Advanced Driving System Software Development] project from the Next Design sample project, the [My Extensions] tab is added to the ribbon and the extension function is enabled.

  • If you click [My Extensions]> [Model Verification]> [Verify] button on the ribbon, all the models are collectively verified according to the following verification rules and the error location is displayed.

    Verification rule: The model name must not contain single-byte space characters.

  • To clear the displayed error, click Home> Model> Check Error> Clear Error from the ribbon.

download

  • You can download the complete set of files created as a result of this tutorial from the following link.

    Download link: ValidationSample-1.zip

.NET DLL development project preparation

To create a new .NET DLL development project in Visual Studio to prepare the extension debug environment, follow the steps below.

  • Creating a new project in Visual Studio
  • Copy of extension development DLL
  • Added reference setting for extension development DLL

This section describes the operation procedure in Visual Studio 2019, but you can also develop in Visual Studio 2017 or later (hereinafter referred to as VS).

The following explanations assume that the installation folder is the default. If it is different, replace it with the actual installation folder.

Default installation folder: C:\Program Files (x86)\DENSO CREATE\Next Design

Creating a new project in VS

To create a new .NET DLL development project, follow these steps:

Create new project in VS

Operating procedure

  1. Start VS and click Create New Project from the start page to open the Create New Project wizard.
  2. Select [Class Library (.NET Framework)] by C# from the project template and click the [Next] button.
  3. In [New Project Configuration], enter the items as shown in the table below and click the [Create] button.
  4. This will create a new VS project template for class library development in C#.
  5. Of the files created as a template, the Class1.cs file is not used. Remove it from VS Solution Explorer.
Item Value
Project name and solution name ValidationSample
Location Any parent folder that contains a set of projects
Framework .NET Framework 4.6.2

Note

Copy of extension development DLL

Follow the steps below to copy the DLL used for Next Design extension development.

Copy DLL for extension development

Operating procedure

  1. Copy the following DLL from the Next Design installation folder into your VS project.

    NextDesign.Core.dll NextDesign.Desktop.dll

Add reference setting of DLL for extension development

To add the copied DLL to your VS project's reference settings, follow these steps:

Add extension reference DLL reference

Operating procedure

  1. From Solution Explorer in VS, expand the following node:

    Solution [ValidationSample]> [ValidationSample]> Reference

  2. Right-click the Reference node in the tree and execute the Add Reference command from the context menu to open the Reference Manager dialog.

  3. Click the [Reference] button at the bottom right of the [Reference Manager] dialog to open the [Select File to Reference] dialog.

  4. Select the following DLL file copied to the VS project and press the [Add] button to return to the [Reference Manager] dialog.

    NextDesign.Core.dll NextDesign.Desktop.dll

  5. Confirm that the added DLL file is checked in the list in the [Reference Manager] dialog, and click the [OK] button.

  6. This will add the DLLs needed for Next Design extension development under the Reference node in the Solution Explorer in VS.

Automation of debug execution preparation

To automate the DLL's debug execution preparation as described in Running and Debugging DLL, follow the steps below.

Automatic preparation for debug execution

Operating procedure

  1. Open the property of solution [ValidationSample]> [ValidationSample], and copy and paste the following script to the following setting items.

    Setting items: [Build event]> [Command line of post-build event]

  2. Next, in the same property, set the following path in [Debug]> [Start behavior]> [Start External Program].

    C:\Program Files (x86)\DENSO CREATE\Next Design\NextDesign.exe

Command line for post-build event

setlocal
set EXTENSIONS_FOLDER=%LOCALAPPDATA%\DENSO CREATE\Next Design\extensions
set DESTINATION_FOLDER=%EXTENSIONS_FOLDER%\$(ProjectName)

if not exist "%EXTENSIONS_FOLDER%" mkdir "%EXTENSIONS_FOLDER%"

del "$(TargetDir)NextDesign.Core.dll" "$(TargetDir)NextDesign.Desktop.dll" >NUL 2>&1
rd/S/Q "%DESTINATION_FOLDER%" >NUL 2>&1

echo Deploy extension into extensions sub folder: %DESTINATION_FOLDER%

xcopy/S/I/Q/Y "$(TargetDir)*.*" "%DESTINATION_FOLDER%"
xcopy/S/I/Q/Y "$(ProjectDir)resources" "%DESTINATION_FOLDER%\resources"
copy/Y "$(ProjectDir)*.json" "%DESTINATION_FOLDER%"

Definition of extension and extension point by manifest

To create a new manifest, create a new text file: manifest.json as a new item in your VS project and define the following:

  • Execution program entry point definition
  • Extension life cycle definition
  • Specify target profile of extension
  • UI extension point definition (ribbon tab group button)
  • Command extension point definition

Creating a new manifest file

To create a new text file: manifest.json as a new item in your VS project, do the following:

Create new manifest file

Operating procedure

  1. Right-click the VS project from the Solution Explorer in VS and execute the Add> New Item command in the context menu.
  2. Select [Text File] from the types of items to add, enter manifest.json in the [Name] input field, and click the [Add] button.
  3. This will create a new empty manifest.json file, which will also appear in Solution Explorer in VS.

Implementation code

manifest.json

{
  //extension definition
  "name": "Validation Sample",
  "version": "1.1.0",
  "publisher": "DENSO CREATE INC.",
  "license": "Conforms to the Next Design License Agreement. Copyright (C) 2019 DENSO CREATE INC. All rights reserved.",

  "main": "ValidationSample.dll", //Specify the DLL file name of the build result as an entry point.
  "lifecycle": "project", //Specify the project lifecycle as the lifecycle.
  "baseprofile": "In-vehicle system software development", //Specify the profile name as the condition of the target project.

  //extension point definition
  "extensionPoints": {
    //ribbon
    "ribbon": {
      "tabs": [
        //Define a ribbon tab to add for the extension.
        {
          "id": "MyExtensions.MainTab",
          "label": "My Extensions",
          "orderAfter": "System.Help",
          "groups": [
            //Define a group that separates the ribbon tabs.
            {
              "id": "MyExtensions.Validation.Group",
              "label": "Model validation",
              "controls": [
                //Define a verification execution button.
                {
                  "type": "Button",
                  "id": "MyExtensions.Validation.RunButton",
                  "label": "verification",
                  "description": "Validate all models",
                  "imageLarge": "resources/icon.png",
                  "command": "Command.Validation.Run" //Specify the id of the validation command defined in the command below.
                }
              ]
            }
          ]
        }
      ]
    },

    //command
    "commands": [
      //Define a verification command that calls the verification process command handler `Run`.
      {
        "id": "Command.Validation.Run",
        "execFunc": "Run", //Specifies the public method implemented in the entry point main class.
        "canExecWhen": {
          "uiState": "ProjectOpened" //Specifies that the project is open as a valid condition for the command.
        }
      }
    ],

    //event
    "events": {
    }
  }
}

Add icon file for ribbon UI

Follow the steps below to add the UI button icon file specified in the imageLarge of the verification execution button in the manifest above to the VS project.

Add Icon File for Ribbon UI

Operating procedure

  1. Create a resources subfolder directly under your VS project.
  2. Store the icon.png file in the created subfolder. (A sample of the icon.png file is included in the download file described in the overview)
  3. If you also want to register the icon file in Solution Explorer of VS, drag and drop the resources subfolder onto the VS project of Solution Explorer. (This operation is optional. There is no problem if you do not register the icon file.)

Info

  • We recommend 32x32 for large icons and 16x16 for small icons.

Implementation of verification processing for all models

To implement the extension entry point and validation process, create a new class: ValidationSample as a new item in your VS project and implement the following contents.

  • Namespace declaration of the referenced API
  • Entry point DLL main class
  • Command handler for verification processing (public method)
  • Extension initialization/termination processing

Creating a new class

To create a new class: ValidationSample as a new item in your VS project, do the following:

Create new class

Operating procedure

  1. Right-click the VS project from VS Solution Explorer and execute the Add> Class command from the context menu.
  2. Make sure that [Class] is selected for the type of item to add, enter ValidationSample in the [Name] input field, and click the [Add] button.
  3. This will create a new template for the ValidationSample.cs file and it will also appear in the Solution Explorer in VS.

Implementation code

ValidationSample.cs

//Declaration of the namespace of the API referenced in extension development
using NextDesign.Extension;
using NextDesign.Core;
using NextDesign.Desktop;

///<summary>
///Main class of the entry point DLL
///</summary>
///<remarks>
///Implement the `IExtension` interface in the main class of the entry point.
///Implement the handler as a public method of this class.
///</remarks>
public class ValidationSample :IExtension
{
    ///<summary>
    ///Command handler for verification processing
    ///</summary>
    ///<param name="context">command context</param>
    ///<param name="parameters">command parameters</param>
    ///<remarks>
    ///Implement the verification process command handler as a public method of the main class.
    ///</remarks>
    public void Run(ICommandContext context, ICommandParams parameters)
    {
        var app = context.App;
        var project = app.Workspace.CurrentProject;

        //Clear all previous errors.
        app.Errors.ClearErrors();

        //Display the error list window.
        app.Window.IsInformationPaneVisible = true;
        app.Window.ActiveInfoWindow = "Error";

        //Iterate over all the models in the project.
        var models = project.GetAllChildren();
        foreach (var model in models)
        {
            //Validate the model according to the validation rules.
            ValidateModel(model);
        }
    }

    ///<summary>
    ///Validate model according to validation rules
    ///</summary>
    ///<param name="model">model</param>
    private void ValidateModel(IModel model)
    {
        //Match the following validation rules.
        //・Do not include spaces in the model name
        if (model.Name.IndexOf(" ")> 0)
        {
            //If it does not meet the validation rules, add error information to the corresponding model.
            var message = string.Format("The model name contains spaces. Model name: {0}", model.Name);
            var error = model.AddError("Name", "Error", "Model naming convention check", message);
        }
    }

    ///<summary>
    ///Extension initialization
    ///</summary>
    ///<param name="context">Execution context</param>
    ///<remarks>
    ///Even if you do not need extension initialization/termination processing, empty `Activate` and `Deactivate` methods are required.
    ///</remarks>
    public void Activate(IContext context)
    {
        //Implement extension initialization etc. if necessary.
    }

    ///<summary>
    ///Extension end processing
    ///</summary>
    ///<param name="context">Execution context</param>
    ///<remarks>
    ///Even if you do not need extension initialization/termination processing, empty `Activate` and `Deactivate` methods are required.
    ///</remarks>
    public void Deactivate(IContext context)
    {
        //Implement extension termination processing etc. if necessary.
    }
}