APISynthesisResourcesTutorial3: Difference between revisions
Kate Racaza (talk | contribs) mNo edit summary |
Kate Racaza (talk | contribs) mNo edit summary |
||
Line 46: | Line 46: | ||
AModel = MyRepository.Model.GetModel(21) | 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. | 3. Let's update the model's properties. Use the following code to add a description and part number for the model. | ||
Revision as of 16:33, 22 October 2015
Synthesis Resources Tutorial
- Connect to a Synthesis Repository and Project
- Create a New Synthesis Resource
- Update an Existing Resource
- 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: