by Vojin Jovanović, April 24, 2003
An Application Programmers Interface (API), Pro/TOOLKIT allows Pro/ENGINEER functionality to be augmented and/or customized to meet the specific needs of PTC's customer base using the "C" programming language. Specifically, Pro/TOOLKIT provides the ability to customize the standard Pro/ENGINEER user interface, automate processes involving repetitive steps, integrate proprietary or other external applications with Pro/ENGINEER, develop customized end-user application for model creation, design rule verification and drawing automation.
Unfortunately, Pro/TOOLKIT deservingly gained a reputation of being hard to work with. Such state of the affairs is the result of current PTC's vision which dictates where and how this product ought to augment the functionality of Pro/ENGINEER. This vision, as the series of the articles to follow will show, is by no means "visionary" as toolkit users would hope for and rather leaves quite a few features to be desired. In these articles we will explore what it takes to work with this product as well as how one can go beyond what PTC supports today.
Quite often one notices new users wanting to learn Pro/TOOLKIT programming that rather too often get discouraged by a number of issues that arise in their first days of struggle. One of the problems that a newcomer is faced with is the setting of the proper development environment so that one can work with Pro/TOOLKIT. The problem is so frequent that somebody by now should have done something about it (especially PTC), unfortunately, to my knowledge, as of today, nobody has.
The development of Pro/TOOLKIT applications does not look so ugly on Unix OS since PTC has adequate support there for toolkit users and to work with Pro/TOOLKIT is via make files (which is a normal way of doing things on Unix), but it looks very ugly on Windows platforms where the support by PTC is minimal and where the normal way of developing applications is with IDE like Visual Studio. Therefore our focus in this article will be dedicated to those new users who often post pleas for help in toolkit user groups related to latter.
First, it is worth mentioning, to make it easier for newcomers, that Pro/TOOLKIT consists of a few libraries: prodevelop.lib ,protoolkit.lib, pt_asynchronous.lib and protk_dll.lib as well as numerous include files. The libraries are precompiled by PTC and sold to the user (for about $20K) with a humongous size of over 2000 function calls. This is quite overwhelming for new users and for that purpose PTC provides an API browser and substantial number of examples that one can re/use for his/her own purpose. However, to work with these examples on Windows platform is not a simple matter. The difficulty is in the form of nmake files in which projects are offered by PTC. Even though VC++ supports this way of building modules, this is an archaic way (coming from Unix) of developing projects that lacks all of the benefits contained in GUI of Visual Studio. Therefore, the Windows toolkit developers attempt to set VC++ projects themselves and at that moment they enter their of own painful world with no site of PTC's tech support so here is where we take off in this article.
We'll look at how one proceeds in setting up a project in VC++ .NET for running a toolkit application within Pro/ENGINEER as well as connecting to it from outside. Both ways have pros and cons and in the end it depends on what one wants to achieve.
We begin with a first project of setting up a Windows DLL application that will get registered with Pro/ENGINEER and will run through a button from Pro/E menus.
Start by creating a new project in VC++ .NET and chose a Win32 application. Enter a name of the project and chose Application Settings (see the required selection bellow)
This will give you the empty project into which you can start adding your C/C++ files. Now, the first thing to do, if you already haven't done so, is to enter your Pro/TOOLKIT include and library directories paths. This is done under Tools/Options ... menu. Observe the paths bellow for include files.
and for the library files ...
The next thing to worry about is the stuff under the Project/Properties menu. There are a lot of parameters that Visual Studio allows you to set and that is the single most troublesome source of problems for Pro/TOOLKIT users. Sometimes even more experienced users of Pro/TOOLKIT have problems setting the right switches while trying to create a blank project.
So here we go.
Selecting the Project/Properties menu under C/C++ you'll get the configuration panel (see bellow). You may accept what is in General by default, while in Optimization just select Disabled (/Od). Now the next selection is Preprocessor as shown bellow.
Enter the set of defines as follows ...
PRO_MACHINE=29
PRO_OS=4
hypot=_hypot
MSB_LEFT
far=ptc_far
huge=p_huge
near=p_near
_X86_=1
_WSTDIO_DEFINED
You'll find these defines in PTC's nmake files and apparently they affect the code generation, so it is good to have them, but the project will build even without having them.
The next is the most important selection related to Code Generation. There you need to make a choice regarding the run time libraries. When it comes to DLL's PTC provides a couple of libraries for linking which are single/multi-threaded. Here we choose to work with single threaded, therefore select MLd switch as shown bellow.
Other default switches in C/C++ configuration section you may inspect, but they are not as relevant, so you are done here. Now, we go to Linker section (see bellow). Under General just choose the name of you output file and then proceed to Input section. This is the most important section. Here you'll enter the libraries that you want your object files to be linked with. Since we selected MLd switch before we have to use a single-threaded library protk_dll.lib. If we had chosen MDd switch (multi-threaded debug) we would need to use protk_dllmd.lib. Now, enter as shown bellow and you are done.
Note that a standard libc.lib library is ignored above. Often you'll see that when you want to build Toolkit projects, errors like "already defined .... in libc.lib" or something similar will show up. Now this is a sign that in some of the pre-compiled libraries contain some symbols that are already defined in Toolkit libraries, therefore a complaint from VC. In such cases you'll need to ignore some of the standard libraries as it was done above. This is a very annoying part of building Pro/TOOLKIT projects, and it should have been handled better by PTC.
That is it. The project should be able to be built now without problems.
Now we come to building executable applications that can be used to connect to Pro/ENGINEER and do the job for us externally. This is the road out of the pre-designed development box that PTC would like to keep us in, but luckily they leave an exit door for the bravest, so we need to set up a template project for this kind of business too.
The configuration parameters are almost the same as above except at a couple of places.
First, start a new Win32 application and select it to be a console empty project as shown bellow
Now, add your C/C++ files as usual and proceed to Project/Properties panel and consider the following.
The three main libraries supplied by PTC that you will use are pre-compiled as single/multi-threaded. Again, as before, we'll use a single threaded switch and the libraries to choose are as shown bellow. In case you have to use multi-threaded switch which you need for MFC then you'll enter in the linker section bellow ptasyncmd.lib, protkmd.lib, and prodevmd.lib instead.
However, not that Pro/TOOLKIT is officially not supported for multi-threaded applications. The above libraries that can be used with MFC are just the same libraries pre-compiled with the MDd switch. This doesn't really make them safe to use in real multi-threaded applications since they are not designed as such. Therefore, you are on your own. You'll find yourself like this often as far as Pro/TOOLKIT is concerned.
Note again that libc.lib is ignored.
All other switches in C/C++ and the linker sections are similarly set as in DLL set up above.
Finally, you can build this project and get an exe file that should run without problems.
For those of you who got lost in the above and could not get the stuff to work you can download two zipped projects bellow.
The first one is a Visual Studio DLL project which is the install test provided by PTC. Extract the files into a directory of your choice (use folder names in the zip archive). Start Visual Studio and open the project. The project assumes that you installed Pro/E 2001 into its default location together with Pro/TOOLKIT, so that C project files will be picked up from that location (of course I can't distribute PTC's C files). If you didn't install Pro/E into its default location you will see an error, and you'll have to add to Source Files these four files TestError.c TestInstall.c TestRunmode.c and UtilString.c yourself. After building the dll simply register it as an Auxilary Application in Pro/E via install.dat provided, but don't forget to adjust the path location in install.dat to reflect where the project resides (change PATH_TO_YOUR_LOCATION_OF in install.dat to wherever you unzipped the project). After registering it, to run the applications select the new button -Install Test from the File menu in Pro/E.
The second project is my own (so I can distribute it) application example that is a stand-alone executable. Besides providing you with a template exe project it also serves to teach you how to set up a notification business. After building it, just start Pro/E and start the built executable from Debug directory. The executable will connect to Pro/E and react to your regeneration of models in the session. Study the code to learn more.
This brings us to the end of setting up your environment in VC++ .NET. Hopefully this explanation makes it easier for new users to start working with Pro/TOOLKIT and relieves the pain that most people initially experience with this product.
Vojin Jovanović is an independent consultant with 20 years of experience developing Pro/TOOLKIT applications in the area of design optimization and automation as well as over 10 years of experience in developing scientific numerical applications. He has published in international journals and presented at various conferences. His area of expertise is in computational geometry related to MCAD and in development of financial applications. You can reach him at fractal97@hotmail.com or visit his website.