Browsing Product contents(3DExperience CATIA)

'---------------------------------------------------------------------------------------------------------------------------
'COPYRIGHT DASSAULT SYSTEMES 2009
'---------------------------------------------------------------------------------------------------------------------------
'Browsing Product Model (Reference/instance Model) Contents
'Mission:   This use case fundamentally illustrates navigation of the Product Structure Model.
'           Use case navigates down the hierarchy of an Product Reference-Instance Model associated with
'           a Product Root Reference loaded in session. And displays the entire hierarchy in a tree format,
'           as viewed in the Specification Tree within CATIA, but with the Representation Instances/References.
'
'Steps:     1- Searches for a Product in database
'           2- Opens the Product and retrieves its Editor
'           3- Navigates the Product Reference recursively
'              3.1- Retrieves the Root Product Occurrence from the current VPM Editor to navigate
'              3.2- Retrieves the Root Reference from the occurrence model
'              3.3- Navigates the Product Reference
'                   3.3.1- Retrieves the Rep Instances under the Product Reference
'                   3.3.2- Retrieves the list of Instances within the input Reference
'                   3.3.3- Navigates through each child Reference recursively

'

'---------------------------------------------------------------------------------------------------------------------------

' Be careful: this piece of code has been written with a specific Product Reference type (VPMReference). If your ENOVIA

' installation does not contain this Product Modele type, use you own Product Reference type.

' You have just to change the contents of the strTheProductReferenceType variable defined just below.

'---------------------------------------------------------------------------------------------------------------------------

'

Dim strTheProductReferenceType As String



'
'Global variable to gather and display at the end the PLM Component Identification Set attributes
Dim strBrowsedPLMCompIDAttr As String
'
'==========================================================================================================================
' Main Routine
'==========================================================================================================================
Sub BrowseProductModel()
    'Error handling
    On Error GoTo ErrorSub
    strTheProductReferenceType = "VPMReference"

    '1- Retrieves the Search service from CATIA session
    Dim oSearchService As SearchService
    Set oSearchService = CATIA.GetSessionService("Search")

    '2- Searches for a Product in database
    Dim oDBSearch As DatabaseSearch
    Set oDBSearch = SearchProduct(oSearchService)
    
    '2- Opens the Product and retrieves its Editor
    Dim oProductEditor As Editor
    Set oProductEditor = OpenProductAndGetEditor(oDBSearch)
    
    '3- Navigates the Product Structure
    NavigateProductStructure oProductEditor
    
    'Error handling
    GoTo EndSub
ErrorSub:
    MsgBox Err.Description
EndSub:
End Sub
'
'--------------------------------------------------------------------------------------------
' 1- Searches for a Product in database
'    The search criteria is:
'     - The Product reference type
'     - A PLM_ExternalID value entered by the end user
'     - A revision value entered by the end user
'    Output  : the object containing the result of the search
'--------------------------------------------------------------------------------------------
'
Function SearchProduct(oSearchService) As DatabaseSearch
   'Error handling
    On Error GoTo ErrorSub
    
    '1- Retrieves the Database attribute from Search service
    Dim oDBSearch As DatabaseSearch
    Set oDBSearch = oSearchService.DatabaseSearch
     
    'Builds the Query criteria for Search on underlying database
    'Prompts the user to input the PLM_ExternalID for search purpose
    Dim strInputPLMIDName As String
    strInputPLMIDName = InputBox("Please enter the PLM_ExternalID to search", "Enter PLM_ExternalID")
    
    'Prompts the user to input the revision for search purpose
    Dim strInputRevision As String
    strInputRevision = InputBox("Please enter the revision to search", "Enter revision")
 
    'Sets the type of objects to search for
    oDBSearch.BaseType = strTheProductReferenceType
    
       
    'Updates the PLM Search object created in the above steps with the attribute criteria provided by the user as an input
    oDBSearch.AddEasyCriteria "PLM_ExternalID", strInputPLMIDName
    oDBSearch.AddEasyCriteria "revision", strInputRevision
       
    'Triggers the Search
    oSearchService.Search
    
    'Valuates the output
    Set SearchProduct = oDBSearch
    
    'Error handling
    GoTo EndSub
