Distributive Systems

Placing a Physical Part


This use case is intended to show you how to place a physical part from a reference part.

This macro opens the document CAAPspEduIn.CATProduct. Using the root node of the document, it then finds a piping valve and uses its reference to place another valve.

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

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

CAAPspPlacePart includes the following steps:

  1. Setup Environment
  2. Get Data for Part Placement
  3. Place Part
  4. View and Test Part Data

Setup Environment

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.

    ...
    ' ------------------------------------------------------------------------- 
    ' Setup the Environment
    ' ------------------------------------------------------------------------- 
    ' Open the Distributive system document 
    dim sDocPath As String 
    dim sDocFullPath As String 
    sDocPath=CATIA.SystemService.Environ("CATDocView")
    If (Not CATIA.FileSystem.FolderExists(sDocPath)) Then
      Err.Raise 9999,sDocPath,"No Doc Path Defined"
    End If

    sDocFullPath = CATIA.FileSystem.ConcatenatePaths(sDocPath, _    
       "online\CAAScdPspUseCases\samples\CAAPspEduIn.CATProduct" )

    
    Set gObjPspDoc = CATIA.Documents.Open(sDocFullPath)
    If (gObjPspDoc Is Nothing) Then
      Err.Raise 9999,sDocPath,"No Document Open"
    End If

    ShowTraceOutputLine "Output traces from CAAPspPlacePart.CATScript"
    ...

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

    ...
    ' Find the top node of the Distributive System object tree - .  
    Set gObjPrdRoot = gObjPspDoc.Product 
    If (gObjPrdRoot Is Nothing) Then
      Err.Raise 9999,sDocPath,"Unable to get root product object"
    End If
    
    Set gObjPspWorkbench = gObjPrdRoot.GetTechnologicalObject ("PspWorkbench")
    If (gObjPspWorkbench Is Nothing) Then
      Err.Raise 9999,sDocPath,"Unable to get PspWorkbench"
    End If
    ShowTraceOutputLine "Success in getting PspWorkbench"

    Set gObjRootProduct = gObjPspWorkbench.GetInterface("CATIAProduct", gObjPrdRoot )      
    If (gObjRootProduct Is Nothing) Then
      Err.Raise 9999,sDocPath,"Unable to get root product"
    End If
    ...

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

    ...
    ' Get Application
    Set objPspApplication = gObjPspWorkbench.GetApplication(catPspIDLCATPiping)
    If (objPspApplication Is Nothing) Then
      Err.Raise 9999,sDocPath,"Unable to get PspApplication"
    End If
    ShowTraceOutputLine "Success in getthing objPspApplication"
    objPspApplication.Initialization()             
    ...

Get Data for Part Placement

The first data the macro acquires for part placement is a PspTempListFactory object gObjListFactory on the application object. This is used to later generate lists of real values needed for part placement input

    ...
    '-----------------------------------------------------------------------
    ' Get Data for Part Placement
    '-----------------------------------------------------------------------
    ' Get gObjListFactory
    Set gObjListFactory = gObjPspWorkbench.GetInterface("CATIAPspTempListFactory", objPspApplication )      
    If (gObjListFactory Is Nothing) Then
      Err.Raise 9999,sDocPath,"Unable to get list factory"
    End If
        ...

Next, the macro uses the root product object gObjRootProduct to find a parent for the part to be placed.

    ...
    ' Get root product children and parent product for placed part
    Dim ParentProductRef As CATIABase
    Set ParentProductRef = Nothing
    Dim ParentProduct As Product
    Set ParentProduct = Nothing
    ShowTraceOutputLine "Number of root children = " & gObjRootProduct.Products.Count
    Dim Prod As CATIABase
    For Each Prod in gObjRootProduct.Products
      ShowTraceOutputLine "Root child product name = " & Prod.Name
      If (Prod.Name = "CAAPsp3DEduIn.1") Then 
        Set ParentProductRef = gObjPspWorkbench.GetInterface("CATIABase", Prod )      
        Set ParentProduct = gObjPspWorkbench.GetInterface("CATIAProduct", Prod )      
      End If
    Next
    If (ParentProductRef Is Nothing Or ParentProduct Is Nothing) Then
      Err.Raise 9999,sDocPath,"Unable to get parent product"
    End If
    ShowTraceOutputLine "Part place parent product name = " & ParentProductRef.Name
     ...

