Skip to main content

Motion Standalone Preprocessor C# library 2025 R1

Getting Started with the C# language

Last update: 16.07.2025

The Ansys Motion Standalone Preprocessor C# library can be used to develop two types of extension modules.

System requirements

The Ansys Motion Standalone Preprocessor C# Library requires a development environment with the .NET Framework version 4.8.

Common Settings

First, you need to create a new C# project for the .NET class library. It's different for your development environment.

This document uses Visual Studio 2022 as an example.

Create C# project

Create a new .NET Framework class library as follows:

Create new Class Library(.NET Framework)

Add reference

Add the assembly from the Ansys Motion Standalone Preprocessor C# library to the project references.

Add reference to the project

See Reference for information on which assemblies to add.

License setting

First, add the reference "Ansys installed path\Motion\bin\VMLNet.dll". Then add the following code snippet to any source code in the project.

using VM.Managed.License;
[assembly: OpenLicense("API_User", null)]

The "API_User" string can be replaced with any other string.

It is recommended to add new source code(for example:LicenseInfo.cs) to the project for the assembly attribute.

Create new external module for the Ansys Motion Standalone Preprocessor

Please note that all steps of the Common Settings must be done before.

The following code shows the source code for displaying a message box.

using System.Windows.Forms;
namespace API
{
    public class Module
    {
        public static void Main()
        {
            MessageBox.Show("This is API sample.");
        }
    }
}

You can change the namespace and class names. But you cannot change the name, argument, and return type of the Main function.

Finally, the System.Windows.Forms assembly must be added to the reference.

Execute the external module from Ansys Motion Standalone Preprocessor

The new external module can be executed from the 'Home→Execute External Module File...' menu of the Ansys Motion Standalone Preprocessor.

Add reference to the project

Create a new operation module and add it to the ribbon menu of the Ansys Motion Standalone Preprocessor

After setting up the Common Settings, add the following code to the project.

using System.Windows.Forms;
using VM.Managed;
using VM.Managed.Operation;

namespace OPERATION
{
    public class TestOperation : OperationBase
    {
        public TestOperation(Document doc)
            : base(doc)
        {
        }
        public override void Execute()
        {
            MessageBox.Show("This is OPERATION sample.");
        }
        public override string Name
        {
            get { return "TestOperation"; }
        }
    }
}

Don't forget to add reference to System.Windows.Forms assembly.

Build the project and copy the output dll file to the 'Ansys installed path\Motion\bin' directory.

Add new button to the ribbon menu

Create new ribbon resource files 'Ansys installed path\Motion\bin\Templates\Resources\TestOpearation.dfresx' as follow:

<resource>
  <!--ICON-->
  <data name="ID_ICO_TestOperation">
    <value>337,..\VMRes.dll</value>
  </data>
  <!--TEXT-->
  <data name="ID_TXT_TestOperation">
    <value>Test Operation</value>
  </data>
  <data name="ID_TOOLTIP_TestOperation">
    <value>This is test operation.</value>
  </data>
</resource>

And new ribbon file 'Ansys installed path\Motion\bin\Templates\Ribbons\TestOperation.dfrbbx:

<ribbon>
  <documents>
    <document name="SubSystem" toolkit="General">
      <tabs>
        <tab name="TestOperation" text="ID_TXT_TestOperation" access_key="T">
          <panels>
            <prepanel name="SimpleViewPanel"></prepanel>
            <panel name="TestOperation" text="ID_TXT_TestOperation" icon="ID_ICO_TestOperation">
              <buttons>
                <button name="Test Operation" text="ID_TXT_TestOperation" tooltip="ID_TOOLTIP_TestOperation" icon_small="ID_ICO_TestOperation" icon_large="ID_ICO_TestOperation" command="TEST_OPERATION" access_key="S">
              </button></buttons>
            </panel>
          </panels>
        </tab>
        <removes></removes>
      </tabs>
    </document>
  </documents>
</ribbon>

Finally, add new sub system module file 'Ansys installed path\Motion\bin\Templates\Modules\TestOperation.dfmdx'

<module name="Subsystem" toolkit="General" is_overlap="true">
  <documentcommands>
    <!--Test Operation-->
    <command command="TEST_OPERATION" operation="OPERATION.TestOperation,OPERATION">
  </documentcommands>
  <viewcommands></viewcommands>
</module>

Then, you can see new command button on the ribbon menu of the sub system file as follow:

Add reference to the project

See also

  • The sample code of the Ansys Motion Preprocessor C# library is available in the 'Ansys installed path\Motion\Document\API Tutorial.zip' file.
  • Reference

Connect with Ansys