APISynthesisResourcesTutorial: Difference between revisions
Kate Racaza (talk | contribs) No edit summary |
Kate Racaza (talk | contribs) No edit summary |
||
Line 7: | Line 7: | ||
#[[#Part2: Creating a New Synthesis Resource|Creating a New Synthesis Resource]] | #[[#Part2: Creating a New Synthesis Resource|Creating a New Synthesis Resource]] | ||
#[[#Part3: Updating an Existing Resource|Updating an Existing Resource]] | #[[#Part3: Updating an Existing Resource|Updating an Existing Resource]] | ||
#[[# | #[[#Part 4: Calculating Results from Models|Calculating Results from Models]] | ||
'''[[Synthesis Data Warehouse (SDW) Tutorial]] | '''[[Synthesis Data Warehouse (SDW) Tutorial]] | ||
</div> | </div> | ||
Line 35: | Line 35: | ||
{{APIComment|'The following code assumes that a standard repository called "RSRepository1.rsr10" exists in the C drive.}} | {{APIComment|'The following code assumes that a standard repository called "RSRepository1.rsr10" exists in the C drive.}} | ||
MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr10"}}) | MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr10"}}) | ||
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. | 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 first use the <code>GetAllProjects</code> method to 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 49: | Line 48: | ||
{{APIComment|'Set the first available project as the current project.}} | {{APIComment|'Set the first available project as the current project.}} | ||
MyRepository.Project.SetCurrentProject(ListofProjects(0).ID) | MyRepository.Project.SetCurrentProject(ListofProjects(0).ID) | ||
{{APIComment|'Display 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) | |||
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 59: | Line 66: | ||
MyRepository.DisconnectFromRepository | MyRepository.DisconnectFromRepository | ||
===Verify | ===Verify It Works=== | ||
Let’s verify that our connections to the repository and project work. | Let’s verify that our connections to the repository and project work. | ||
Below is the code | Below is the code list for this example. 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''' | ||
Line 84: | Line 91: | ||
MyRepository.Project.SetCurrentProject(ListofProjects(0).ID) | MyRepository.Project.SetCurrentProject(ListofProjects(0).ID) | ||
{{APIComment|' | {{APIComment|'Display the name and ID number of the current project.}} | ||
{{APIPrefix|Dim}} ProjectName {{APIPrefix|As}} String | {{APIPrefix|Dim}} ProjectName {{APIPrefix|As}} String | ||
{{APIPrefix|Dim}} ProjectID {{APIPrefix|As}} Integer | {{APIPrefix|Dim}} ProjectID {{APIPrefix|As}} Integer | ||
ProjectName = MyRepository.Project.GetCurrentProject().Name | ProjectName = MyRepository.Project.GetCurrentProject().Name | ||
ProjectID = MyRepository.Project.GetCurrentProject().ID | ProjectID = MyRepository.Project.GetCurrentProject().ID | ||
Line 111: | Line 118: | ||
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. | 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. | 1. Create a new module and begin again by connecting to the Synthesis repository and project. | ||
'''VBA|VB.NET''' | '''VBA|VB.NET''' | ||
{{APIComment|'Connect to a Synthesis repository and set | {{APIComment|'Connect to a Synthesis repository and set project ID#1 as the current project.}} | ||
{{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository | {{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository | ||
MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr10"}}) | MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr10"}}) | ||
MyRepository.Project.SetCurrentProject(1) | 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." | 2. Use the cModel class to create a 2-parameter Weibull reliability model with beta 1 and eta 100. Name the model, "MyNewModel." | ||
Line 139: | Line 145: | ||
ModelCategory = ModelCategoryEnum_Reliability | ModelCategory = ModelCategoryEnum_Reliability | ||
ModelName = {{APIString|"MyNewModel"}} | ModelName = {{APIString|"MyNewModel"}} | ||
ModelParams(0) = 1 | |||
ModelParams(1) = 100 | |||
{{APIPrefix|Call}} AModel.SetModel(ModelType, ModelCategory, ModelName, ModelParams) | |||
'''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) | |||
3. Use the <code>AddModel</code> method to save the new model to the repository. | |||
'''VBA''' | |||
{{APIComment|'Add the new model to the current project.}} | |||
{{APIPrefix|Call}} MyRepository.Model.AddModel(AModel) | |||
'''VB.NET''' | |||
{{APIComment|'Add the new model to the current project.}} | |||
MyRepository.Model.AddModel(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. 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. | |||
'''VBA''' | |||
Sub Main() | |||
{{APIComment|'Connect to a Synthesis repository and set project ID#1 as the current project.}} | |||
{{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository | |||
MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr10"}}) | |||
MyRepository.Project.SetCurrentProject(1) | |||
{{APIComment|'Declare a new instance of the cModel class.}} | |||
{{APIPrefix|Dim}} Amodel {{APIPrefix|As New}} cModel | |||
{{APIComment|'Define the model'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(0) = 1 | ||
ModelParams(1) = 100 | ModelParams(1) = 100 | ||
Line 147: | Line 198: | ||
{{APIComment|'Add the new model to the current project.}} | {{APIComment|'Add the new model to the current project.}} | ||
{{APIPrefix|Call}} MyRepository.Model.AddModel(AModel) | {{APIPrefix|Call}} MyRepository.Model.AddModel(AModel) | ||
End Sub | |||
'''VB.NET''' | '''VB.NET''' | ||
Sub Main() | |||
{{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|'Declare a new instance of the cModel class. You can use an in-line parameter list to define the model.}} | {{APIComment|'Declare a new instance of the cModel class. You can use an in-line parameter list to define the model.}} | ||
Line 155: | Line 215: | ||
{{APIComment|'Add the new model to the current project.}} | {{APIComment|'Add the new model to the current project.}} | ||
MyRepository.Model.AddModel(AModel) | MyRepository.Model.AddModel(AModel) | ||
End Sub | |||
===Reference Links=== | ===Reference Links=== | ||
*[[CModel Class|cModel Class]] | *[[CModel Class|cModel Class]] | ||
*[[CModel.SetModel| | *[[CModel.SetModel|cModel.SetModel Method]] | ||
*[[CModel_Constructors|cModel Constructor (VB.NET Only)]] | *[[CModel_Constructors|cModel Constructor (VB.NET Only)]] | ||
*[[Repository.Model.AddModel|Repository.Model.AddModel Method]] | |||
*[[ModelTypeEnum Enumeration]] | *[[ModelTypeEnum Enumeration]] | ||
*[[ModelCategoryEnum Enumeration]] | *[[ModelCategoryEnum Enumeration]] | ||
==Part 3: Updating an Existing Resource== | ==Part 3: Updating an Existing Resource== | ||
In this section, we'll update the properties of the model | In this section, we'll update the properties of the model we've created in the previous section. | ||
1. | 1. Create a new module and add code to connect to the Synthesis repository and project. | ||
'''VBA|VB.NET''' | '''VBA|VB.NET''' | ||
{{APIComment|'Connect to a Synthesis repository and set | {{APIComment|'Connect to a Synthesis repository and set project ID#1 as the current project.}} | ||
{{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository | {{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository | ||
MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr10"}}) | MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr10"}}) | ||
Line 183: | Line 244: | ||
'''VBA''' | '''VBA''' | ||
{{APIComment|Retrieve the model with ID# 21 from the repository.}} | {{APIComment|'Retrieve the model with ID# 21 from the repository.}} | ||
{{APIPrefix|Dim}} Amodel {{APIPrefix|As New}} cModel | {{APIPrefix|Dim}} Amodel {{APIPrefix|As New}} cModel | ||
{{APIPrefix|Set}} AModel = MyRepository.Model.GetModel(21) | {{APIPrefix|Set}} AModel = MyRepository.Model.GetModel(21) | ||
Line 189: | Line 250: | ||
'''VB.NET''' | '''VB.NET''' | ||
{{APIComment|Retrieve the model with ID# 21 from the repository.}} | {{APIComment|'Retrieve the model with ID# 21 from the repository.}} | ||
{{APIPrefix|Dim}} Amodel {{APIPrefix|As New}} cModel | {{APIPrefix|Dim}} Amodel {{APIPrefix|As New}} cModel | ||
AModel = MyRepository.Model.GetModel(21) | AModel = MyRepository.Model.GetModel(21) | ||
Line 195: | Line 256: | ||
3. For this example, let's change the model's name to "MyNewModel_Updated" and change the value of beta to 2. | 3. For this example, let's change the model's name to "MyNewModel_Updated" and change the value of beta to 2. | ||
'''VBA''' | '''VBA|VB.NET''' | ||
{{APIComment|Specify the new model name and new value for beta.}} | {{APIComment|'Specify the new model name and new value for beta.}} | ||
{{APIPrefix|Dim}} ModelParams(1) {{APIPrefix|As}} Double | {{APIPrefix|Dim}} ModelParams(1) {{APIPrefix|As}} Double | ||
Line 203: | Line 264: | ||
ModelParams(0) = 2 | ModelParams(0) = 2 | ||
{{APIComment|Apply the changes to the model.}} | 4. Use the <code>UpdateModel</code> method to apply the changes to the model. | ||
'''VBA''' | |||
{{APIComment|'Apply the changes to the model.}} | |||
{{APIPrefix|Call}} MyRepository.Model.UpdateModel(AModel) | {{APIPrefix|Call}} MyRepository.Model.UpdateModel(AModel) | ||
'''VB.NET''' | '''VB.NET''' | ||
{{APIComment|'Apply the changes to the model.}} | |||
{{APIComment|Apply the changes to the model.}} | |||
MyRepository.Model.UpdateModel(AModel) | MyRepository.Model.UpdateModel(AModel) | ||
Line 222: | Line 281: | ||
'''VBA''' | '''VBA''' | ||
{{APIComment|'Connect to a Synthesis repository and set | Sub Main() | ||
{{APIComment|'Connect to a Synthesis repository and set project ID#1 as the current project.}} | |||
{{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository | {{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository | ||
MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr10"}}) | MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr10"}}) | ||
MyRepository.Project.SetCurrentProject(1) | MyRepository.Project.SetCurrentProject(1) | ||
{{APIComment|Retrieve the model with ID# 21 from the repository.}} | {{APIComment|'Retrieve the model with ID# 21 from the repository.}} | ||
{{APIPrefix|Dim}} Amodel {{APIPrefix|As New}} cModel | {{APIPrefix|Dim}} Amodel {{APIPrefix|As New}} cModel | ||
{{APIPrefix|Set}} AModel = MyRepository.Model.GetModel(21) | {{APIPrefix|Set}} AModel = MyRepository.Model.GetModel(21) | ||
{{APIComment|Specify the new model name and new value for beta.}} | {{APIComment|'Specify the new model name and new value for beta.}} | ||
{{APIPrefix|Dim}} ModelParams(1) {{APIPrefix|As}} Double | {{APIPrefix|Dim}} ModelParams(1) {{APIPrefix|As}} Double | ||
Line 237: | Line 298: | ||
ModelParams(0) = 2 | ModelParams(0) = 2 | ||
{{APIComment|Apply the changes to the model.}} | {{APIComment|'Apply the changes to the model.}} | ||
{{APIPrefix|Call}} MyRepository.Model.UpdateModel(AModel) | {{APIPrefix|Call}} MyRepository.Model.UpdateModel(AModel) | ||
End Sub | |||
'''VB.NET''' | '''VB.NET''' | ||
Sub Main() | |||
{{APIComment|'Connect to a Synthesis repository and set the first available project in the repository as the active project.}} | {{APIComment|'Connect to a Synthesis repository and set the first available project in the repository as the active project.}} | ||
Line 247: | Line 312: | ||
MyRepository.Project.SetCurrentProject(1) | MyRepository.Project.SetCurrentProject(1) | ||
{{APIComment|Retrieve the model with ID# 21 from the repository.}} | {{APIComment|'Retrieve the model with ID# 21 from the repository.}} | ||
{{APIPrefix|Dim}} Amodel {{APIPrefix|As New}} cModel | {{APIPrefix|Dim}} Amodel {{APIPrefix|As New}} cModel | ||
AModel = MyRepository.Model.GetModel(21) | AModel = MyRepository.Model.GetModel(21) | ||
{{APIComment|Specify the new model name and new value for beta.}} | {{APIComment|'Specify the new model name and new value for beta.}} | ||
{{APIPrefix|Dim}} ModelParams(1) {{APIPrefix|As}} Double | {{APIPrefix|Dim}} ModelParams(1) {{APIPrefix|As}} Double | ||
Line 257: | Line 322: | ||
ModelParams(0) = 2 | ModelParams(0) = 2 | ||
{{APIComment|Apply the changes to the model.}} | {{APIComment|'Apply the changes to the model.}} | ||
MyRepository.Model.UpdateModel(AModel) | MyRepository.Model.UpdateModel(AModel) | ||
End Sub | |||
===Reference Links=== | ===Reference Links=== | ||
Line 265: | Line 332: | ||
==Part 4: Calculating Results from Models== | |||
Models are used by other Synthesis resources to represent the reliability of a task, the duration of a task, the expected cost of a repair, and many other characteristics. In this section, we'll learn how to obtain calculated results from models. | |||
1. Create a new module, and then add code to retrieve the model that we've been working on in the last sections (recall that the model's name is now "MyNewModel_Update"). The following code example assumes that the model's ID number is 21. | |||
== | '''VBA|VB.NET''' | ||
{{APIComment|'Connect to the Synthesis repository and retrieve model ID#21.}} | |||
{{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository | |||
MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr10"}}) | |||
MyRepository.Project.SetCurrentProject(1) | |||
{{APIPrefix|Dim}} AModel {{APIPrefix|As}} cModel | |||
MyRepository.Model.GetModel(21) | |||
2. Use the <code>Reliability</code> method to calculate for the reliability at 100 hrs and the <code>MeanTime</code> method to return the mean time to failure. | |||
'''VBA|VB.NET''' | |||
{{APIComment|'Calculate the model's reliability at time = 100 hrs and mean time.}} | |||
{{APIPrefix|Dim}} Result1 {{APIPrefix|As}} Double | |||
{{APIPrefix|Dim}} Result2 {{APIPrefix|As}} Double | |||
Result1 = AModel.Reliability(100) | |||
Result2 = AModel.MeanTime() | |||
{{APIComment|'Display the output.}} | |||
MsgBox ({{APIString|"Reliability <nowiki>=</nowiki> "}} & Result1 & {{APIString|" Mean Time <nowiki>=</nowiki> "}} & Result2}}) | |||
3. Let's add confidence bounds calculations to the results. Use the <code>SetConfidenceLevel</code> method to specify 90% two-sided confidence bounds. | |||
'''VBA|VB.NET''' | |||
{{APIComment|'Set the confidence level to 90% two-sided bounds.}} | |||
{{APIComment|'Declare a string variable for any errors found during this method.}} | |||
{{APIPrefix|Dim}} ErrorMsg {{APIPrefix|As}} String | |||
{{APIPrefix|Call}} AModel.SetConfidenceLevel(0.9, ConfBoundsSides_TwoSidedBoth, False, ErrorMsg) | |||
{{APIComment|'Initiate new instances of the BoundsValues class.}} | |||
{{APIPrefix|Dim}} BResult1 {{APIPrefix|As}} BoundsValues | |||
{{APIPrefix|Dim}} BResult2 {{APIPrefix|As}} BoundsValues | |||
{{APIComment|'Calculate bounds for the reliability at 100 hrs and the mean time.}} | |||
BResult1 = AModel.Bounds_Reliability(100) | |||
BResult2 = AModel.Bounds_MeanTime() | |||
{{APIComment|'Display the results for the upper and lower confidence bounds.}} | |||
MsgBox ({{APIString|" Reliability: Upper bound: "}} & BResult1.Upper & {{APIString|", Lower bound: "}} & BResult1.Lower) | |||
MsgBox ({{APIString|" Mean Time: Upper bound: "}} & BResult2.Upper & {{APIString|", Lower bound: "}} & BResult2.Lower) | |||
===Verify It Works=== | |||
Below are the VBA and VB.NET code lists for this example. You can experiment with the code by retrieving published models from the repository and then comparing the results obtained by the API from the results obtained by the Quick Calculation Pad (QCP). | |||
'''VBA|VB.NET''' | |||
{{APIComment|'Connect to the Synthesis repository and retrieve model ID#21.}} | |||
{{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository | |||
MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr10"}}) | |||
MyRepository.Project.SetCurrentProject(1) | |||
{{APIPrefix|Dim}} AModel {{APIPrefix|As}} cModel | |||
MyRepository.Model.GetModel(21) | |||
{{APIComment|'Calculate the model's reliability at time = 100 hrs and mean time.}} | |||
{{APIPrefix|Dim}} Result1 {{APIPrefix|As}} Double | |||
{{APIPrefix|Dim}} Result2 {{APIPrefix|As}} Double | |||
Result1 = AModel.Reliability(100) | |||
Result2 = AModel.MeanTime() | |||
{{APIComment|'Display the output.}} | |||
MsgBox ({{APIString|"Reliability <nowiki>=</nowiki> "}} & Result1 & {{APIString|" Mean Time <nowiki>=</nowiki> "}} & Result2}}) | |||
{{APIComment|'Set the confidence level to 90% two-sided bounds.}} | |||
{{APIComment|'Declare a string variable for any errors found during this method.}} | |||
{{APIPrefix|Dim}} ErrorMsg {{APIPrefix|As}} String | |||
{{APIPrefix|Call}} AModel.SetConfidenceLevel(0.9, ConfBoundsSides_TwoSidedBoth, False, ErrorMsg) | |||
{{APIComment|'Initiate new instances of the BoundsValues class.}} | |||
{{APIPrefix|Dim}} BResult1 {{APIPrefix|As}} BoundsValues | |||
{{APIPrefix|Dim}} BResult2 {{APIPrefix|As}} BoundsValues | |||
{{APIComment|'Calculate bounds for the reliability at 100 hrs and the mean time.}} | |||
BResult1 = AModel.Bounds_Reliability(100) | |||
BResult2 = AModel.Bounds_MeanTime() | |||
{{APIComment|'Display the results for the upper and lower confidence bounds.}} | |||
MsgBox ({{APIString|" Reliability: Upper bound: "}} & BResult1.Upper & {{APIString|", Lower bound: "}} & BResult1.Lower) | |||
MsgBox ({{APIString|" Mean Time: Upper bound: "}} & BResult2.Upper & {{APIString|", Lower bound: "}} & BResult2.Lower) | |||
===Reference Links=== | |||
*[[CModel.Reliability|cModel.Reliability Method]] | |||
*[[CModel.MeanTime|cModel.MeanTime Method]] | |||
*[[CModel.SetConfidenceLevel|cModel.SetConfidenceLevel Method]] | |||
*[[CModel.Bounds_Reliability|cModel.Bounds_Reliability Method]] | |||
*[[CModel.Bounds_MeanTime|cModel.Bounds_MeanTime Method]] | |||
*[[BoundsValues Class]] |
Revision as of 18:43, 20 October 2015
<< Back to Quick Start Guide
Synthesis Resources 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 first use the GetAllProjects
method to 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) 'Display 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)
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 list for this example. 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) 'Display 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
- Repository Class
- NameIdPair Class
- Repository.ConnectToRepository Method
- Repository.DisconnectFromRepository Method
- Repository.Project.GetAllProjects Method
- Repository.Project.SetCurrentProject Method
- Repository.Project.GetCurrentProject Method
- Guide to Using Item IDs with the Synthesis API
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. Create a new module and begin again by connecting to the Synthesis repository and project.
VBA|VB.NET 'Connect to a Synthesis repository and set project ID#1 as the current 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)
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)
3. Use the AddModel
method to save the new model to the repository.
VBA 'Add the new model to the current project. Call MyRepository.Model.AddModel(AModel)
VB.NET
'Add the new model to the current project.
MyRepository.Model.AddModel(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. 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.
VBA Sub Main() 'Connect to a Synthesis repository and set project ID#1 as the current project. Dim MyRepository As New Repository MyRepository.ConnectToRepository("C:\RSRepository1.rsr10") MyRepository.Project.SetCurrentProject(1) '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) End Sub
VB.NET Sub Main() '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) '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) End Sub
Reference Links
- cModel Class
- cModel.SetModel Method
- cModel Constructor (VB.NET Only)
- Repository.Model.AddModel Method
- ModelTypeEnum Enumeration
- ModelCategoryEnum Enumeration
Part 3: Updating an Existing Resource
In this section, we'll update the properties of the model we've created in the previous section.
1. Create a new module and add code to connect to the Synthesis repository and project.
VBA|VB.NET 'Connect to a Synthesis repository and set project ID#1 as the current 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|VB.NET 'Specify the new model name and new value for beta. Dim ModelParams(1) As Double Amodel.Name = "MyNewModel_Updated" ModelParams(0) = 2
4. Use the UpdateModel
method to apply the changes to the model.
VBA 'Apply the changes to the model. Call MyRepository.Model.UpdateModel(AModel)
VB.NET
'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 Sub Main() 'Connect to a Synthesis repository and set project ID#1 as the current 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) End Sub
VB.NET Sub Main() '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) End Sub
Reference Links
Part 4: Calculating Results from Models
Models are used by other Synthesis resources to represent the reliability of a task, the duration of a task, the expected cost of a repair, and many other characteristics. In this section, we'll learn how to obtain calculated results from models.
1. Create a new module, and then add code to retrieve the model that we've been working on in the last sections (recall that the model's name is now "MyNewModel_Update"). The following code example assumes that the model's ID number is 21.
VBA|VB.NET 'Connect to the Synthesis repository and retrieve model ID#21. Dim MyRepository As New Repository MyRepository.ConnectToRepository("C:\RSRepository1.rsr10") MyRepository.Project.SetCurrentProject(1) Dim AModel As cModel MyRepository.Model.GetModel(21)
2. Use the Reliability
method to calculate for the reliability at 100 hrs and the MeanTime
method to return the mean time to failure.
VBA|VB.NET 'Calculate the model's reliability at time = 100 hrs and mean time. Dim Result1 As Double Dim Result2 As Double Result1 = AModel.Reliability(100) Result2 = AModel.MeanTime() 'Display the output. MsgBox ("Reliability = " & Result1 & " Mean Time = " & Result2}})
3. Let's add confidence bounds calculations to the results. Use the SetConfidenceLevel
method to specify 90% two-sided confidence bounds.
VBA|VB.NET 'Set the confidence level to 90% two-sided bounds. 'Declare a string variable for any errors found during this method. Dim ErrorMsg As String Call AModel.SetConfidenceLevel(0.9, ConfBoundsSides_TwoSidedBoth, False, ErrorMsg) 'Initiate new instances of the BoundsValues class. Dim BResult1 As BoundsValues Dim BResult2 As BoundsValues 'Calculate bounds for the reliability at 100 hrs and the mean time. BResult1 = AModel.Bounds_Reliability(100) BResult2 = AModel.Bounds_MeanTime() 'Display the results for the upper and lower confidence bounds. MsgBox (" Reliability: Upper bound: " & BResult1.Upper & ", Lower bound: " & BResult1.Lower) MsgBox (" Mean Time: Upper bound: " & BResult2.Upper & ", Lower bound: " & BResult2.Lower)
Verify It Works
Below are the VBA and VB.NET code lists for this example. You can experiment with the code by retrieving published models from the repository and then comparing the results obtained by the API from the results obtained by the Quick Calculation Pad (QCP).
VBA|VB.NET 'Connect to the Synthesis repository and retrieve model ID#21. Dim MyRepository As New Repository MyRepository.ConnectToRepository("C:\RSRepository1.rsr10") MyRepository.Project.SetCurrentProject(1) Dim AModel As cModel MyRepository.Model.GetModel(21) 'Calculate the model's reliability at time = 100 hrs and mean time. Dim Result1 As Double Dim Result2 As Double Result1 = AModel.Reliability(100) Result2 = AModel.MeanTime() 'Display the output. MsgBox ("Reliability = " & Result1 & " Mean Time = " & Result2}}) 'Set the confidence level to 90% two-sided bounds. 'Declare a string variable for any errors found during this method. Dim ErrorMsg As String Call AModel.SetConfidenceLevel(0.9, ConfBoundsSides_TwoSidedBoth, False, ErrorMsg) 'Initiate new instances of the BoundsValues class. Dim BResult1 As BoundsValues Dim BResult2 As BoundsValues 'Calculate bounds for the reliability at 100 hrs and the mean time. BResult1 = AModel.Bounds_Reliability(100) BResult2 = AModel.Bounds_MeanTime() 'Display the results for the upper and lower confidence bounds. MsgBox (" Reliability: Upper bound: " & BResult1.Upper & ", Lower bound: " & BResult1.Lower) MsgBox (" Mean Time: Upper bound: " & BResult2.Upper & ", Lower bound: " & BResult2.Lower)