This section describes how to use C # to package the connection to Pro/ENGINEER.
Title
Simple asynchronous mode
Start and Stop Pro/ENGINEER
Connect to a Pro/ENGINEER Process
Full asynchronous mode
C # program troubleshooting
Simple asynchronous mode
A simple asynchronous mode program does not implement a handle request from Pro/ENGINEER. Therefore, C # cannot intercept the notification when an event occurs in Pro/ENGINEER. Correspondingly, Pro/ENGINEER cannot call the methods that must be provided when you add them, for example, the menu button of Pro/ENGINEER.
Due to this limitation, a simple asynchronous mode program can be used to automate processes in Pro/ENGINEER. The program may start or connect to an existing Pro/ENGINEER session, or access Pro/ENGINEER in interactive or graphic mode.
When the Pro/ENGINEER is running in a graph, there are still interaction processes available to users. When you design a C # program in simple asynchronous mode, you have the following ideas in mind:
- The Pro/ENGINEER processes and programs perform operations at the same time.
- No listening method of a program can be called by Pro/ENGINEER.
Start and Stop Pro/ENGINEER
When using the C # program, use the following methods to start and stop Pro/ENGINEER.
Method Introduction:
- Ccpfcasyncconnection. Start ()
- Ipfcasyncconnection. End ()
A c # program can be generated and connected to a Pro/ENGINEER process through the CcpfcAsyncConnection. Start () method. Once the method returns an asynchronous connection object, the C # program can use the corresponding API to call the Pro/ENGINEER process. In interactive mode, when it runs, you can also access Pro/ENGINEER sessions on your computer.
This program will not be terminated when the Pro/ENGINEER is terminated. It is useful when the program only requires temporary Pro/ENGINEER Operations. Therefore, you must start and stop Pro/ENGINEER more than once in a session.
At any time, only one Pro/ENGINEER session can be started or connected. If the C # program generates a Second Session, the connection to the first session will be lost.
Call IpfcAsyncConnection. End () to terminate the Pro/ENGINEER process connected to any program.
Create a non-interactive session
You can generate a Pro/ENGINEER session with no interaction or graphics. In asynchronous mode, the Pro/ENGINEER Start/connection string that calls CcpfcAsyncConnection. Start () contains the following strings:
- -G: no_graphics -- disable graphical display;
- -I: rpc_input -- as a result, Pro/ENGINEER only expects input from your asynchronous program.Ote note:
These parameters are required, but the order is not important.
The syntax for calling a non-interactive, non-graphic session is as follows:
IpfcAsyncConnection aC;
CcpfcAsyncConnection ccAC = new CcpfcAsyncConnection ();
AC = ccAC. Start ("<pro>-g: no_graphics-I: rpc_input", <text_dir> );
Here, <pro> is the command to start Pro/ENGINEER and <text_dir> is the working directory.
Visual C #2008 sample code
This example demonstrates C #. Method: Start Pro/ENGINEER asynchronously, load a session, and open a model in Pro/ENGINEER.
Using pfcls;
Public class pfcAsynchronousModeExamples
{
Public void runProE (string exePath, string workDir)
/*
First parameter: Path of the Command executed by Pro/ENGINEER
Line options:-I and-g tags enable Pro/ENGINEER to run in no-graphics, no interaction mode
The second parameter is the string path of the menu and message file.
*/
{
IpfcAsyncConnection asyncConnection = null;
CCpfcAsyncConnection cAC = null;
Fcipbasesession;
Try
{
CAC = new CCpfcAsyncConnection ();
AsyncConnection = cAC. Start (exePath + "-g: no_graphics-I: rpc_input ",".");
Session = asyncConnection. Session as IpfcBaseSession;
// Set the working directory
Session. ChangeDirectory (workDir );
// C # process invocation and other processes to be performed
Fcipmodeldescriptor descModel;
Fcipmodel model;
// Load the "prt0001.prt" file in the working directory
DescModel = (new CCpfcModelDescriptor (). Create (int) EpfcModelType. EpfcMDL_PART, "prt0001.prt", null );
Model = session. RetrieveModel (descModel );
}
Catch (Exception ex)
{
MessageBox. Show (ex. Message. ToString ());
}
// When the process is completed, end the Pro/ENGINEER session
Finally
{
If (asyncconnection! = NULL)
If (asyncconnection. isrunning ())
Asyncconnection. End ();
}
}
}
Connect to the Pro/ENGINEER Process
Methods introduced:
Method Introduction:
- Ccpfcasyncconnection. Connect ()
- Ccpfcasyncconnection. connectws ()
- Ccpfcasyncconnection. getactiveconnection ()
- Ipfcasyncconnection. Disconnect ()
A simple asynchronous program can also be connected to a pro/engineer process that is already running on a local machine. The ccpfcasyncconnection. Connect () method executes this connection. If multiple Pro/ENGINEER sessions run, ccpfcasyncconnection. Connect () fails.
If several versions of Pro/Engineer run on the same machine, try to connect by specifying the user and display parameters. However, if several versions of Pro/Engineer run in the same user and display parameters, they may not be connected.
Ccpfcasyncconnection. connectws () connects Pro/Engineer with Pro/intralink3.x.
CCpfcAsyncConnection. GetActiveConnectionReturns the current connection to the Pro/Engineer session.
To remove the connection from the Pro/ENGINEER process, callIpfcAsyncConnection. Disconnect ()Method.
Connect by Connection Id
Method Introduction:
- Ipfcasyncconnection. getconnectionid ()
- Fcipconnectionid. externalrep
- Ccpfcconnectionid. Create ()
- Ccpfcasyncconnection. connectbyid ()
Each Pro/ENGINEER Process manages a unique identifier for a communication purpose. This ID can be used to reconnect to a Pro/Engineer process.
IpfcAsyncConnection. GetConnectionId ()Method returns a data structure containing the connection ID.
If the connection ID must be passed to another program,Fcipconnectionid. ExternalRepProvides external string representation of the connection Id.
Ccpfcconnectionid. Create ()Method to input a string to createConnectionidData Object.Ccpfcasyncconnection. connectbyid ()Method: connect to Pro/ENGINEER by specifying the connection Id.
Note:
The connection Id of each Pro/ENGINEER process is unique and will not be maintained once the Pro/ENGINEER exits.
Status of the Pro/Engineer Process
Method Introduction:
- Ipfcasyncconnection. isrunning ()
To detect whether a Pro/ENGINEER process is running, usePfcasyncconnectionasyncconnection. isrunning.
Get Session Object
Method Introduction:
- Ipfcasyncconnection. Session
Ipfcasyncconnection. SessionMethod returns the session object that represents the Pro/ENGINEER session. Use this object to access the content of the Pro/ENGINEER session. For more information, see the session object section.