Repository.Model.GetModel: Difference between revisions

From ReliaWiki
Jump to navigation Jump to search
No edit summary
Line 11: Line 11:


==Usage Example==
==Usage Example==
{{APIComment|'Declare a new repository connection class.}}
{{Template:RepositoryFull.Ex}}
  Dim MyRepository As New Repository
 
{{APIComment|'Connect to the Synthesis repository.}}
  Dim Success As Boolean = False
  Success = MyRepository.ConnectToRepository("RepositoryFileNamePath")
 
{{APIComment|'Get the list of Models in the connected repository.}}
  Dim ListOfModels() As [[NameIdPair Class|NameIdPair]]
  ListOfModels = MyRepository.GetAllModelsInfo()
 
{{APIComment|'Select the ID of the model and retrieve it.  In this example, the first model is used.}}
  Dim AModel as cModel
  AModel = MyRepository.GetModel(ListOfModels(0).ID)

Revision as of 20:23, 27 May 2014


Returns the model from the current project with the specified ID. Returns nothing if the model does not exist or is not in the current project.

Note regarding compound analytical models: After you connect to a database and create the cModel using Repository Class (GetModel or GetAllModels methods), the Repository Class must stay connected to the same database until you are done working with the model.

Syntax

  • GetModel( IDAs Integer)AscModel

Parameters

ID: The ID of the model to retrieve.

Usage Example

In this usage example, the API is used to connect to a repository, retrieve one of the models in it and then calculate the reliability at a specified time, based on that model.

 'Declare a new repository connection object. See Repository. 
 Dim MyRepository As New Repository
 
 'Connect to a Synthesis repository. 
 Dim Success As Boolean = False
 Success = MyRepository.ConnectToRepository("C:\Users\Name\Documents\ReliaSoft\Files\repository.rsr10")
 
 'Get a list of the names/IDs of projects in the connected repository. 
 Dim ListOfProjects() As NameIdPair
 ListOfProjects = MyRepository.Project.GetAllProjects()
 
 'Open the first project in the list. 
 MyRepository.Project.SetCurrentProject(ListOfProjects(0).ID)
 
 'Get a list of the names/IDs of models in the current project. 
 Dim ListOfModels() As NameIdPair
 ListOfModels = MyRepository.Model.GetAllModelsInfo()
 
 'Retrieve the first model in the list. 
 Dim AModel As cModel
 AModel = MyRepository.Model.GetModel(ListOfModels(0).ID)
 
 'Calculate the reliability at time = 50 and save the result. See Reliability. 
 Dim Rel As Double
 Rel = AModel.Reliability(50)
 
 'Disconnect from the repository. 
 MyRepository.DisconnectFromRepository()