APISynthesisResourcesTutorial3

From ReliaWiki
Revision as of 16:08, 22 October 2015 by Kate Racaza (talk | contribs) (Created page with '{{DISPLAYTITLE:Synthesis Resources Tutorial}}{{Template:InProgress}}{{Template:API}} <div style="border:1px solid #AAA; background:#f9f9f9; border-radius:10px; width:auto; margin…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Template:InProgress

APIWiki.png


<< Back to Quick Start Guide

Synthesis Resources Tutorial

  1. Connect to a Synthesis Repository and Project
  2. Create a New Synthesis Resource
  3. Update an Existing Resource
  4. Calculate Results from a Model

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






Part 3: Update an Existing Resource

1. Create a new module and add code to connect to the Synthesis repository and project.

VBA|VB.NET

 'Connect to the 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 the 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. Let's update the model's properties. Use the following code to add a description and part number for the model.

VBA|VB.NET

  'Add a description and part number for the model. 
  Amodel.ItemDescription = "A specific type of light bulb."
  Amodel.ItemPartNumber = "PN5461"   

4. Let's also update the model's definition by changing its name to "MyNewModel_Updated" and the values of beta = 2 and eta = 150. Use the SetModel method to define the model. In VB.NET, you can use an in-line parameter list to define the values of the parameters.

VBA

 'Define a new model name and values for beta and eta. 
  Dim ModelParams(1) As Double     
  ModelParams(0) = 2
  ModelParams(1) = 150
  
  Call AModel.SetModel(ModelTypeEnum_Weibull2, ModelCategoryEnum_Reliability, "MyNewModel_Updated", ModelParams)
VB.NET

 'Define a new model name and values for beta and eta. 
  AModel.SetModel(ModelTypeEnum.Weibull2, ModelCategoryEnum.Reliability, "MyNewModel_Updated", New Double() {2, 150})

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

Test the Code

Below are the VBA and VB.NET code lists for this example. On the Debug menu, click Start to run the application, and then check the project's Resource Manager to verify that the model's name has been changed to "MyNewModel_Updated" and that beta = 2 and eta = 150.

VBA

Sub Main()

 'Connect to the 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)

  'Add a description and part number for the model. 
  Amodel.ItemDescription = "A specific type of light bulb."
  Amodel.ItemPartNumber = "PN5461"   

 'Define a new model name and values for beta and eta. 
  Dim ModelParams(1) As Double     
  ModelParams(0) = 2
  ModelParams(1) = 150
  
  Call AModel.SetModel(ModelTypeEnum_Weibull2, ModelCategoryEnum_Reliability, "MyNewModel_Updated", ModelParams)
 
 '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)

  'Add a description and part number for the model. 
  Amodel.ItemDescription = "A specific type of light bulb."
  Amodel.ItemPartNumber = "PN5461"   
  
 'Define a new model name and values for beta and eta. 
  AModel.SetModel(ModelTypeEnum.Weibull2, ModelCategoryEnum.Reliability, "MyNewModel_Updated", New Double() {2, 150})

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

End Sub

References

To learn more, see the reference documentation for the methods discussed in this section:



Next: Calculate Results from a Model>>