The following table contains information on the ISCModelObjectCollection interface:
Signature |
Description |
Valid Arguments |
---|---|---|
ISCModelObjectCollection * Collect(VARIANT Root, VARIANT ClassId [optional], VARIANT Depth [optional], VARIANT MustBeOn [optional], VARIANT MustBeOff [optional]) |
Creates a Model Objects collection, which represents a subcollection of itself. The method creates a valid collection even though the collection may be empty. |
Root:
ClassId:
|
|
|
Depth:
MustBeOn:
MustBeOff:
|
Note: For information about valid object class names and identifiers, see the HTML document ERwin Metamodel Reference, in the Metamodel Reference Bookshelf located in the CA ERwin Data Modeler installation folder. More information about SC_ModelObjectFlags is located in the appendix API Interfaces Reference.
The following sections show the code examples for the different filters.
Example 10
The following example illustrates the Object Type filter using C++. The example uses the Session object from Example 6 and creates a collection of objects of csType type, owned by the rootObj object:
void FilterObjects(ISCSessionPtr scSessionPtr, ISCModelObjectPtr & rootObj, CString & csType) { ISCModelObjectCollectionPtr scModelObjectsPtr; scModelObjectsPtr = scSessionPtr->GetModelObjects()->Collect(rootObj->GetObjectId(), COleVariant(csType)); // … }
The following example illustrates the Object Type filter using Visual Basic .NET. The example uses the Session object from Example 6 and creates a collection of objects of csType type, owned by the rootObj object:
Public Sub FilterObjects(ByRef scSession As SCAPI.Session, _ ByRef rootObj As SCAPI.ModelObject, ByRef objType as String) Dim scModelObjects As SCAPI.ModelObjects scModelObjects = scSession.ModelObject.Collect(rootObj, objType) ' scModelObjects will contain only objects of type objType End Sub
Example 11
The following example illustrates the Depth filter using C++:
void FilterObjects(ISCSessionPtr scSessionPtr, ISCModelObjectPtr & rootObj, CString & csType, long depth) { ISCModelObjectCollectionPtr scModelObjectsPtr; scModelObjectsPtr = scSessionPtr->GetModelObject()-> Collect(rootObj->GetObjectId(), COleVariant(csType),depth); // … }
The following example illustrates the Depth filter using Visual Basic .NET:
Public Sub FilterObjects(ByRef scSession As SCAPI.Session, _ ByRef rootObj As SCAPI.ModelObject, ByRef classID As String, depth As Integer) Dim scModelObjects As SCAPI.ModelObjects scModelObjects = scSession.ModelObjects.Collect(rootObj, classID, depth) End Sub
Example 12
The following example illustrates the MustBeOn/MustBeOff filter using C++. The example uses the Session object from Example 6:
void FilterObjects(ISCSessionPtr scSessionPtr, ISCModelObjectPtr & rootObj, long depth) { ISCModelObjectCollectionPtr scModelObjectsPtr; scModelObjectsPtr = scSessionPtr->GetModelObjects()-> Collect(rootObj->GetObjectId(), vtMissing, depth, SCD_MOF_USER_DEFINED); // … }
The following example illustrates the MustBeOn/MustBeOff filter using Visual Basic .NET. The example uses the Session object from Example 6:
Public Sub FilterObjects(ByRef scSession As SCAPI.Session, _ ByRef rootObj As SCAPI.ModelObject, depth As Integer) Dim scModelObjects As SCAPI.ModelObjects scModelObjects = scSession.ModelObjects.Collect(rootObj, , depth, SCD_MOF_USER_DEFINED) End Sub
The following example illustrates how to create a note through API:
Sub updateAttribute()
' This Creates an Instance of SCApplication
Set SCApp = CreateObject("AllfusionERwin.SCAPI")
'Declare a variable as a FileDialog object.
Dim fd As FileDialog
'Create a FileDialog object as a File Picker dialog box.
Set fd = Application.FileDialog(msoFileDialogFilePicker)
fd.AllowMultiSelect = False
fd.Filters.Clear
fd.Filters.Add "Erwin File", "*.erwin", 1
If (fd.Show = -1) Then
strFileName = fd.SelectedItems.Item(1)
Else
Exit Sub
End If
'Set the object variable to Nothing.
Set fd = Nothing
'strFileName = "C:\models\test03.erwin"
' This is the name of the ER1 Model that needs to be updated
Set SCPUnit = SCApp.PersistenceUnits.Add("erwin://" & strFileName)
Set SCSession = SCApp.Sessions.Add
SCSession.Open (SCPUnit)
Set SCRootObj = SCSession.ModelObjects.Root
Set SCEntObjCol = SCSession.ModelObjects.Collect(SCRootObj, "Entity")
Dim nTransId
nTransId = SCSession.BeginNamedTransaction("Test")
For Each oEntObject In SCEntObjCol
On Error Resume Next
Set oEntCol = SCSession.ModelObjects.Collect(oEntObject, "Attribute")
For Each oAttObject In oEntCol
Set oUserNote = SCSession.ModelObjects.Collect(oAttObject).Add("Extended_Notes")
oUserNote.Properties("Comment").Value = "Test note1"
oUserNote.Properties("Note_Importance").Value = "0" 'enum {0|1|2|3|4|5}
oUserNote.Properties("Status").Value = "1" 'enum {1|2|3}
Next oAttObject
Next oEntObject
SCSession.CommitTransaction (nTransId)
SCSession.Close
' Save the model
Call SCPUnit.Save("erwin://" & strFileName)
MsgBox "Incremental-Save successfully"
SCApp.Sessions.Remove (SCSession)
SCApp.PersistenceUnits.Clear
SCPUnit = Null
SCSession = Null
End Sub
Copyright © 2016 CA Technologies.
All rights reserved.
|
|