Code:
Public Sub Initialise()
Try
addTerminationListener()
addMenuAndButton()
'clsCreo.asyncConnection.WaitForEvents()
Catch ex As Exception
clslog.addErrorException(ex, MethodInfo.GetCurrentMethod().DeclaringType.Name)
Finally
'If Not clsCreo.asyncConnection Is Nothing AndAlso clsCreo.asyncConnection.IsRunning Then
' clsCreo.asyncConnection.End()
'End If End Try
End Sub
'======================================================================
'Function : addTerminationListener
'Purpose : This function adds termination listener to the Creo
' Parametric session.
'======================================================================
Private Sub addTerminationListener()
Dim terminationListener As New ProEExitListener()
Try
clsCreo.asyncConnection.AddActionListener(terminationListener)
Catch ex As Exception
MsgBox(ex.Message.ToString + Chr(13) + ex.StackTrace.ToString)
End Try
End Sub
'======================================================================
'Class : ProEExitListener
'Purpose : This class must implement the listner interface along
' with the correct client interface name. The OnTerminate
' function is called when the Creo Parametric session is
' ended by the user.
'======================================================================
Private Class ProEExitListener
Implements IpfcAsyncActionListener
Implements ICIPClientObject
Implements IpfcActionListener
Public Function GetClientInterfaceName() As String Implements pfcls.ICIPClientObject.GetClientInterfaceName
GetClientInterfaceName = "IpfcAsyncActionListener"
End Function
Public Sub OnTerminate(ByVal _Status As Integer) Implements pfcls.IpfcAsyncActionListener.OnTerminate
Dim aC As pfcls.IpfcAsyncConnection
aC = (New CCpfcAsyncConnection).GetActiveConnection
aC.InterruptEventProcessing()
MsgBox("ProE Exited")
End Sub
End Class
'======================================================================
'Function : addMenuAndButton
'Purpose : This function demonstrates the usage of UI functions to
' add a new menu and button to Creo Parametric.
'======================================================================
Private Sub addMenuAndButton()
Dim session As pfcls.IpfcSession
Dim inputCommand As IpfcUICommand
Dim buttonListener2 As IpfcUICommandActionListener
Dim exitCommand As IpfcUICommand
Dim eListener As IpfcUICommandActionListener
Try
session = clsCreo.asyncConnection.Session
buttonListener2 = New ButtonListener()
eListener = New ExitListener()
'======================================================================
'Command is created which will be associated with the button. The class
'implementing the actionlistener must be given as input.
'======================================================================
inputCommand = session.UICreateCommand("INPUT", buttonListener2)
exitCommand = session.UICreateCommand("EXIT", eListener)
'======================================================================
'Menu is created and buttons are created in the menu
'======================================================================
session.UIAddMenu("VB-Async", "Windows", "pfcAsynchronousModeExamples.txt", Nothing)
session.UIAddButton(exitCommand, "VB-Async", Nothing,
"USER Exit Listener", "USER Exit Help", "pfcAsynchronousModeExamples.txt")
session.UIAddButton(inputCommand, "VB-Async", Nothing,
"USER Async App", "USER Async Help", "pfcAsynchronousModeExamples.txt")
inputCommand.SetIcon("test.png")
Catch ex As Exception
clslog.addErrorException(ex, MethodInfo.GetCurrentMethod().DeclaringType.Name)
End Try
End Sub
'======================================================================
'Class : ButtonListener
'Purpose : This class must implement the listner interface along
' with the correct client interface name. The OnCommand
' function is called when the user button is pressed.
'======================================================================
Private Class ButtonListener
Implements pfcls.IpfcUICommandActionListener
Implements ICIPClientObject
Public Function GetClientInterfaceName() As String _
Implements ICIPClientObject.GetClientInterfaceName
GetClientInterfaceName = "IpfcUICommandActionListener"
End Function
Public Sub OnCommand() Implements pfcls.IpfcUICommandActionListener.OnCommand
Me.UserFunction()
End Sub
Public Sub UserFunction()
Application.DoEvents()
'clsCreoLayout.new_Command(eCreoCommand.Export_BOM_ULY)
End Sub
End Class
'======================================================================
'Class : ExitListener
'Purpose : This class must implement the listner interface along
' with the correct client interface name. The OnCommand
' function is called when the user button is pressed to
' exit the session listener.
'======================================================================
Private Class ExitListener
Implements pfcls.IpfcUICommandActionListener
Implements ICIPClientObject
Public Function GetClientInterfaceName() As String _
Implements ICIPClientObject.GetClientInterfaceName
GetClientInterfaceName = "IpfcUICommandActionListener"
End Function
Public Sub OnCommand() Implements pfcls.IpfcUICommandActionListener.OnCommand
Me.UserFunction()
End Sub
Public Sub UserFunction()
Dim aC As pfcls.IpfcAsyncConnection
aC = (New CCpfcAsyncConnection).GetActiveConnection
aC.InterruptEventProcessing()
MsgBox("Listener Exited")
End Sub
End Class