Thursday, February 14, 2008

Example ProTookit Application using Visual Studio 2005

PTC has been offering an Application Programming Interface (API) for Pro/Engineer for many years now and I have seen an article or two or three online that shows you how to develop Pro/Toolkit applications using Visual C++. These are very useful and if you navigate to the bottom of the page on article three then you will find a few zip files that you can download and start working with Visual C++ and Pro/Toolkit quickly. There is even a site that sells you tutorials on how to develop Pro/Toolkit applications. Of course I have never purchased any such tutorials so am unable to recommend them.

Interestingly very little outside help is available on developing Pro/Toolkit Applications using Visual C++. Simply Googling for Pro/Toolkit help is of very very little help. So what is a Pro/Toolkit developer to do?

In an effort to help other Pro/Toolkit developers who are using Visual C++ 2005 I have attached a zipped workspace created in Visual Studio 2005. This zipped workspace allows you to create a DLL that creates a Menu in the Pro/Engineer interface. Please use this workspace as a starting point - it is not by no means the perfect workspace (for example I currently put the menu.txt in two locations - which is not the most efficient way to do it). This workspace was created and donated by a colleague of mine, Amar Junankar (although I had created a similar workspace and have kept it updated for many years).

If you notice carefully in the workspace (after unzipping) in both the "debug" and "release" sub-folders there is a batch file named "Start_ProE_Here.bat". What this batch file does is start Pro/Engineer (default location of "C:\Program Files\proeWildfire 3.0\bin\proe.exe") from the "debug" or "release" (viz. current) sub-folder. This ensures that the protk.dat (which Pro/Engineer uses to register Pro/Toolkit applications) is loaded on startup of Pro/Engineer thus enabling our Pro/Toolkit application. Of course before starting this batch file, please do a build of both debug and release configurations.

As a side note: In my next post I will add to this workspace the necessary lines of code that will allow a developer to call .NET assemblies from within the Pro/Toolkit Application.

If you need any help please post a comment and I will try to help as much as I can.

Monday, February 04, 2008

.NET in Pro/Toolkit

Summary: Can we use .NET to develop Pro/Toolkit applications for Pro/Engineer?

I have seen numerous articles providing tutorials (heres one and another one) on how to develop Pro/Toolkit applications using Visual C++ (either 2003 or 2005). Now the articles refer to developing Pro/Toolkit applications using Visual C++.NET which I think is misleading since the .NET portion refers (I believe) to Managed Visual C++ code while the articles refer to Unmanaged Visual C++ code.

So this begs the question: how does one develop Pro/Toolkit applications using Visual C++.NET Managed Code and is this even possible?

The short answer is NO - YOU CANNOT DEVELOP Pro/Toolkit APPLICATIONS USING VISUAL C++.NET MANAGED CODE (or C# or Visual Basic.NET).

The long answer is PERHAPS - I found a product by ETRAGE LLC named ACI for Pro/Engineer that provides a COM wrapper around Pro/Toolkit functions. Using such a wrapper developers can code Pro/Toolkit applications using pure .NET languages. In fact the product page provides sample code in Visual Basic.NET. This is pretty nice, since if I were to replicate such functionality then I would need to create a DLL (since I could not find a DLL containing Pro/Toolkit functions for Pro/Engineer Wildfire 3.0) that exports the functions in the LIB and mentioned in the header files and then use that DLL in .NET through .NET's Platform Invoke - which is a lot of work - not difficult but a lot of work (major testing would be required). I will try this method out and if it works will post another article with a HowTo.

But suppose you wanted to merely call functions from .NET classes in your Pro/Toolkit application then there is a simple way to do so using the idea of exposing .NET objects through COM interface. This article on CodeProject provides a great tutorial on how to do just that. Of course you are still developing the Pro/Toolkit application using Visual C++ but now you can consume .NET objects easily.

An FYI though if you use the method suggested by the CodeProject article - there is a slight slowdown when you call the COM methods (I think the call to CoInitialize is what causes this problem) - so initialize and finalize the COM components once for your application instead of for each method call.

I will try and post a sample workspace with my next post that shows how to use .NET objects in Pro/Toolkit applications. If anyone has any comments or questions please provide them below I will do my best to answer them.