ErrorSub:
    MsgBox Err.Description
EndSub:
    
End Function
'
'--------------------------------------------------------------------------------------------
' 2- Opens the Product and retrieves its Editor
'    Input  : the object containing the result of the previous search
'    Output : the editor containing the opened Product
'--------------------------------------------------------------------------------------------
'
Function OpenProductAndGetEditor(oDBSearch) As Editor
   'Error handling
   On Error GoTo ErrorSub
    
    'Retrieves the list of PLM Entities from the PLM Search object
    Dim oPLMProdRefAsEntities As PLMEntities
    Set oPLMProdRefAsEntities = oDBSearch.Results
    
    'Ensures the search results retrieves atleast one PLM Entity
    If oPLMProdRefAsEntities.Count > 1 Then
        MsgBox "Please enter a query criteria which outputs a unique PLM Component for further processing"
        GoTo EndSub
    ElseIf oPLMProdRefAsEntities.Count = 0 Then
        MsgBox "No result for the input criteria"
        GoTo EndSub
    End If

    'Retrieves first PLM Entity from the PLMEntities collection object
    Dim oPLMProdRefAsPLMEntity As PLMEntity
    Set oPLMProdRefAsPLMEntity = oPLMProdRefAsEntities.Item(1)
    
    'Call the Open Service to open the product
    Dim oOpenService As PLMOpenService
    Set oOpenService = CATIA.GetSessionService("PLMOpenService")
    
    'Opens the PLM Component in the VPM editor
    Dim oProductEditor As Editor
    oOpenService.PLMOpen oPLMProdRefAsPLMEntity, oProductEditor
        
    'Valuates the output
    Set OpenProductAndGetEditor = oProductEditor
    
   'Error handling
    GoTo EndSub
ErrorSub:
    MsgBox Err.Description
EndSub:
End Function
'
'--------------------------------------------------------------------------------------------
'  3- Navigates the Product Structure recursively
'     Input : the Product editor
'--------------------------------------------------------------------------------------------
'
Sub NavigateProductStructure(oProductEditor)
    'Error handling
    On Error GoTo ErrorSub
    
    'Initializes the global variable
    strBrowsedPLMCompIDAttr = ""
 
    'Retrieves the Product Context from the editor
    Dim oProductService As PLMProductService
    Set oProductService = oProductEditor.GetService("PLMProductService")
        
    '3.1 - Retrieves the Root Product Occurrence from the current VPM Editor to navigate
    Dim oVPMRootOccOnRoot As VPMRootOccurrence
    Set oVPMRootOccOnRoot = oProductService.RootOccurrence
    
    '3.2- Retrieves the Root Reference from the occurrence model
    Dim oVPMRefOnRoot As VPMReference
    Set oVPMRefOnRoot = oVPMRootOccOnRoot.ReferenceRootOccurrenceOf
    
    'Displays the Root Product Reference name
    strBrowsedPLMCompIDAttr = strBrowsedPLMCompIDAttr + oVPMRefOnRoot.Name + vbCrLf
        
    '3.3- Navigates the Product Reference
    '(Call for Navigate on the retrieved Reference)
    NavigateProdReference oVPMRefOnRoot, 1
    
    'Displays the Occurrence Product Model Contents in the Message Box
    MsgBox strBrowsedPLMCompIDAttr
        
    'Clears the display contents
    strBrowsedPLMCompIDAttr = ""
        
   'Error handling
    GoTo EndSub
ErrorSub:
    MsgBox Err.Description
