Showing posts with label Pro/ENGINEER customization. Show all posts
Showing posts with label Pro/ENGINEER customization. Show all posts

Nuts and Bolts

In this and few subsequent blogs, I would like to introduce Pro/Toolkit. It will be a helpful guide for the new users, experienced user may skip this section. Throughout this series of blog I will be using a Windows XP machine and my compiler will be Visual Studio. To keep it simple in the beginning, I will compile my Pro/Toolkit applications using the command line arguments of the VC compiler. For UNIX users, I would like to help them by emails if they have any specific requirement. You will be required to keep the index.html (APIWizard) started from the (ProENGINEER_LOADPOINT)\protoolkit\protkdoc folder.
To begin with, new Pro/Toolkit users must know some key stuff as listed below:
Pro/Develop - This was the customization tool used in Pro/ENGINEER till Pro/Toolkit replaced it in the Release 17 of Pro/ENGINEER. Though, we have a better product in Pro/Toolkit, we may still use Pro/Develop to build our application. In fact, there are few areas where there is no equivalent Pro/Toolkit function and we are required to use Pro/Develop functions. Both Pro/Toolkit and Pro/Develop uses the same mechanism to connect to Pro/ENGINEER, so in a single application we may have a mix of both these products.
protk.dat file - This is the file which registers a pro/Toolkit application in Pro/ENGINEER. It is a text file with .dat extension for Pro/ENGINEER to recognize and register the application. I will be taking a closer look at this file later on.
Environment variables: There are few environment variables required to be set for asynchronous application but for synchronous application no additional environment variables are required to be set. The environment variable "PRO_COMM_MSG_EXE" should point to "(ProENGINEER_LOADPOINT)/obj/pro_comm_msg.exe" file. The other environment variables like Pro/ENGINEER path, etc are already set when installing Pro/ENGINEER. Some special environment variables are required for J-link, which we will cover when we touch that topic.
Synchronous Application: This is the mode of Pro/Toolkit when the application is registered in Pro/ENGINEER and is controlled by the Pro/ENGINEER session. This application has no main () function but two mandatory function called user_initialize () and user_terminate (). The function user_initialize () is the first function to be visited when the application is being called from Pro/ENGINEER. Standalone synchronous application is not feasible as it has no main () function and it dependent on Pro/ENGINEER session to make calls to it. There are two ways of creating a synchronous application; Spawn mode and DLL mode.
  • Spawn mode: In this mode the executable file interacts with the Pro/ENGINEER process (xtop.exe) using Inter Process Communication (IPC). This mode is slower as compared with the DLL mode but while developing an application, this mode is recommended as it is easier to debug a smaller application.
  • DLL mode: In this mode the executable (DLL file) gets embedded inside the Pro/ENGINEER process (xtop.exe), while it launches. This mode is much faster than the spawn mode. This mode should be used when the application has to be released for the end users.
Asynchronous Application: In this mode, the executable file has its own main () function. Which means it can exist independently. In this mode the application makes a call either to connect to an existing Pro/ENGINEER session or to start a new Pro/ENGINEER session. In this mode the Pro/ENGINEER process (xtop.exe) and application perform operations concurrently. There are two forms of Asynchronous application; Simple Asynchronous Mode and Full Asynchronous Mode.
  • Simple Asynchronous Mode: In this mode there is no implementation in the application to handle the request from Pro/ENGINEER. So, any event (user click, feature failure etc) will not be passed on to the application to react to it. This application can start/connect to Pro/ENGINEER session and ask Pro/ENGINEER to perform some tasks and then disconnect/end Pro/ENGINEER session. None of the functions of the applications can be invoked by Pro/ENGINEER.
  • Full Asynchronous Mode: In this mode, there is a mechanism to handle the requests from Pro/ENGINEER. In this mode, the application has to implement a control loop that waits for messages from Pro/ENGINEER. In this mode, Pro/ENGINEER can call functions in the application also the application can react to events in Pro/ENGINEER.
