List out all the Creo window & activate the required window using VB API

VB API allows the user to activate the required window from multiple window in the Creo Session. Here I’m gonna explain how to achieve this using a basic WPF UI.

Collect all windows and show it into the Listbox

Follow this procedure 

In WPF application, Create a Stack panel and then add a label for heading, a button to collect windows from creo and a Listbox to show the collected windows

WPF UI to collect Creo Window
<StackPanel Orientation="Vertical" Margin="5" Width="550" Background="#FF7272D4">
	<Label Content="LIST WINDOW" Margin="5" FontFamily="Cambria" FontSize="17.333" Width="200" ></Label>
	<StackPanel Orientation="Vertical" Margin="5">
		<Button x:Name="btn_ListWindows" Content="LIST WINDOWS" FontFamily="Cambria" FontSize="17.333" Margin="5" 
				Click="btn_ListWindows_Click"></Button>
		<ListBox x:Name="lst_Windows" FontFamily="Cambria" FontSize="17.333" Margin="5" Width="450" Height="200" 
				 MouseDoubleClick="lst_Windows_MouseDoubleClick" ></ListBox>
	</StackPanel>
</StackPanel>
  • The following variables should declared before part of our code
Required Variables

' VARIABLE DECLARATION REQUIRED

Public AConnection As IpfcAsyncConnection
Public BSession As IpfcBaseSession
  • Declare the variable AConnection using Creo Connect or Creo Start functions (please refer fundamentals of VB API section)
  • Now add the Creo windows collection program to the code behind of Button click action
Collect all Creo Windows using VB API
 	Private Sub btn_ListWindows_Click(sender As Object, e As RoutedEventArgs)
        Try
            BSession = AConnection.Session
            Dim IWindows As IpfcWindows = BSession.ListWindows
            lst_Windows.Items.Clear()
            For i = 0 To IWindows.Count - 1
                Dim ListBoxItem As New ListBoxItem
                ListBoxItem.Content = IWindows.Item(i).Model.FileName.ToString
                lst_Windows.Items.Add(ListBoxItem)
            Next
        Catch ex As Exception
            MessageBox.Show(ex.ToString, "Failure")
        End Try
    End Sub
  • In the above code we are getting all the Creo windows and then we are getting the details of model opened in it
  • Using the model name we are listing out window name into our application list box
  • Now add this code to List box items double click action
Activate the window by ListBox item double click action
    Private Sub lst_Windows_MouseDoubleClick(sender As Object, e As MouseButtonEventArgs)
        Try
            BSession = AConnection.Session
            Dim SelectedListBoxItem As ListBoxItem = lst_Windows.SelectedItem
            Dim ItemName As String = SelectedListBoxItem.Content
            Dim IWindows As IpfcWindows = BSession.ListWindows
            For i = 0 To IWindows.Count - 1
                If IWindows.Item(i).Model.FileName.ToString = ItemName Then
                    IWindows.Item(i).Activate()
                End If
            Next

        Catch ex As Exception
            MessageBox.Show(ex.ToString, "Failure")
        End Try
    End Sub
  • In the above code using the Listbox selected item name, I’ve activated the Creo window

That’s all, Now the user can able to get all the windows in List box by clicking the List windows button and can activate the required window by double clicking the List box items.

Thanks & Regards

Parthiban Kannan

Follow me on LinkedIn!

 

Share Now
  • 1
  •  
  •  
  •  
  •  
  •  
    1
    Share

Leave a Reply