Add and Delete a Package Example

This example opens an existing model, adds a couple of packages, displays the information about each package, deletes one of the packages, and saves the model to a new file.
Sub Example29()
    Dim objTransApp As Object
    Dim model As Model
    Dim packages As Packages
    Dim package As Package
    Dim new_package As Package
    Dim temp_package As Package
    Dim path As String
    Dim timestamp As String
    Dim name As String
    Dim index As Integer
    Dim strIBMCognos10Location As String
    Dim strModelPath As String
    Dim strModelSource As String
    'Change these paths to match your installation
    strIBMCognos10Location = "C:\Program Files\IBM\Cognos\c10\"
    strModelSource = "Sales and Marketing.mdl"
    strModelPath = strIBMCognos10Location & _
        "webcontent\samples\models\Transformer8\EN\" & strModelSource
    objTransApp = CreateObject("IBMCognosTransformer.ApplicationCtrl.1")
    With objTransApp
        .DataSourcePath = strIBMCognos10Location & "bin"
        .TransdaPath = strIBMCognos10Location & "CS7Gateways\bin\TransDa.exe"
    End With
    'Open a package based model
    model = objTransApp.OpenModel(strModelPath)
    'Create a new package and add it to the model
    timestamp = Format(Now, "yyyy-MM-ddTHH:mm:ss.fffZ")
    new_package = model.Packages.Add()
    new_package.Name = "GO Data Warehouse (analysis)"
    new_package.Path = "/content/package[@name='GO Data Warehouse
(analysis)']"
    new_package.TimeStamp = "/content/package[@name='GO Data Warehouse (analysis)']"
_
        & "/model[@name='" & timestamp & "']"
    new_package.Update()
    'Create a second package and add it to the model
    timestamp = Format(Now, "yyyy-MM-ddTHH:mm:ss.fffZ")
    temp_package = model.Packages.Add()
    temp_package.Name = "Temporary Package"
    temp_package.Path = "/content/package[@name='Temporary Package']"
    temp_package.TimeStamp = "/content/package[@name='Temporary
Package']" _
        & "/model[@name='" & timestamp & "']"
    temp_package.Update()
    'Iterate through all packages and display information
    packages = model.Packages
    For index = 1 To packages.Count
        package = packages.Item(index)
        name = package.Name
        path = package.Path
        timestamp = package.TimeStamp
        MsgBox("Package name: " & name & Chr(13) & _
               "Package path: " & path & Chr(13) & _
               "Package time stamp: " & timestamp)
    Next
    'Delete second package
    packages.Remove(temp_package)
    model.Update()
    'Save the model under a different location
    model.SaveAs("Sales and MarketingX.mdl")
    model.Close()
    objTransApp = Nothing
End Sub