Now the PspAppFactory object objPspAppFactory is used to search for a physical product that will serve as a reference for the part to be placed. In this case it finds a piping valve.

    ...
    ' Get PspPhysicalProduct object
    Dim objLPhysicals     As PspListOfObjects                  
    Set objPspAppFactory = gObjPspWorkbench.GetInterface("CATIAPspAppFactory", objPspApplication )      
  
    Set objLPhysicals = objPspAppFactory.ListPhysicals ( gObjPrdRoot , catPspIDLCATPIP)
    If ( Not ( objLPhysicals Is Nothing ) And _
        ( objLPhysicals.Count > 0 ) ) Then      
      Set objPspPhysicalPrd =  objLPhysicals.Item( 1, "CATIAPspPhysicalProduct" )
    End If
    If (objPspPhysicalPrd Is Nothing) Then
      Err.Raise 9999,sDocPath,"Unable to get physcial part for reference product input"
    End If
    ShowObjectID "Physical Product object", objPspPhysicalPrd
    ...

Now the reference of the physical part (the valve) is found. A reference is needed as input to the part placement method.

    ...
    ' Get object reference part and parent.
    Dim objPhysicalProduct As Product
    Dim objReferenceProduct As Product
    Dim objParentProduct As Product
    Set objPhysicalProduct = gObjPspWorkbench.GetInterface("CATIAProduct", objPspPhysicalPrd )      
  
    If ( Not (objPhysicalProduct Is Nothing) ) Then
      Set objReferenceProduct = objPhysicalProduct.ReferenceProduct

      'Just for info: got parent for part place above.
      Set objParentProduct = objPhysicalProduct.Parent
      If (Not (objParentProduct Is Nothing)) Then
        ShowTraceOutputLine "Parent part name = " & objParentProduct.Name
      End If
    End If 
    If (objReferenceProduct Is Nothing) Then
      Err.Raise 9999,sDocPath,"Unable to get reference product input"
    End If
    ShowTraceOutputLine "Reference part number = " & objReferenceProduct.PartNumber
    ShowObjectID "Reference Product object", objReferenceProduct
    ...

The next piece of data needed is a logical line to contain the placed part. The macro uses the logical line that contains the valve already in the model. Note that the physical part can be in many groups: the code must filter for the group which is a logical line.

    ...
    ' Get logical line
    Dim LogicalLine As PspLogicalLine
    Set LogicalLine = Nothing
    Dim PhysicalProductGroupable As PspGroupable
    Set PhysicalProductGroupable = Nothing
    Set PhysicalProductGroupable = gObjPspWorkbench.GetInterface("CATIAPspGroupable", objPspPhysicalPrd )      
    If ( Not ( PhysicalProductGroupable Is Nothing ) ) Then
      ShowTraceOutputLine "Number of groups = " & PhysicalProductGroupable.Groups.Count
      Dim iiGroup As Integer
      For iiGroup = 1 to PhysicalProductGroupable.Groups.Count
        Dim Group As CATIABase
        Set Group = PhysicalProductGroupable.Groups.Item(iiGroup, "CATIABase")
        ShowTraceOutputLine "Group name = " & Group.Name
        Set LogicalLine = gObjPspWorkbench.GetInterface("CATIAPspLogicalLine", Group ) 
        If ( Not ( LogicalLine Is Nothing ) ) Then
          ShowTraceOutputLine "Part place logical line name = " & LogicalLine.Name
          Exit For
        End If
      Next
    End If
    ...

Place Part

Now enough data has been gathered to place the part. The placement is done by calling the PlacePartInSpace method on the objPlacePart object. Before PlacePartInSpace is called a few input argument values are set. Standard is set to specify the standard to be used in the placement. The function type to assciate with the placed part is specified by FunctionType. UpDirection, HorizontalOrientation and Position are set to properly position and orient the part. These are all taken by the PlacePartInSpace method as relative to the parent product.

    ...
    '-----------------------------------------------------------------------
    ' Place Part
    '-----------------------------------------------------------------------
    Dim Standard As String
    Standard = "ASTL"
    Dim FunctionType As String
    FunctionType = "CATPspValveFunction"
    Dim PlacedPartID As String
    PlacedPartID = "" 'Null string uses name generated by PP engine
    ' Up direction for part = (0,0,1)
    Dim UpDirection As PspListOfDoubles
    Set UpDirection = gObjListFactory.CreateListOfDoubles()
    UpDirection.Append 0.0 'Align vertical parallel to z-axis.
    UpDirection.Append 0.0
    UpDirection.Append 1.0
    ' Horizontal alignment for part = (1,0,0)
    Dim HorizontalOrientation As PspListOfDoubles
    Set HorizontalOrientation = gObjListFactory.CreateListOfDoubles()
    HorizontalOrientation.Append 1.0 'Align horizontal parallel to x-axis.
    HorizontalOrientation.Append 0.0
    HorizontalOrientation.Append 0.0
    ' Part position = (1000,2000,4000) (mm)
    Dim Position As PspListOfDoubles
    Set Position = gObjListFactory.CreateListOfDoubles()
    Position.Append 1000.0 'Position part at (1000, 2000, 3000)
    Position.Append 2000.0
    Position.Append 4000.0
    Dim PlacePartRef As CATIABase
    Set PlacePartRef = Nothing
    Dim objPlacePart As PspPlacePart                  
    Set objPlacePart = Nothing
    Set objPlacePart = gObjPspWorkbench.GetInterface("CATIAPspPlacePart", objPspApplication )      
    If ( Not ( objPlacePart Is Nothing ) ) Then      
      Set PlacePartRef = objPlacePart.PlacePartInSpace(Standard, _
                                                       FunctionType, _
                                                       objReferenceProduct, _
                                                       ParentProductRef, _
                                                       LogicalLine, _
                                                       PlacedPartID, _
                                                       UpDirection, _
                                                       HorizontalOrientation, _
                                                       Position)
    End If
    If ( PlacePartRef Is Nothing ) Then      
      Err.Raise 9999,sDocPath,"Place part error = " & objPlacePart.ErrorMessage
    Else
      ShowObjectID "Placed part", PlacePartRef
    End If
    ...

