Create a Custom View Example
This example creates a custom view. It then
associates the custom view with the cube.
Note: In some cases, you cannot use a macro to set the properties of a category object. Your macro may appear valid but when you run the 'objCategory =' portion, you receive a message: 'This collection is Read Only in this context.' We recommend using the user interface instead.
Sub Example7()
Dim objTransApp As Object
Dim model As Model
Dim dimension As Dimension
Dim measure As Measure
Dim custom_view As CustomView
Dim view As TransformerSDKLib.View
Dim category As Category
Dim cube As Cube
Dim intX 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
model = objTransApp.OpenModel(strModelPath)
'Set a custom view for a dimension.
dimension = model.Dimensions.Item("Retailers")
'Exclude the "Planned revenue" measure
measure = model.Measures.Item("Planned revenue")
'Create custom view
custom_view = model.CustomViews.Add()
With custom_view
.Name = "Central Europe"
.DimensionInclude(dimension) = xtrViewType.trViewTypeCustom
.MeasureInclude(measure) = False
.Update()
End With
'Get associated View object
view = custom_view.DimensionView(dimension)
'Set a view for each category in the top level of the collection.
For intX = 1 To dimension.DrillDowns.Item(1).Categories.Count
category = dimension.DrillDowns.Item(1).Categories(intX)
If category.Name <> "Central Europe" Then
view.SetViewStatus(category, xtrViewStatus.trViewStatusSummaryMom)
End If
Next intX
'Associate a custom view with a cube
cube = model.Cubes.Item("Sales and Marketing")
cube.CubeCustomViews.Add(custom_view)
With model
.SaveAs("Sales and MarketingX.mdl")
.Close()
End With
objTransApp = Nothing
End Sub