Distributive Systems

Querying Properties and Object ID


This use case is intended to show you how to access properties and ID data using a macro.

This macro opens the document CAAPspEduIn.CATProduct. Using the root node of the document, it obtains a physical object. It then gets PspID and PspAttribute interface handle on the physical object to obtain ID and attribute information.

CAAPspQueryProperties is launched in CATIA [1]. No open document is needed.

CAAPspQueryProperties.CATScript is located in the CAAScdPspUseCases module. Execute macro (windows only).

CAAPspQueryProperties includes the following steps:

  1. Prolog
  2. Get a PspID Object
  3. Query ID Information
  4. Get PspAttribute object
  5. Get List of Attributes
  6. Get Attribute Information
  7. Get Attribute Values Depending on Types

Prolog

The macro first loads Distributive System document CAAPspEduIn.CATProduct containing Equipment and Piping Design objects.

Note: To open a different document, modify the variable sDocPath to point to the directory and sDocFullPath to point to full path name of the document.

    ...
    ' ------------------------------------------------------------------------- 
    ' Open the Distributive system document 
    Dim objPspDoc As Document
    
	sDocFullPath = CATIA.FileSystem.ConcatenatePaths(sDocPath, _    
       "\online\CAAScdPspUseCases\samples\CAAPspEduIn.CATProduct" )

    Set objPspDoc = CATIA.Documents.Open(sDocFullPath)
    ...

Next, the macro acquires the PspWorkbench object from the document using the top node of the object tree in a Distributive System document

    ...
    ' ---------------
    '  Find the top node of the Distribute System object tree - .
    
    If ( Not ( objPspDoc Is Nothing ) ) Then
      Set objPrdRoot = objPspDoc.Product 
      If ( Not ( objPrdRoot Is Nothing ) ) Then
        Set objPspWorkbench = objPrdRoot.GetTechnologicalObject ("PspWorkbench")
      End If
    End If
    ...

Next, the macro acquires the PspApplication object corresponding to Piping application and initializes the data.

    ...
    If ( Not ( objPspWorkbench Is Nothing ) ) Then
      Set objPspApplication = objPspWorkbench.GetApplication(catPspIDLCATPiping)

      If ( Not(objPspApplication Is Nothing ) ) Then
        objPspApplication.Initialization()             
      End If
    ...

Next, the macro acquires the PspAppFactory object on the application object.

    ...
    If ( Not ( objPspWorkbench Is Nothing ) And _
         Not ( objPspApplication Is Nothing ) ) Then
                        
      Set objPspAppFactory = objPspWorkbench.GetInterface("CATIAPspAppFactory",objPspApplication )
    ...

Get a PspID Object

Using the ListPhysicals method of PspAppFactory it obtains a list of physical objects in the Piping domain under the root product. Note that the output of this method is a list of objects. The member of this list can be retrieved using the Item method. The second argument of this method specifies a particular interface to be returned on this object.

It then uses the first physical object and obtains a PspID interface handle on the object.

    ...
        Set objLPhysicals = objPspAppFactory.ListPhysicals ( objPrdRoot , catPspIDLCATPIP)
        If ( Not ( objLPhysicals Is Nothing ) And _
           ( objLPhysicals.Count > 0 ) ) Then      
          Set objPspPhysical =  objLPhysicals.Item( 1, "CATIAPspPhysical" )
        End If
      End If

    End If '--- If ( Not ( objPspWorkbench Is Nothing ) and objPspApplication
    
    '-----------------------------------------------------------------------
    ' Get PspID object and query ID information
    '-----------------------------------------------------------------------

    If ( Not ( objPspWorkbench Is Nothing ) And _
         Not ( objPspPhysical Is Nothing ) ) Then  
      Set objPspID = objPspWorkbench.GetInterface("CATIAPspID",objPspPhysical )
    ...

Query ID Information

It then calls local Subroutine QueryPspID to query ID information.

    ...
     If( Not ( objPspID Is Nothing )) Then
        QueryPspID objPspID
      End if
    ...

The PspID interface is used to obtain the following information:

  • Get current IDby calling GetID method
  • Set a new ID by calling SetID method
  • Generate ID without regenerating a new sequence number but retaining the current sequence number, if it exists. This attained using the method GenIDNoGenSeqNum
  • Generate ID with a new sequence number (it it exists) and store IDby calling GenAndPutID
  • Check if current ID of the object is generated as per the ID schema by calling method IsIDGenerated
    ...
    Private Sub QueryPspID (objPspIDArg As PspID)  
    Dim strID            As String 
    Dim str2ID           As String     
    Dim strGenIDNoSeq    As String     
    Dim strGenAndPutID   As String     
    Dim strNewID         As String     
    Dim bIsIDGenerated   As Boolean

    strMessage_g =  strMessage_g & _
      "     --------Display ID information -----    " & vbCrLf
    
    If ( Not ( objPspIDArg Is Nothing ) ) Then         
      strID = objPspIDArg.GetID
      strMessage_g = strMessage_g &  "Object ID =" & strID & vbCr
      
      strNewID = strID & "NewID"

      objPspIDArg.SetID strNewID

      str2ID = objPspIDArg.GetID
      strMessage_g = strMessage_g &  "New ID set =" & str2ID & vbCr

      '----------------------------------------------------------
      ' Generate ID without regenerating sequence num
      '----------------------------------------------------------

      strGenIDNoSeq = objPspIDArg.GenIDNoGenSeqNum

      '----------------------------------------------------------
      ' Generate and Put ID on the object
      '----------------------------------------------------------

      strGenAndPutID = objPspIDArg.GenAndPutID

      strMessage_g = strMessage_g &  "Generated ID =" & strGenAndPutID & vbCr                       
     
      '----------------------------------------------------------
      ' Is ID generated
      '----------------------------------------------------------
    
      bIsIDGenerated = objPspIDArg.IsIDGenerated
      If ( bIsIDGenerated   ) Then
    ...

