Pro/TOOLKIT
I'm using Pro/ENIGNEER Wildfire 3.
Contents |
Installation
Pro/TOOLKIT is sold as a component of Pro/ENGINEER. If your license allows, you can install Pro/TOOLKIT along with Pro/ENGINEER. There should be an option during the Define Installation Components section of the install with something like:
API Toolkits—Select this component to optionally install the files necessary to run the Application Program Interface toolkits like Pro/J.Link, Pro/Web.Link, and Pro/TOOLKIT.
Setting Up A Project
I found a tutorial on setting up a visual studio project at [1]. I used Visual Studio .Net 2003 and had no problems.
Hello World
The simplest method for a "HelloWorld" program is likely the following:
ProStringToWstring (UserMsg, "C:\\cygwin\\home\\Admin\\tkTest\\TKTEMPLATE\\msg_user.txt");
ProMessageDisplay (UserMsg, "USER %0s",
"Hello World.");
where msg_user.txt has the following:
USER %0s %0s # # USER -HelloWorld HelloWorld # # USER -MainBtn1 -MainBtn1 # # USER New Button help. New Button help. # # USER -Sub1 -Sub1 # # USER -Sub1Btn1 -Sub1Btn1 # # USER -Sub1Btn2 -Sub1Btn2 # #
The path will obviously have to be changed to wherever you keep the file. These message files keep the text that is displayed in Pro/ENGINEER. A typical use will be something like the following:
status = ProMenubarMenuAdd ("HelloWorld", "USER -HelloWorld",
"Utilities", PRO_B_TRUE, UserMsg);
Here, a button will recieve the text defined in the file under "USER -HelloWorld." In the above, this is HelloWorld. However, if the the text file instead had the entry
USER -HelloWorld Export
the button would be named "Export." A quirky feature of these message files is that changes in them will only be recognized once Pro/ENGINEER is closed down and restarted. Merely restarting the auxiliary application or re-registering it is insufficient.
Hello Button
The added functionality of some of the above code hints at what is to come here: a short talk on adding menus to Pro/E. This section is based on code from the user guide, which has had its buggy portions removed.
#include <time.h>
#ifdef USE_ANSI_IOSTREAMS
# include <iostream>
using namespace std;
#else
//# include <iostream.h>
#endif
#include "TestError.h"
/*--------------------------------------------------------------------*\
Pro/Toolkit includes
\*--------------------------------------------------------------------*/
#define PRO_USE_VAR_ARGS
#include <ProDrawing.h>
#include <ProMenuBar.h>
#include <ProMessage.h>
/*--------------------------------------------------------------------*\
Application global/external data
\*--------------------------------------------------------------------*/
static wchar_t MSGFIL[] = {'m','s','g','_','u','s','e','r','.','t','x','t','\0'};
static char revcode[PRO_LINE_SIZE];
/* Declare function */
ProError ProTestInstallationCheck();
ProError ProTestInstallationURLCheck();
ProError ProTestDialogCreate ( ProBoolean is_successful );
extern "C" static uiCmdAccessState TestAccessDefault(uiCmdAccessMode access_mode)
{
return (ACCESS_AVAILABLE);
}
/*================================================================*\
FUNCTION: MiscAction()
PURPOSE: Generic action function
\*================================================================*/
extern "C" int MiscAction()
{
wchar_t UserMsg[80];
ProStringToWstring (UserMsg, "C:\\cygwin\\home\\Admin\\tkTest\\TKTEMPLATE\\msg_user.txt");
ProMessageDisplay (UserMsg, "USER %0s", "Action function called.");
return (0);
}
/*===========================================================================*\
Function : main
Purpose : Test the ProToolkitMain() function. main is optional function.
\*===========================================================================*/
int main(int argc, char **argv)
{
// cerr << endl << "\tWelcome to Pro/TOOLKIT - The \"pt_install_test\" program" << endl;
ProToolkitMain(argc, argv);
return(0);
}
/*====================================================================*\
FUNCTION : user_initialize()
PURPOSE : Pro/DEVELOP standard initialize - define menu button
\*====================================================================*/
extern "C" int user_initialize(
int argc,
char *argv[],
char *version,
char *build,
wchar_t errbuf[80])
{
char cbuff1[PRO_PATH_SIZE], cbuff2[PRO_PATH_SIZE];
char astr1[PRO_LINE_SIZE];
int i, menu_id;
ProPath wbuff1, wbuff2;
ProError status;
uiCmdCmdId cmd_id;
wchar_t UserMsg[80];
/*================================================================*\
Say hello and add menu buttons.
\*================================================================*/
/*----------------------------------------------------------------*\
Message file.
\*----------------------------------------------------------------*/
ProStringToWstring (UserMsg, "C:\\cygwin\\home\\Admin\\tkTest\\TKTEMPLATE\\msg_user.txt");
ProMessageDisplay (UserMsg, "USER %0s", "Apples2Apples export tool started.");
/*----------------------------------------------------------------*\
Add a new menu to the menu bar (to the right of Utilities).
\*----------------------------------------------------------------*/
status = ProMenubarMenuAdd ("Exporter", "USER -Exporter",
"Utilities", PRO_B_TRUE, UserMsg);
/*----------------------------------------------------------------*\
Add to the new menu.
\*----------------------------------------------------------------*/
status = ProCmdActionAdd ("UserDispMsg", (uiCmdCmdActFn)MiscAction,
uiCmdPrioDefault, TestAccessDefault, PRO_B_TRUE, PRO_B_TRUE,
&cmd_id);
status = ProMenubarmenuMenuAdd ("Exporter", "Sub1", "USER -Sub1",
NULL, PRO_B_TRUE, UserMsg);
/*----------------------------------------------------------------*\
Fill in the buttons of Sub1.
\*----------------------------------------------------------------*/
status = ProMenubarmenuPushbuttonAdd ("Sub1", "Sub1Btn1",
"USER -Sub1Btn1", "USER New Button help.", NULL, PRO_B_TRUE,
cmd_id, UserMsg);
return(0);
}
/*====================================================================*\
FUNCTION : user_terminate()
PURPOSE : To handle any termination actions
\*====================================================================*/
extern "C" void user_terminate()
{
/*---------------------------------------------------------------------*\
Loging file close.
\*---------------------------------------------------------------------*/
ProTestErrlogClose();
// cout << "user_terminate" << endl;
}
- ProMenubarMenuAdd - this creates a button on the highest level menu next to "Utilities," which is actually the Tools button...
- ProMenubarmenuMenuAdd - this adds a menu to the menu that was added with ProMenubarMenuAdd.
- ProMenubarmenuPushbuttonAdd - This adds a button off of the menu just added an associates with it the action created with ProCmdActionAdd.
Integration with other DLLs
The documentation for Pro/TOOLKIT in the windows environment is, as near as I can tell, virtually non-existent. The best documentation that I've been able to find is the website cited earlier. This site brings up a difficulty in integrating Pro/TOOLKIT with other libraries: modern dlls are often built with the a multi-threaded runtime library. In order to build a Pro/TOOLKIT dll with a multi-threaded runtime library, the following changes must be made to the set up sequence described in the cited site:
- Do not link to protk_dll.lib. Instead link to protk_dllmd.lib.
- Change the runtime library to Multi-threaded Debug DLL or the non-Debug version.
- If needed, explicitly include MSVCRTD.lib (debug) or MSVCRT.lib.
The project should now be able to be built and run from Pro/ENGINEER as well as integrated with existing dlls.
Links
1: http://www.caddigest.com/subjects/pro_engineer/select/tutorials/jovanovic_toolkit_environment.htm