MSVC Vs Command prompt: There are two different ways by which we can compile and create an executable file in Pro/Toolkit. The first way is to create a project in Visual Studio and then compile the code. Though this mode is very user friendly, it could become a daunting task for the new users to learn Pro/Toolkit as well as the operations of the Visual studio. For setting up the Visual studio project, please read the chapter 2 of Getting started guide of Pro/Toolkit in the Wildfire 4.0 installation directory (Protoolkit_GSG.pdf). If you have prior experience in Visual studio I would highly recommend it. Otherwise for a new user it would be better if we follow the command prompt way of compiling to start with and then moving on to Visual Studio. In the command prompt mode we normally set the environment variables of the VC compiler in the command window and then compile our code with the "nmake" option. I will cover how we can set up the environment variables of the VC compiler and compile a Pro/Toolkit application. I would encourage all to use the make files supplied by PTC. Throughout this blog I will use the PTC's makefiles to compile my applications.
Makefile: I will be covering the Makefile in more details later on. For the time being you may consider a make file as an instruction file for the compiler about the various compiler flags to be set while compiling and linking the application to the Pro/ENGINEER libraries.
________________________________________________________
These are the few concepts/terms which should help new users to accelerate their learning. Again, do let me know if you find this blog interesting, do leave me a comment; I will be happy to interact with you. I am signing off for now.
_________________________________________________________
TRADEMARKS: Pro/ENGINEER, Wildfire, Pro/Toolkit, Pro/Develop, J-Link, Pro/Web.Link and VB API are the registered trademarks of PTC (http://www.ptc.com/). All other products or services mentioned in this blog are the trademarks or service marks of their respective companies or organizations.

Getting Started

In this section we will build a skeleton synchronous Pro/Toolkit application from the scratch. You should have a compiler to compile code. In this example I will be using the Microsoft Visual C++ 6 and Pro/ENGINEER Wildfire 2.0. I will use the command prompt for compiling the code with the help of PTC provided standard make files. Create a folder and copy the "make_basic" file from the "[TK_LOADPOINT]/ [MACHINE]/obj" folder. Now open the file with any text editor and edit the text in the file as shown below:
~~~~~~~~~~~~~~~~~~~~
Line#23 -->> EXE = pt_basic.exe change it to EXE = tkapp.exe ( we will call our application "tkapp")
Line#24 -->> EXE_DLL = pt_basic.dll change it to EXE_DLL = tkapp.dll
Line#27 -->> PROTOOL_SRC = ../../../protoolkit change it to PROTOOL_SRC = [PROE_LOADPOINT]/protoolkit (this is required for the compiler to know the location of the library file and the include files of Pro/Toolkit)
Line#29 -->> PRODEV_SRC = ../../../prodevelop change it to PRODEV_SRC = [PROE_LOADPOINT]/prodevelop (this is required for the compiler to know the location of the library file and the include files of Pro/Develop)
Line#73 -->> OBJS = pt_basic_src.obj pt_utils.obj change it to OBJS = tkapp.obj (we indicate that there will be an intermediate file with the name tkapp.obj created)
Line#94 -->> pt_basic_src.obj: $(PROTK_APPLS)/pt_basic/pt_basic_src/pt_basic_src.c
$(CC) $(CFLAGS) $(PROTK_APPLS)/pt_basic/pt_basic_src/pt_basic_src.c change it to tkapp_src.obj: tkapp.c
Remove the line starting with "pt_utils.obj" completely.
~~~~~~~~~~~~~~~~~~~~
Save the file and exit the editor. Now the second task is to get the source code going. To start with, we will write a small program in Pro/Toolkit. As mentioned in my previous blog, for a synchronous application the requirement is to have a user_initialize() and a user_terminate() function. We will open a text editor again and write the code as shown below (The name of the code file should be tkapp.c):
~~~~~~~~~~~~~~~~~~~~
#include "ProToolkit.h" // This include file is a must
/********************************/
int user_initialize() // This is a must for sync applications
{
printf("\nHello Pro/Toolkit World !!\n");
return (0);
}
/********************************/
void user_terminate() // This is a must for sync applications
{
printf("\nGoodbye !!\n");
}
~~~~~~~~~~~~~~~~~~~~
Save the file as tkapp.c in the same directory which was created in step 1. Open a command prompt and then go to the directory which was created in step 1. At this point you will have to set the environment for using Microsoft Visual C++ tools on the command window. You will type something like this on the command prompt "C:\Program Files\Microsoft Visual Studio\VC98\Bin\VCVARS32.bat" (The path could vary if you have the "Microsoft Visual Studio", installed on a different folder). After running this batch file (VCVARS32.bat), you will get a system message as “Setting environment for using Microsoft Visual C++ tools.”
Once the environment is set in the command prompt, we will compile the program “tkapp.c” by using the namke function, we will type “nmake -f make_basic”. This is going to compile the program and give us the “tkapp.exe” which is our first executable Pro/Toolkit application. Please refer to the command line snapshot below for more details.

Once the application is ready we will have to just make a protk.dat file to register the application in Pro/ENGINEER. The protk.dat file is a text file which has .dat extension for Pro/ENGINEER to recognize and register the Pro/Toolkit application. I am pasting the contents of the protk.dat file for the above application below:
~~~~~~~~~~~~~~~~~~~~
name tkapp
Startup exe
Allow_stop True
Delay_start False
exec_file tkapp.exe
text_dir .
END
~~~~~~~~~~~~~~~~~~~~
For details about the contents of the protk.dat file please refer to PTC guide for Pro/Toolkit (tkuse.pdf). After having the protk.dat file you may launch Pro/ENGINEER from the same directory and get the application running as shown in the snapshot below:
___________________________________________________________________
This is a skeleton application to have us up and running. The subsequent blog entries will deal with more complex features of Pro/Toolkit. I hope that all the readers will be able to follow the steps and complete the application as suggested in this blog. Please feel free to write to me and I will be glad to answer. Do subscribe to this blog and get updates as and when it happens. I will be posting the entries on regular intervals, do leave me a comment; I will be happy to interact with you. In case you require the source code and other files from this application, feel free to write to me at Alxn.Page@gmail.com. Thanks for your valuable time in reading through…. Bye for now, God Bless!!
_________________________________________________________
TRADEMARKS: Pro/ENGINEER, Wildfire, Pro/Toolkit, Pro/Develop, J-Link, Pro/Web.Link and VB API are the registered trademarks of PTC (http://www.ptc.com/). All other products or services mentioned in this blog are the trademarks or service marks of their respective companies or organizations.

Asynchronous Application

For a head start on Asynchronous applications, please read my previous post “Nuts and Bolts” or follow the link. I have given brief summary about the Asynchronous mode. For more details refer to the section “Asynchronous Mode” from the toolkit user guide.

It is very important for an asynchronous application to have the following environment variable set.
On Windows:
PRO_COMM_MSG_EXE = (ProENGINEER_LOADPOINT)\i486_nt\obj\pro_comm_msg.exe
On Unix:
% setenv PRO_COMM_MSG_EXE (ProENGINEER_LOADPOINT)//obj/pro_comm_msg
Here is an example of Simple Asynchronous application. It launches a Pro/ENGINEER session and then create a PART, saves it and then Displays it.
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/*************************************************\
This is an Asynchronous application which launches
a Pro/E session and then create a PART and save and
Display it. It also activates the window
\*************************************************/

/*************************************************\
Pro/Toolkit Includes files
\*************************************************/
#include "ProToolkit.h"
#include "user_tk_error.h"
#include "ProCore.h"
#include "ProMdl.h"
#include "ProObjects.h"
#include "ProSizeConst.h"
#include "ProUtil.h"
/*************************************************\
Main Function
\*************************************************/
int main( int argc, char *argv[] )
{
char *arg_ptr;
int w_id;
ProName part_name;
ProError status;
ProSolid p_part, model;
/*************************************************\
Pro/ENGINEER launched asynchronously
\*************************************************/
if ( argc == 3)
{
arg_ptr = argv[1];
status=ProEngineerStart(arg_ptr,"");
printf("\n\n*The ProEngineerStart status: %d",status );
}
else
{
printf("Use Syntex: toolkit \n"); /* make sure to use a unique name for the Pro/E part, everytime the application is launched*/
exit(1);
}
/*************************************************\
Set up the part name from the argument list.
\*************************************************/
arg_ptr = argv[2];
ProStringToWstring(part_name,arg_ptr);
/*************************************************\
Retrieve a part with that name.
\*************************************************/
status=ProSolidCreate (part_name, PRO_MDL_PART, &p_part);
if (status!=PRO_TK_NO_ERROR)
{
printf("\n\n* Failed to Create part %s", arg_ptr); /* If the part file name exist on the working folder, Pro/E will exit giving error*/
}
/*************************************************\
Save the part
\*************************************************/
status=ProMdlSave((ProMdl)p_part);
printf("\n\n*The ProMdlSave status: %d",status );
if (status!=PRO_TK_NO_ERROR)
{
ProEngineerEnd(); /* If there is a specials character(e.g.#^%~ ) in the model file name, Exit Pro/E */
}
/*************************************************\
Retrieve the model
\*************************************************/
status = ProMdlRetrieve(part_name, PRO_MDL_PART, &model); /*It neither displays the model nor makes it the current model*/
printf("\n\n*The ProMdlRetrieve status: %d",status );
/*************************************************\
Display the Model
\*************************************************/
status = ProMdlDisplay((ProMdl)model);
printf("\n\n*The ProMdlDisplay status: %d",status );
/*************************************************\
Activate the Model
\*************************************************/
status = ProMdlWindowGet(model, &w_id);
status = ProWindowActivate(w_id);
return(0);
}
/*************************************************\
End of Application
\*************************************************/
If you need any help in compiling and running this application please get in touch with me at Alxn.Page@gmail.com. Thanks for your valuable time in reading through…. Happy coding, God Bless.

_________________________________________________________

TRADEMARKS: Pro/ENGINEER, Wildfire, Pro/Toolkit, Pro/Develop, J-Link, Pro/Web.Link and VB API are the registered trademarks of PTC (http://www.ptc.com/). All other products or services mentioned in this blog are the trademarks or service marks of their respective companies or organizations.