EndSub:
End Sub
'
'--------------------------------------------------------------------------
'3.3 Navigates the Product Reference
'    Input : the Product Reference
'            depth of the object in hierarchy
'--------------------------------------------------------------------------
Sub NavigateProdReference(oProdRef, depth)
    'Error handling
    On Error GoTo ErrorSub
    
    '3.3.1- Retrieves the Rep Instances under the Product Reference
    NavigateProdReferenceForRepInst oProdRef, depth
        
    '3.3.2- Retrieves the list of instances within the input reference
    Dim oListChildrenInstances As VPMInstances
    Set oListChildrenInstances = oProdRef.Instances
    
    '3.3.3-  Navigates through each child Reference recursively
    'Loop through the List of child instances
    For i = 1 To oListChildrenInstances.Count
    
        'Retrieves the Child instance from the list
        Dim oVPMInst As VPMInstance
        Set oVPMInst = oListChildrenInstances.Item(i)
        
        'Indent the PLM entity appropriately
        For spaceCnt = 1 To depth
            strBrowsedPLMCompIDAttr = strBrowsedPLMCompIDAttr + vbTab
        Next spaceCnt
        
         'Retrieves the Reference of the instance
        Dim oVPMRef As VPMReference
        Set oVPMRef = oVPMInst.ReferenceInstanceOf
        
        'Prepare the string for displaying purpose
        strBrowsedPLMCompIDAttr = strBrowsedPLMCompIDAttr + oVPMRef.GetAttributeValue("PLM_ExternalID") + oVPMRef.GetAttributeValue("V_version") + " " + "("
        strBrowsedPLMCompIDAttr = strBrowsedPLMCompIDAttr + oVPMInst.GetAttributeValue("PLM_ExternalID") + ")" + vbCrLf
              
        'Navigate further into this VPM Ref. A recursive call to Navigate follows
        NavigateProdReference oVPMRef, depth + 1
            
    'Next ref
    Next i
    
    'Error handling
    GoTo EndSub
ErrorSub:
    MsgBox Err.Description
EndSub:
End Sub
'
'--------------------------------------------------------------------------
'3.3.1 'Retrieve the Rep Instances under the root and display them accordingly
'    Input : the Product Reference
'            depth of the object in hierarchy
'--------------------------------------------------------------------------
Sub NavigateProdReferenceForRepInst(oProdRef, depth)
    'Error handling
    On Error GoTo ErrorSub
    
    '3.3.1.a- Retrieves the list of Rep Instances within the input reference
    Dim oVPMRepInsts As VPMRepInstances
    Set oVPMRepInsts = oProdRef.RepInstances
    
    '3.3.1.b- Navigates through each child Rep instances
    'Loop through the List of child rep instances
    For k = 1 To oVPMRepInsts.Count
    
        Dim oVPMRepInst As VPMRepInstance
        Set oVPMRepInst = oVPMRepInsts.Item(k)
        
        'If the Product reference has Rep Instances, then indent it else not required.
        For spaceCnt = 1 To depth
            strBrowsedPLMCompIDAttr = strBrowsedPLMCompIDAttr + vbTab
        Next spaceCnt
        
        'Retrieve the Rep References of the instances
        Dim oVPMRepRef As VPMRepReference
        Set oVPMRepRef = oVPMRepInst.ReferenceInstanceOf
        
        'Prepare the string for displaying purpose
        strBrowsedPLMCompIDAttr = strBrowsedPLMCompIDAttr + oVPMRepRef.GetAttributeValue("PLM_ExternalID") + oVPMRepRef.GetAttributeValue("V_version") + " " + "("
        strBrowsedPLMCompIDAttr = strBrowsedPLMCompIDAttr + oVPMRepInst.GetAttributeValue("PLM_ExternalID") + ")" + vbCrLf
            
    'Next Rep Inst
    Next k
    
    'Error handling
    GoTo EndSub
ErrorSub:
    MsgBox Err.Description
EndSub:
End Sub

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值