Handling 3D Views in Creo using VB API

Creo VB API provides the basic operations to handle the 3D model views. Here I am gonna give a simple program in WPF & VB to control views.

please add the following code to create user interface which same like as shown in the image

WPF UI Code

WPF UI - Handling Views
			<WrapPanel Orientation="Vertical" Margin="5">
                <StackPanel Orientation="Vertical" Margin="5">
                    <Label Content="VIEW OBJECTS" Margin="5" FontFamily="Cambria" FontSize="17.333"></Label>
                    <StackPanel Orientation="Vertical" Margin="5">
                        <Button x:Name="btn_RetrieveView" Click="btn_RetrieveView_Click" Content="RETRIEVE VIEW" FontFamily="Cambria" FontSize="17.333" Margin="5" ></Button>
                        <ListBox x:Name="lst_ViewNames" MouseDoubleClick="lst_ViewNames_MouseDoubleClick" FontFamily="Cambria" FontSize="17.333" Margin="5"
                                 Height="200"></ListBox>
                    </StackPanel>
                    <StackPanel Orientation="Vertical" Margin="5">
                        <StackPanel Orientation="Horizontal" Margin="5" >
                            <Label Content="VIEW NAME" FontFamily="Cambria" FontSize="17.333" Margin="5" Width="200"></Label>
                            <TextBox x:Name="tb_ViewName" FontFamily="Cambria" FontSize="17.333" Margin="5" Width="300"></TextBox>
                        </StackPanel>
                        <Button x:Name="btn_SaveView" FontFamily="Cambria" FontSize="17.333"  Margin="5" Content="SAVE VIEW"
                                Click="btn_SaveView_Click"></Button>
                    </StackPanel>
                    <StackPanel Orientation="Vertical" Margin="5">
                        <Button x:Name="btn_Reset" FontFamily="Cambria" FontSize="17.333" Margin="5" Content="RESET" Click="btn_Reset_Click"></Button>
                    </StackPanel>
                </StackPanel>
            </WrapPanel>

Basic declarations required

Variable declarations
' BASIC DECLARATIONS NEEDED

    Public AConnection As IpfcAsyncConnection
    Public CConnection As New CCpfcAsyncConnection
    Public BSession As IpfcBaseSession

' NOTE: AConnection should be declared at the stage of Creo Start or Creo Connection.

To List out all the views from the current model

  • The vb code used here to collect all the views from current model
  • Current model implies the model currently active in the Creo session
Retrieve 3D model Views using VB API
 Private Sub btn_RetrieveView_Click(sender As Object, e As RoutedEventArgs)
        Try
            BSession = AConnection.Session
            Dim IViewOwner As IpfcViewOwner = BSession.CurrentModel
            lst_ViewNames.Items.Clear()
            For i = 0 To IViewOwner.ListViews.Count - 1
                lst_ViewNames.Items.Add(IViewOwner.ListViews.Item(i).Name)
            Next
        Catch ex As Exception
            MessageBox.Show(ex.ToString, "Failure")
        End Try
    End Sub

To retrieve the required view in 3D model

  • Following code used to retrieve the required view from collection of views
To Retrieve the View using VB API
   Private Sub lst_ViewNames_MouseDoubleClick(sender As Object, e As MouseButtonEventArgs)
        Try
            BSession = AConnection.Session
            Dim IViewOwner As IpfcViewOwner = BSession.CurrentModel
            IViewOwner.RetrieveView(lst_ViewNames.SelectedItem)
        Catch ex As Exception
            MessageBox.Show(ex.ToString, "Failure")
        End Try
    End Sub

To Save a new view

  • User can change the 3D model view and save it from VB Application using the below code
To Save a 3D View - using VB API
    Private Sub btn_SaveView_Click(sender As Object, e As RoutedEventArgs)
        Try
            BSession = AConnection.Session
            Dim IViewOwner As IpfcViewOwner = BSession.CurrentModel
            IViewOwner.SaveView(tb_ViewName.Text)
        Catch ex As Exception
            MessageBox.Show(ex.ToString, "Failure")
        End Try
    End Sub

To Reset the View

  • The below code used the reset the view 
Reset View - using Vb API
   Private Sub btn_Reset_Click(sender As Object, e As RoutedEventArgs)
        Try
            BSession = AConnection.Session
            Dim IViewOwner As IpfcViewOwner = BSession.CurrentModel
            Dim IViews As IpfcViews = IViewOwner.ListViews

            IViewOwner.GetCurrentView().Reset()

        Catch ex As Exception
            MessageBox.Show(ex.ToString, "Failure")
        End Try
    End Sub

These are the basic operations available in Creo VB API to handle the 3D views

 

Thanks & Regards

Parthiban Kannan

Follow me in LinkedIn!

Share Now
  •  
  •  
  •  
  •  
  •  
  •  

Leave a Reply