Creating a User-Defined Primitive

The modeler allows you to generate user-defined primitives customized to suit any application. User-defined primitives are accessed using DLLs that you build and compile. When user-defined primitives exist in your UserLib or Personal directory (given the paths specified in Tools > OptionsGeneral Options > Directories tab), they appear in the Draw > User Defined Primitives menu. Newly created UDPs will appear after a restart, or Draw > User Defined Primitive > Update Menu.

Example C++ source and header files that can be used to generate DLLs are located in the /UserDefinedPrimitives/Examples subdirectory under the Ansys Electromagnetics Suite installation directory.

As an example, create the primitive myUDP.dll using Microsoft Visual C++ Developer Studio:

  1. Create a directory to store all of the workspace information, call it UDPDir.
  2. Use the sample workspace RectangularSpiral.dsw as a template:
    1. Copy RectangularSpiral.dsw and RectangularSpiral.dsp from the /UserDefinedPrimitives/Examples directory to this new directory.
    2. Make sure the new files have write permissions.
    3. Rename the files to myUDP.dsw and myUDP.dsp respectively.
    4. Open the .dsw and .dsp files in a text editor, and replace every occurrence of RectangularSpiral with myUDP.
    5. Save myUDP.dsp and myUDP.dsw.
  3. In the UDPDir directory, create a Headers subdirectory.
  4. Copy the UserDefinedPrimitiveStructures.h and UserDefinedPrimitiveDLLInclude.h files from the /UserDefinedPrimitives/Headers directory.
  5. Note: The header files include information on the methods that are available for use in your source code. They must be included when you compile the DLL.
  6. In the UDPDir directory, create a Sources subdirectory.
  7. Use the sample source file RectangularSpiral.cpp as a template:
    1. Copy RectangularSpiral.cpp from the /UserDefinedPrimitives/Examples directory to this new directory.
    2. Make sure the new file has write permission.
    3. Rename the file to myUDP.cpp.

    The resulting directory structure will appear similar to the following:

  8. Open myUDP.dsw using Microsoft Visual C++ Developer Studio, and edit the source code to create your desired primitive. You may also add additional headers and source files as appropriate.
  9. The UDP dll contains a data structure called UDPPrimitiveTypeInfo. This contains information about the UPD, its purpose, company/author who created it, date created, and the version number. When you select a primitive from your library, you see the Create Primitive dialog box with a Parameters tab for setting the parameters, and an Info tab with the information from this data structure.

  10. Build myUDP.dll using the Win32 Release configuration.
  11. Copy the resulting file myUDP.dll to the [ProductInstallationPath]/userlib/UserDefinedPrimitives directory.
  12. Optionally, copy the resulting file to the UserDefinedPrimitives directory in your PersonalLib. The PersonalLib directory path is specified on the Directories panel under General in the Options window.

  13. To view your primitives, click Draw > User Defined Primitive > Update Menu and then click Draw > User Defined Primitive > UserLib or Draw > User Defined Primitive > PersonalLib.
Note: On Linux, you may use the same example directory structure, source, and header files to build and compile a shared library using C++. The resulting shared library needs to be placed in the same /userlib/UserDefinedPrimitives directory.
As with the Windows DLL, the compiled library will work only on the operating system on which it was built.

Related Topics 

User-Defined Primitives for Motor Geometries

Drawing a Spiral Using User-Defined Primitives

Drawing a Segmented Helix with Polygon Cross-Section Using a User-Defined Primitive

Drawing a Segmented Helix with Rectangular Cross-Section Using a User-Defined Primitive