View and Test Part Data

After the part is placed, the script test and displays some data related to the placed part. First the position of the part itself is examined.

  ...
    '-----------------------------------------------------------------------
    ' View and Test Part Data
    '-----------------------------------------------------------------------
    ' Placed part position
    Dim objPlacePartProduct As Product
    'Set objPlacePartProduct = PlacePartRef
    Set objPlacePartProduct = gObjPspWorkbench.GetInterface("CATIAProduct", PlacePartRef )      
    If ( objPlacePartProduct Is Nothing ) Then      
      Err.Raise 9999,sDocPath,"Bad placed product"
    End If
    Dim placePartPositArray(12) As CATSafeArray
    objPlacePartProduct.Position.GetComponents(placePartPositArray)
    ShowTraceOutputLine "Product posit = " & DumpTransform(placePartPositArray)
   ...   

Finally data associated with the part connectors of the part is tested and displayed.

  ...
    ' Placed part connectors
    Dim objPlacePartPhysical As CATIAPspPhysicalProduct                  
    Set objPlacePartPhysical = Nothing
    Set objPlacePartPhysical = gObjPspWorkbench.GetInterface("CATIAPspPhysicalProduct", PlacePartRef )      
    If ( Not ( objPlacePartPhysical Is Nothing ) ) Then
      ShowTraceOutputLine "Number of connectors = " & objPlacePartPhysical.Connectors.Count
      If ( objPlacePartPhysical.Connectors.Count <> 2 ) Then      
        Err.Raise 9999,sDocPath,"Wrong number of connectors"
      End If
      Dim iiCtr As Integer
      For iiCtr = 1 to objPlacePartPhysical.Connectors.Count
        ShowTraceOutputLine "iiCtr = " & iiCtr
        Dim Ctr As PspPartConnector
        Set Ctr = objPlacePartPhysical.Connectors.Item(iiCtr, "CATIAPspPartConnector")
        If ( Ctr Is Nothing ) Then      
          Err.Raise 9999,sDocPath,"Bad connector"
        End If
        ShowTraceOutputLine "Ctr name = " & Ctr.Name
        Dim CtrPosit As PspListOfDoubles
        Set CtrPosit = Nothing
        Set CtrPosit = Ctr.GetPosition(ParentProduct)
        ShowTraceOutputLine "Ctr posit = " & DumpVector(CtrPosit)
        Dim CtrAlign As PspListOfDoubles
        Set CtrAlign = Nothing
        Set CtrAlign = Ctr.GetAlignmentDirection(ParentProduct)
        ShowTraceOutputLine "Ctr align = " & DumpVector(CtrAlign)
        Dim CtrUp As PspListOfDoubles
        Set CtrUp = Nothing
        Set CtrUp = Ctr.GetUpDirection(ParentProduct)
        ShowTraceOutputLine "Ctr up = " & DumpVector(CtrUp)
      Next
    End If
   ...   

[Top]


In Short

This use case is intended to show you how to place a physical part. It shows how to load a model and setup the environment, how to gather necessary data and how to place the part. It also illustrates how to extract some data from the placed part.

Here is what the input model looks like.

Before Part Placed

Here is the model after the valve is placed.

After Part Placed

Here are the status messages displayed at the end of the macro execution.

Message Panel

[Top]


References

[1] Replaying a macro
[Top]

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