APISynthesisResourcesTutorial: Difference between revisions

From ReliaWiki
Jump to navigation Jump to search
(Created page with '{{DISPLAYTITLE:Synthesis Resources Tutorial}}{{Template:InProgress}}{{Template:API}} This tutorial introduces you to the basic functionalities of the Synthesis API. You will lea…')
 
(Redirected page to API Tutorials)
 
(30 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{DISPLAYTITLE:Synthesis Resources Tutorial}}{{Template:InProgress}}{{Template:API}}
#REDIRECT [[API_Tutorials]]
 
This tutorial introduces you to the basic functionalities of the Synthesis API. You will learn how to use the API to create new and update existing resources in a Synthesis repository.
 
In the Synthesis Platform, repositories contain projects, and projects contain resources, analyses and other related items. Therefore, to read or write data to a Synthesis repository, we must begin by first connecting to a Synthesis repository and then accessing one of its projects.
 
==Connecting to a Synthesis Repository and Project==
 
1. Start with the following basic code for connecting to a standard Synthesis repository.
 
'''VBA|VB.NET'''
{{APIComment|'Declare a new instance of the Repository class.}}
  {{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository
{{APIComment|'Specify the full path to the Synthesis repository.}}
{{APIComment|'The following code assumes that a standard repository called "RSRepository1.rsr10" exists in the C drive.}}
  MyRepository.ConnectToRepository({{APIString|"C:/ RSRepository1.rsr10"}})
The Repository class provides other methods for connecting to standard or enterprise repositories. In this example, we use the basic <code>ConnectToRepository</code> method because we are creating a simple application.
 
 
2. Next, we select one of the projects in the repository as our current (or active) project.
 
'''VBA|VB.NET'''
{{APIComment|'Declare a new instance of the NameIDPair class.}}
  {{APIPrefix|Dim}} ListofProjects() {{APIPrefix|As}} NameIDPair
{{APIComment|'Get a list of all projects in the repository.}}
  ListOfProjects = MyRepository.Project.GetAllProjects()
{{APIComment|'Set the first available project in the repository as the current project.}}
  MyRepository.Project.SetCurrentProject(ListofProjects(0))
 
Any time you wish to switch to another project in the repository, you can always use the <code>Project.SetCurrentProject</code> method to specify a new active project.
 
However, if you wish to access projects from another repository, you’ll first need to disconnect from the current repository by using the <code>DisconnectFromRepository</code> method, and then use the <code>ConnectToRepository</code> method again to connect to the desired repository.
 
'''VBA|VB.NET'''
{{APIComment|'Disconnect from the Synthesis repository.}}
  MyRepository.DisconnectFromRepository
===Verify it works===
Let’s verify that our connections to the repository and project work.
 
Here’s the code we have so far, with additional code added right before disconnecting from the repository to verify the result:
 
'''VBA|VB.NET'''
{{APIComment|'Declare a new instance of the Repository class.}}
  {{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository
 
{{APIComment|'Specify the full path to the Synthesis repository.}}
{{APIComment|'The following code assumes that a standard repository called "RSRepository1.rsr10" exists in the C drive.}}
  MyRepository.ConnectToRepository({{APIString|"C:/ RSRepository1.rsr10"}})
{{APIComment|'Declare a new instance of the NameIDPair class.}}
  {{APIPrefix|Dim}} ListofProjects() {{APIPrefix|As}} NameIDPair
{{APIComment|'Get a list of all projects in the repository.}}
  ListOfProjects = MyRepository.Project.GetAllProjects()
{{APIComment|'Set the first available project in the repository as the current project.}}
  MyRepository.Project.SetCurrentProject(ListofProjects(0))
{{APIComment|'Verify connection to repository and project.}}
{{APIComment|'The following code displays a message box containing the name and ID number of the current project.}}
  {{APIPrefix|Dim}} ProjectName {{APIPrefix|As}} String
  {{APIPrefix|Dim}} ProjectID {{APIPrefix|As}} Integer
  ProjectName = MyRepository.Project.GetCurrentProject().Name
  ProjectID = MyRepository.Project.GetCurrentProject().ID
  MsgBox ({{APIString|"You are currently connected to: "}} & ProjectName & {{APIString|", ID#"}} & ProjectID)
{{APIComment|'Disconnect from the Synthesis repository.}}
  MyRepository.DisconnectFromRepository
 
On the Debug menu, click '''Start''' to run the application. A message box displays the name and ID number of the first available project in the repository. You can verify the information by opening the repository in any Synthesis application and checking for the name of the project. (The project ID can be found by xxx.)
 
 
==Creating a New Synthesis Resource==
Now that we know how to connect to a repository and a project, let’s experiment with adding a new model resource to a repository.
 
1. We begin again by connecting to a Synthesis repository and a project.
 
'''VBA | VB.NET'''
{{APIComment|'Connect to a Synthesis repository and set the first available project in the repository as the active project.}}
  {{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository
  MyRepository.ConnectToRepository({{APIString|"C:/ RSRepository1.rsr10"}})
  MyRepository.Project.SetCurrentProject(1)
 
 
2. Use the cModel class to create a 2-parameter Weibull reliability model with beta 1 and eta 100. Name the model, "MyNewModel."
 
For VBA, use the <code>SetModel</code> method to define the model. For VB.NET, use the parameterized constructor to create and define the model.
 
'''VBA '''
{{APIComment|'Declare a new instance of the cModel class.}}
  {{APIPrefix|Dim}} Amodel {{APIPrefix|As New}} cModel
{{APIComment|'Define the model&#39;s properties.}}
  {{APIPrefix|Dim}} ModelType {{APIPrefix|As}} ModelTypeEnum
  {{APIPrefix|Dim}} ModelCategory {{APIPrefix|As}} ModelCategoryEnum
  {{APIPrefix|Dim}} ModelName {{APIPrefix|As}} String
  {{APIPrefix|Dim}} ModelParams(1) {{APIPrefix|As}} Double
  ModelType = ModelTypeEnum_Weibull2
  ModelCategory = ModelCategoryEnum_Reliability
  ModelName = {{APIString|"MyNewModel"}}
  ModelParams(0) = 1
  ModelParams(1) = 100
  {{APIPrefix|Call}} AModel.SetModel(ModelType, ModelCategory, ModelName, ModelParams)
{{APIComment|'Add the new model to the current project.}}
  {{APIPrefix|Call}} MyRepository.Model.AddModel(AModel)
 
'''VB.NET'''
{{APIComment|'Declare a new instance of the cModel class. You can use an in-line parameter list to define the model.}}
  {{APIPrefix|Dim}} newModel {{APIPrefix|As New}} cModel(ModelTypeEnum.Weibull2, ModelCategoryEnum.Reliability, {{APIString|"MyNewModel"}}, 1, 100)
{{APIComment|'Add the new model to the current project.}}
  MyRepository.Model.AddModel(AModel)
 
===Verify it works===
On the Debug menu, click '''Start''' to run the application. Then in the Synthesis repository, open the project’s Resource Manager ('''Project > Synthesis> Resource Manager''') and then select the Models page. A model named "MyNewModel" should be on the list.
 
 
==Updating an Existing Resource==
 
==Extracting Information from Resources==

Latest revision as of 22:14, 9 February 2016

Redirect to: