Interactive CATIA SMARTEAM

Saving Documents in SmarTeam


This macro show you how to use the CAI automation objects to perform SMARTEAM life-cycle operations on CATIA V5 documents.

It connects to SMARTEAM, create new CATIA V5 documents, save them in SMARTEAM then put them in SMARTEAM vault.

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

CAAStiUseCase1.CATScript is located in the CAAScdStiUseCases module.  Execute macro (Windows only).

 

CAAStiUseCase1 includes ten steps:

  1. Retrieving CAIEngine object
  2. Define UI mode
  3. Connect to SMARTEAM
  4. Save a CATPart document into SMARTEAM
  5. Retrieve SMARTEAM identification of the saved CATPart document
  6. Perform Check-In operation on the CATPart document
  7. Retrieve Checked-In CATPart document and insert it in a new CATProduct document
  8. Perform save and Release operation on the CATProduct document
  9. Reset connection status
  10. Reset UI mode as it was before

Retrieving CAIEngine object

  ...
    ' Get CAIEngine
    Dim CAIEngine As StiEngine
    Set CAIEngine = CATIA.GetItem("CAIEngine")
  ...

The entry point of the CATIA-SMARTEAM Integration, is the "SMARTEAM Integration Engine".
This object is retrieved using the GetItem method of CATIA object.

Define UI mode

  ...
    ' Decide to run without any user interaction
    Dim bUI As Boolean
    if ( CAIEngine.UseGraphicalUI ) Then
        CAIEngine.UseGraphicalUI = False
        bUI = true
    End If
  ...

CATIA-SMARTEAM Integration can operate either in an interactive way requiring user interactions (like validating various SMARTEAM dialogs) or in an non-interactive way.
By setting UseGraphicalUI property to False, we indicate that we don't want to have any user interaction during the execution of this script.

Connect to SMARTEAM

  ...
    ' Connect to the database (if not already connected)
    Dim bConnect As Boolean
    bConnect = false
    If Not CAIEngine.IsConnected() Then
        CAIEngine.Connect "joe", ""
        bConnect = true
    End If
  ...

Here we check if CATIA is already connected to SMARTEAM. If CATIA is not already connect, then we connect with user "joe" and no password.

Save a CATPart document into SMARTEAM

  ...
    ' Creating new CATPart document
    Dim PartDoc As PartDocument
    Set PartDoc = CATIA.Documents.Add("Part")
     
    ' Save document in SMARTEAM
    Dim PartDocDBItem As StiDBItem
    Set PartDocDBItem = CAIEngine.GetStiDBItemFromAnyObject(PartDoc)
    CAIEngine.Save PartDocDBItem
  ...

A new CATPart document is created and saved in SMARTEAM. As we decided not to have any user interaction, the document will be saved with default values (default project and/or folder)

Retrieve SMARTEAM identification of the saved CATPart document

  ...
    ' Once saved, retrieve corresponding SMARTEAM classid & objectid
    Dim cid As Integer
    Dim oid As Integer
    cid = CAIEngine.GetSMARTEAMClassID(PartDocDBItem)
    oid = CAIEngine.GetSMARTEAMObjectID(PartDocDBItem)
  ...

As soon as the CATPart document is saved into SMARTEAM, it gets a SMARTEAM unique identification. Here we retrieve this identification to make sure we will be able to access the document later in the execution of the macro.

Perform Check-In operation on the CATPart document

  ...
    ' Perform Check-In operation on the document
    ' (this will close the document from the CATIA session and
    ' file will be removed from the disk)
    CAIEngine.LifeCycleCheckIn PartDocDBItem
  ...

We run the SMARTEAM life-cycle "Check-In" operation on the CATPart document. The document is automatically moved to the SMARTEAM "Checked-In" vault and closed from the CATIA session.

Retrieve Checked-In CATPart document and insert it in a new CATProduct document

  ...
    ' Create new Product
    Dim ProductDoc As ProductDocument
    Set ProductDoc = CATIA.Documents.Add("Product")
      
    ' Retrieve checked-in Part document from SMARTEAM database and
    ' get a local copy in the user work directory
    Dim CheckedInPartDBItem As StiDBItem
    Set CheckedInPartDBItem = CAIEngine.BuildFileDBItemFromSmarTeamID(oid, cid)
     
    ' Insert the part in the new Product
    Dim tPath(1)
    tPath(0) = CheckedInPartDBItem.GetDocumentFullPath()
    ProductDoc.Product.Products.AddComponentsFromFiles tPath, "All"
   ...

Here we create a new CATProduct document. Then, based on SMARTEAM unique identification of the already saved CATPart document, we can retrieve it and get a read-only copy in the user local work area. This CATPart document is then inserted in the CATProduct document.

Perform save and Release operation on the CATProduct document

  ...
    ' Save the Product in SMARTEAM
    Dim ProductDocDBItem As StiDBItem
    Set ProductDocDBItem = CAIEngine.GetStiDBItemFromAnyObject(ProductDoc)
    CAIEngine.Save ProductDocDBItem
     
    ' Perform Release operation on the Product document
    CAIEngine.LifeCycleRelease ProductDocDBItem
  ...

Here we saved the CATProduct document in SMARTEAM. The link from the CATProduct document to the CATPart will also be saved in SMARTEAM.
Then, we perform SMARTEAM life-cycle "Release" operation. Both CATProduct and CATPart will get released.
Once done, both files are moved to the SMARTEAM "Released" vault and removed from the CATIA session.

Reset connection status

  ...
    ' Disconnect from the database in case we had to connect at the
    ' beginning of the script
    If bConnect Then
    CAIEngine.Disconnect
    End If
  ...

Here we disconnect from SMARTEAM (but only in case we had to connect at the beginning of the macro.

Reset UI mode as it was before

  ...
    ' Reset UseGraphicalUI option
    If bUI Then
    CAIEngine.UseGraphicalUI = true
    End If
  ...

Here we reset the UseGraphicalUI property as it was at the beginning of the macro.

End of the macro.

[Top]


In Short

This use case has shown how to use CATIA SMARTEAM Integration.

[Top]


References

[1] Replaying a Macro
[Top]

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