APISynthesisResourcesTutorial: Difference between revisions

From ReliaWiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
{{DISPLAYTITLE:Synthesis Resources Tutorial}}{{Template:InProgress}}{{Template:API}}
{{DISPLAYTITLE:Synthesis Resources Tutorial}}{{Template:InProgress}}{{Template:API}}
<div style="border:1px solid #AAA; background:#f9f9f9; border-radius:10px; width:auto; margin:0 0 1em 1em; padding:1em; float:right;">
<nowiki><<</nowiki> Back to Quick Start Guide
'''Synthesis Resources Tutorial'''
#[[#Part1: Connecting to a Synthesis Repository and Project|Connecting to a Synthesis Repository and Project]]
#[[#Part2: Creating a New Synthesis Resource|Creating a New Synthesis Resource]]
#[[#Part3: Updating an Existing Resource|Updating an Existing Resource]]
#[[#Part4: Extracting Information from Resources|Extracting Information from Resources]]
'''[[Synthesis Data Warehouse (SDW) Tutorial]]
</div>
This four-part 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.


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.  
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.  


__TOC__


==Connecting to a Synthesis Repository and Project==
<div style="border:1px solid #AAA; background:#f9f9f9; border-radius:10px; width:auto; margin:0 0 1em 1em; padding:1em; float:right;">
'''Reference Links'''
*[[Repository Class]]
*[[Repository.ConnectToRepository|ConnectToRepository Method]]
*[[NameIdPair Class]]
*[[Repository.Project.GetAllProjects|GetAllProjects Method]]
*[[Repository.Project.SetCurrentProject|SetCurrentProject Method]]
*[[Repository.DisconnectFromRepository|DisconnectFromRepository Method]]
*[[Repository.Project.GetCurrentProject|GetCurrentProject Method]]
</div>


1. Start with the following basic code for connecting to a standard Synthesis repository.
 
 
 
 
==Part 1: Connecting to a Synthesis Repository and Project==
1. We'll start with the Repository class, which provides several methods for connecting to standard or enterprise repositories. In this example, we will use the basic <code>ConnectToRepository</code> method to create a simple application.  
 
Create a new module and start with the following basic code for connecting to a standard Synthesis repository.


  '''VBA|VB.NET'''
  '''VBA|VB.NET'''
Line 30: Line 36:
   MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr10"}})
   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.
2. Next, use the <code>Project.SetCurrentProject</code> method to specify the current (or active) project using the project's ID number. In this example, we'll get an array of all projects in the repository and then use the ID number of the first project in the array to set it as the current project.


  '''VBA|VB.NET'''
  '''VBA|VB.NET'''
Line 43: Line 47:
   ListOfProjects = MyRepository.Project.GetAllProjects()
   ListOfProjects = MyRepository.Project.GetAllProjects()
   
   
  {{APIComment|'Set the first available project in the repository as the current project.}}
  {{APIComment|'Set the first available project as the current project.}}
   MyRepository.Project.SetCurrentProject(ListofProjects(0))
   MyRepository.Project.SetCurrentProject(ListofProjects(0).ID)


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.
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.
Line 58: Line 62:
Let’s verify that our connections to the repository and project work.
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:
Below is the code we have so far, with additional code added right before disconnecting from the repository to verify the result. On the Debug menu, click '''Start''' to run the application. A message box displays the name and ID number of the current project in the repository.


  '''VBA|VB.NET'''
  '''VBA|VB.NET'''
 
Sub Main()
   
   
  {{APIComment|'Declare a new instance of the Repository class.}}
  {{APIComment|'Declare a new instance of the Repository class.}}
Line 75: Line 81:
   ListOfProjects = MyRepository.Project.GetAllProjects()
   ListOfProjects = MyRepository.Project.GetAllProjects()
   
   
  {{APIComment|'Set the first available project in the repository as the current project.}}
  {{APIComment|'Set the first available project as the current project.}}
   MyRepository.Project.SetCurrentProject(ListofProjects(0))
   MyRepository.Project.SetCurrentProject(ListofProjects(0).ID)
   
   
  {{APIComment|'Verify connection to repository and project.}}
  {{APIComment|'Verify connection to repository and project.}}
Line 88: Line 94:
  {{APIComment|'Disconnect from the Synthesis repository.}}
  {{APIComment|'Disconnect from the Synthesis repository.}}
   MyRepository.DisconnectFromRepository
   MyRepository.DisconnectFromRepository
End Sub


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.)
===Reference Links===
*[[Repository Class]]
*[[NameIdPair Class]]
*[[Repository.ConnectToRepository|Repository.ConnectToRepository Method]]
*[[Repository.DisconnectFromRepository|Repository.DisconnectFromRepository Method]]
*[[Repository.Project.GetAllProjects|Repository.Project.GetAllProjects Method]]
*[[Repository.Project.SetCurrentProject|Repository.Project.SetCurrentProject Method]]
*[[Repository.Project.GetCurrentProject|Repository.Project.GetCurrentProject Method]]
*[[Guide to Using Item IDs with the Synthesis API]]




==Creating a New Synthesis Resource==
==Part 2: Creating a New Synthesis Resource==
Now that we know how to connect to a repository and a project, let’s try adding a new model resource to a repository.
Now that we've learned how to connect to a repository and a project, let’s try adding a new model resource to the repository.


<div style="border:1px solid #AAA; background:#f9f9f9; border-radius:10px; width:auto; margin:0 0 1em 1em; padding:1em; float:right;">
'''Reference Links'''
*[[CModel Class|cModel Class]]
*[[CModel.SetModel|SetModel Method]]
*[[CModel_Constructors|cModel Constructor (VB.NET)]]
*[[ModelTypeEnum Enumeration]]
*[[ModelCategoryEnum Enumeration]]
</div>
1. We begin again by connecting to a Synthesis repository and a project.
1. We begin again by connecting to a Synthesis repository and a project.


Line 151: Line 159:
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.
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.


===Reference Links===
*[[CModel Class|cModel Class]]
*[[CModel.SetModel|CModel.SetModel Method]]
*[[CModel_Constructors|cModel Constructor (VB.NET Only)]]
*[[ModelTypeEnum Enumeration]]
*[[ModelCategoryEnum Enumeration]]


==Updating an Existing Resource==
<div style="border:1px solid #AAA; background:#f9f9f9; border-radius:10px; width:auto; margin:0 0 1em 1em; padding:1em; float:right;">
'''Reference Links'''
*[[Repository.Model.GetModel|GetModel Method]]
*[[Guide to Using Item IDs with the Synthesis API]]
</div>


This next section demonstrates how to update the properties of an existing resource in a Synthesis repository.
==Part 3: Updating an Existing Resource==
In this section, we'll update the properties of the model of we've created in the previous section.


1. First, connect to the Synthesis repository and project.
1. First, connect to the Synthesis repository and project.
Line 170: Line 179:
   MyRepository.Project.SetCurrentProject(1)
   MyRepository.Project.SetCurrentProject(1)


2. Next, retrieve the resource to be updated from the repository. For this example, let's retrieve the model we created in the previous section. (The model was called "MyNewModel.")
2. Next, use <code>GetModel</code> method to the retrieve the model (called "MyNewModel") from the repository. The following code assumes that the model's ID number is 21.  
 
The following code demonstrates how to retrieve the model, assuming that its ID# is 21.  


  '''VBA'''
  '''VBA'''
Line 186: Line 193:
   AModel = MyRepository.Model.GetModel(21)
   AModel = MyRepository.Model.GetModel(21)


3. For this example, let's change the model's name to "MyNewModel_Updated" and change the value of beta to 2.
'''VBA'''
   
   
3.  
{{APIComment|Specify the new model name and new value for beta.}}
  {{APIPrefix|Dim}} ModelParams(1) {{APIPrefix|As}} Double 
 
  Amodel.Name = {{APIString|"MyNewModel_Updated"}}
  ModelParams(0) = 2
{{APIComment|Apply the changes to the model.}}
  {{APIPrefix|Call}} MyRepository.Model.UpdateModel(AModel)
 
'''VB.NET'''
{{APIComment|Specify the new model name and new value for beta.}}
  {{APIPrefix|Dim}} ModelParams(1) {{APIPrefix|As}} Double 
 
  Amodel.Name = {{APIString|"MyNewModel_Updated"}}
  ModelParams(0) = 2
{{APIComment|Apply the changes to the model.}}
  MyRepository.Model.UpdateModel(AModel)
 
===Verify It Works===
Below are the VBA and VB.NET code lists for this example. On the Debug menu, click '''Start''' to run the application. Check the project's Resource Manager to verify the results.
 
'''VBA'''
{{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)
{{APIComment|Retrieve the model with ID# 21 from the repository.}}
  {{APIPrefix|Dim}} Amodel {{APIPrefix|As New}} cModel
  {{APIPrefix|Set}} AModel = MyRepository.Model.GetModel(21)
{{APIComment|Specify the new model name and new value for beta.}}
  {{APIPrefix|Dim}} ModelParams(1) {{APIPrefix|As}} Double 
   
  Amodel.Name = {{APIString|"MyNewModel_Updated"}}
  ModelParams(0) = 2
 
{{APIComment|Apply the changes to the model.}}
  {{APIPrefix|Call}} MyRepository.Model.UpdateModel(AModel)
 
'''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)
    
    
{{APIComment|Retrieve the model with ID# 21 from the repository.}}
  {{APIPrefix|Dim}} Amodel {{APIPrefix|As New}} cModel
  AModel = MyRepository.Model.GetModel(21)
{{APIComment|Specify the new model name and new value for beta.}}
  {{APIPrefix|Dim}} ModelParams(1) {{APIPrefix|As}} Double 
 
  Amodel.Name = {{APIString|"MyNewModel_Updated"}}
  ModelParams(0) = 2
{{APIComment|Apply the changes to the model.}}
  MyRepository.Model.UpdateModel(AModel)
===Reference Links===
*[[Repository.Model.GetModel|Repository.Model.GetModel Method]]
*[[Repository.Model.UpdateModel|Repository.Model.UpdateModel Method]]




==Extracting Information from Resources==
==Part 4: Extracting Information from Resources==

Revision as of 17:11, 20 October 2015

Template:InProgress

APIWiki.png


<< Back to Quick Start Guide

Synthesis Resources Tutorial

  1. Connecting to a Synthesis Repository and Project
  2. Creating a New Synthesis Resource
  3. Updating an Existing Resource
  4. Extracting Information from Resources

Synthesis Data Warehouse (SDW) Tutorial

This four-part 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.




Part 1: Connecting to a Synthesis Repository and Project

1. We'll start with the Repository class, which provides several methods for connecting to standard or enterprise repositories. In this example, we will use the basic ConnectToRepository method to create a simple application.

Create a new module and start with the following basic code for connecting to a standard Synthesis repository.

VBA|VB.NET

 'Declare a new instance of the Repository class. 
  Dim MyRepository As New Repository

 'Specify the full path to the Synthesis repository. 
 'The following code assumes that a standard repository called "RSRepository1.rsr10" exists in the C drive. 
  MyRepository.ConnectToRepository("C:\RSRepository1.rsr10")

2. Next, use the Project.SetCurrentProject method to specify the current (or active) project using the project's ID number. In this example, we'll get an array of all projects in the repository and then use the ID number of the first project in the array to set it as the current project.

VBA|VB.NET

 'Declare a new instance of the NameIDPair class. 
  Dim ListofProjects() As NameIDPair

 'Get a list of all projects in the repository. 
  ListOfProjects = MyRepository.Project.GetAllProjects()

 'Set the first available project as the current project. 
  MyRepository.Project.SetCurrentProject(ListofProjects(0).ID)

Any time you wish to switch to another project in the repository, you can always use the Project.SetCurrentProject 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 DisconnectFromRepository method, and then use the ConnectToRepository method again to connect to the desired repository.

VBA|VB.NET

 'Disconnect from the Synthesis repository. 
  MyRepository.DisconnectFromRepository

Verify it works

Let’s verify that our connections to the repository and project work.

Below is the code we have so far, with additional code added right before disconnecting from the repository to verify the result. On the Debug menu, click Start to run the application. A message box displays the name and ID number of the current project in the repository.

VBA|VB.NET
 
Sub Main()

 'Declare a new instance of the Repository class. 
  Dim MyRepository As New Repository
 
 'Specify the full path to the Synthesis repository. 
 'The following code assumes that a standard repository called "RSRepository1.rsr10" exists in the C drive. 
  MyRepository.ConnectToRepository("C:\RSRepository1.rsr10")

 'Declare a new instance of the NameIDPair class. 
  Dim ListofProjects() As NameIDPair

 'Get a list of all projects in the repository. 
  ListOfProjects = MyRepository.Project.GetAllProjects()

 'Set the first available project as the current project. 
  MyRepository.Project.SetCurrentProject(ListofProjects(0).ID)

 'Verify connection to repository and project. 
 'The following code displays a message box containing the name and ID number of the current project. 
  Dim ProjectName As String
  Dim ProjectID As Integer 
  ProjectName = MyRepository.Project.GetCurrentProject().Name
  ProjectID = MyRepository.Project.GetCurrentProject().ID
  MsgBox ("You are currently connected to: " & ProjectName & ", ID#" & ProjectID)

 'Disconnect from the Synthesis repository. 
  MyRepository.DisconnectFromRepository

End Sub

Reference Links


Part 2: Creating a New Synthesis Resource

Now that we've learned how to connect to a repository and a project, let’s try adding a new model resource to the repository.

1. We begin again by connecting to a Synthesis repository and a project.

VBA|VB.NET

 'Connect to a Synthesis repository and set the first available project in the repository as the active project. 
  Dim MyRepository As New Repository
  MyRepository.ConnectToRepository("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 SetModel method to define the model. For VB.NET, use the parameterized constructor to create and define the model.

VBA 

 'Declare a new instance of the cModel class. 
  Dim Amodel As New cModel

 'Define the model's properties. 
  Dim ModelType As ModelTypeEnum
  Dim ModelCategory As ModelCategoryEnum
  Dim ModelName As String
  Dim ModelParams(1) As Double

  ModelType = ModelTypeEnum_Weibull2
  ModelCategory = ModelCategoryEnum_Reliability
  ModelName = "MyNewModel"

  ModelParams(0) = 1
  ModelParams(1) = 100

  Call AModel.SetModel(ModelType, ModelCategory, ModelName, ModelParams)

 'Add the new model to the current project. 
  Call MyRepository.Model.AddModel(AModel)
VB.NET

 'Declare a new instance of the cModel class. You can use an in-line parameter list to define the model. 
  Dim newModel As New cModel(ModelTypeEnum.Weibull2, ModelCategoryEnum.Reliability, "MyNewModel", 1, 100)

 '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.

Reference Links


Part 3: Updating an Existing Resource

In this section, we'll update the properties of the model of we've created in the previous section.

1. First, connect to the Synthesis repository and project.

VBA|VB.NET

 'Connect to a Synthesis repository and set the first available project in the repository as the active project. 
  Dim MyRepository As New Repository
  MyRepository.ConnectToRepository("C:\RSRepository1.rsr10")
  MyRepository.Project.SetCurrentProject(1)

2. Next, use GetModel method to the retrieve the model (called "MyNewModel") from the repository. The following code assumes that the model's ID number is 21.

VBA

 Retrieve the model with ID# 21 from the repository. 
  Dim Amodel As New cModel
  Set AModel = MyRepository.Model.GetModel(21)
VB.NET

 Retrieve the model with ID# 21 from the repository.  
  Dim Amodel As New cModel
  AModel = MyRepository.Model.GetModel(21)

3. For this example, let's change the model's name to "MyNewModel_Updated" and change the value of beta to 2.

VBA

 Specify the new model name and new value for beta. 
  Dim ModelParams(1) As Double  
  
  Amodel.Name = "MyNewModel_Updated"
  ModelParams(0) = 2

 Apply the changes to the model. 
  Call MyRepository.Model.UpdateModel(AModel)
VB.NET

 Specify the new model name and new value for beta. 
  Dim ModelParams(1) As Double  
  
  Amodel.Name = "MyNewModel_Updated"
  ModelParams(0) = 2

 Apply the changes to the model. 
  MyRepository.Model.UpdateModel(AModel)

Verify It Works

Below are the VBA and VB.NET code lists for this example. On the Debug menu, click Start to run the application. Check the project's Resource Manager to verify the results.

VBA

 'Connect to a Synthesis repository and set the first available project in the repository as the active project. 
  Dim MyRepository As New Repository
  MyRepository.ConnectToRepository("C:\RSRepository1.rsr10")
  MyRepository.Project.SetCurrentProject(1)

 Retrieve the model with ID# 21 from the repository. 
  Dim Amodel As New cModel
  Set AModel = MyRepository.Model.GetModel(21)

 Specify the new model name and new value for beta. 
  Dim ModelParams(1) As Double  
   
  Amodel.Name = "MyNewModel_Updated"
  ModelParams(0) = 2
 
 Apply the changes to the model. 
  Call MyRepository.Model.UpdateModel(AModel)
VB.NET
  
 'Connect to a Synthesis repository and set the first available project in the repository as the active project. 
  Dim MyRepository As New Repository
  MyRepository.ConnectToRepository("C:\RSRepository1.rsr10")
  MyRepository.Project.SetCurrentProject(1)
 
 Retrieve the model with ID# 21 from the repository.  
  Dim Amodel As New cModel
  AModel = MyRepository.Model.GetModel(21)

 Specify the new model name and new value for beta. 
  Dim ModelParams(1) As Double  
  
  Amodel.Name = "MyNewModel_Updated"
  ModelParams(0) = 2

 Apply the changes to the model. 
  MyRepository.Model.UpdateModel(AModel)

Reference Links


Part 4: Extracting Information from Resources