Creating a User Defined Primitive
The modeler allows you to generate user-defined primitives, primitives customized to suit any application. User-defined primitives are accessed using DLLs or IronPython scripts that you build and compile. When user defined primitives exist in your UserLib or PersonalLib directory (given the paths specified in Tools > General Options, Project Options tab), they appear in the menu bar under Draw > User Defined Primitives. Newly created UDPs will appear after a restart or after executing the command Draw > User Defined Primitive > Update Menu.
For Python-based primitives, see the
The modeler includes example C++ source and header files that can be used to generate DLLs. The files are located in the UserDefinedPrimitives/Examples subdirectory under the directory.
As an example, create the primitive myUDP.dll using Microsoft Visual C++ Developer Studio:
- Create a directory to store all of the workspace information, call it UDPDir.
- Use the sample workspace RectangularSpiral.dsw as a template:
- Copy RectangularSpiral.dsw and RectangularSpiral.dsp from the UserDefinedPrimitives/Examples directory to this new directory.
- Make sure the new files have write permissions.
- Rename the files to myUDP.dsw and myUDP.dsp respectively.
- Open the .dsw and .dsp files in a text editor, and replace every occurrence of RectangularSpiral with myDLL.
- Save myUDP.dsp and myUDP.dsw.
- In the UDPDir directory, create a Headers subdirectory.
- Copy the UserDefinedPrimitiveStructures.h
and UserDefinedPrimitiveDLLInclude.h
files from the UserDefinedPrimitives/Headers
directory.
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.
- In the UDPDir directory, create a Source subdirectory.
- Use the sample source file RectangularSpiral.cpp as a template:
- Copy RectangularSpiral.cpp from the UserDefinedPrimitives/Examples directory to this new directory.
- Make sure the new file has write permission.
- Rename the file to myUDP.cpp.
The resulting directory structure will resemble the following:
-
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.
The UDP dll contains a data structure called UDPPrimitiveTypeInfo. This contains information about the udp, 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 with a Parameters tab for setting the parameters, and an Info tab with the information from this data structure.
- Build myUDP.dll using the Win32 Release configuration.
- Copy the resulting file myUDP.dll to the [ProductInstallationPath]/userlib/UserDefinedPrimitives directory or the [PersonalLibPath]personallib/UserDefinedPrimitives directory.
- To view your primitives, click Draw > User Defined Primitive > Update Menu and then click Draw > User Defined Primitive > [PrimitiveToDraw].
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 will have a .so extension and 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.