Get a PspAttribute Object

It then calls GetInterface method on PspWorkbench on the physical object to get a PspAttribute interface handle.

    ...
      If ( Not ( objPspWorkbench Is Nothing ) And _
         Not ( objPspPhysical Is Nothing ) ) Then  
        
      Set objPspAttribute = objPspWorkbench.GetInterface("CATIAPspAttribute",objPspPhysical )
    ...

Get List of Attributes

The macros calls ListAttributes on the PspAttribute object to get a list of attribute Piping domain. It then calls local private subroutine QueryPspAttribute to query information on each attribute.

    ...
        '----------------------------------------------------------------------
        ' List Attributes for CATPIP domain
        '----------------------------------------------------------------------
        
        Set objLStrAttrNames= objPspAttribute.ListAttributes (ePspIDLDomainID )
       
        If ( Not ( objLStrAttrNames Is Nothing ) ) Then   
          intNbAttr = objLStrAttrNames.Count
          If ( intNbAttr > 0 ) Then
            QueryPspAttribute objPspWorkbench, objPspAttribute, objLStrAttrNames  
    ...

Get Attribute Information

The macro uses local private subroutine QueryPspAttribute to obtain additional information for each of the attribute

  • Attribute type
  • Discrete type of the attribute.
  • Derived status of an attribute i.e whether attribute is deriving attribute from a logical line
    ...
Private Sub QueryPspAttribute (objPspWorkbenchArg As PspWorkbench, _
                               objPspAttributeArg As PspAttribute, _
                               objLStrAttrNamesArg As PspListOfBSTRs )  
    ...
      For intIdx = 1 To intNbAttr      
        strAttrName = objLStrAttrNamesArg.Item (intIdx)

        '-----------------------------------------------------
        ' Getting type, Discrete, Derived status of the attribute
        '-------------------------------------------------------

        eAttrDataType = objPspAttributeArg.GetType    (strAttrName)
        iDiscreteType = objPspAttributeArg.IsDiscrete (strAttrName, bIsDiscrete)
        bIsDerived    = objPspAttributeArg.IsDerived  (strAttrName)
    ...

Get Attribute Values Depending on Types

To get value of each attribute it calls method GetParameter to get CATIAParameter or its derived objects . To get value of an attribute in string format use method ValueAsString method on CATIAParameter object. To get attribute value that could be double integer, or boolean use derived objects like CATIAIntParam, CATIARealParam and CATIABoolParam respectively.

     ...
       If ( (eAttrDataType = catPspIDLInteger ) Or _            
            (eAttrDataType = catPspIDLString ) Or _ 
            (eAttrDataType = catPspIDLBoolean ) ) Then

          Set objAttrParam = objPspAttributeArg.GetParameter (strAttrName)
          If ( Not( objAttrParam Is Nothing) ) Then
            strAttrValue = objAttrParam.ValueAsString
     ...

For real type attribute that have a unit, use GetInterface method of PspWorkbench object on the Parameter object to get a handle on CATIADimension object.

It calls property Unit on CATIADimension object to get CATIUnit interface object.

    ...          
        '-------------------------------------------------
        ' Handling Real (Double) attribute
        ' Some attribute could be with magnitude and unit

        If( (eAttrDataType = catPspIDLDouble ) ) Then
          Set objAttrRealParam = objPspAttributeArg.GetParameter (strAttrName)

          If ( Not( objAttrRealParam Is Nothing) ) Then
            ' -------------------------------------
            ' Checking if CATIADimension handle
            ' can be obtained from Real parameter
            Set objAttrDimensionParam = objPspWorkbenchArg.GetInterface( _
                                    "CATIADimension",objAttrRealParam )
    ...
          ' ---------------------------------------------
          ' Getting Unit handler from the Dimension object
          ' ----------------------------------------------

          If ( Not( objAttrDimensionParam Is Nothing) ) Then
            Set objAttrUnit = objAttrDimensionParam.Unit
    ...

It obtains symbol of the unit used call property Symbol on CATIUnit interface object.

    ...
       If ( Not( objAttrUnit Is Nothing) ) Then
            strMessage_g = strMessage_g &  " , unit = " & objAttrUnit.Symbol
          End If 
    ...

[Top]


In Short

This use case shows how to obtain ID and properties information on a object in an existing document. A message logging the status of the critical steps is displayed at the end of the use case.

[Top]


References

[1] Replaying a macro
[Top]

Copyright © 2004, Dassault Systèmes. All rights reserved.