APISynthesisResourcesTutorial3: Difference between revisions

From ReliaWiki
Jump to navigation Jump to search
mNo edit summary
(Redirected page to API Tutorials)
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{DISPLAYTITLE:Synthesis Resources Tutorial}}{{Template:InProgress}}{{Template:API}}
#REDIRECT [[API_Tutorials]]
<div style="border:1px solid #AAA; background:#f9f9f9; border-radius:10px; width:auto; margin:0 0 1em 1em; padding:1em; float:right;">
<nowiki><<</nowiki> [[APIQuickStartGuide|Back to Quick Start Guide]]
 
'''Synthesis Resources Tutorial'''
#[[APISynthesisResourcesTutorial|Connect to a Synthesis Repository and Project]]
#[[APISynthesisResourcesTutorial2|Create a New Synthesis Resource]]
#Update an Existing Resource
#[[APISynthesisResourcesTutorial4|Calculate Results from a Model]]
</div>
 
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'''
{{APIComment|'Connect to the 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)
 
2. Next, use the <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.
 
'''VBA'''
{{APIComment|'Retrieve the model with ID# 21 from the repository.}}
  {{APIPrefix|Dim}} Amodel {{APIPrefix|As New}} cModel
  {{APIPrefix|Set}} AModel = MyRepository.Model.GetModel(21)
 
'''VB.NET'''
{{APIComment|'Retrieve the model with ID# 21 from the repository.}}
  {{APIPrefix|Dim}} Amodel {{APIPrefix|As New}} cModel
  AModel = MyRepository.Model.GetModel(21)
 
<div id="Anchor1"></div>
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'''
  {{APIComment|'Add a description and part number for the model.}}
  Amodel.ItemDescription = {{APIString|"A specific type of light bulb."}}
  Amodel.ItemPartNumber = {{APIString|"PN5461"}} 
 
4. Let's also update the model's definition by changing its name to "MyNewModel_Updated" and the values of beta &#61; 2 and eta &#61; 150. Use the <code>SetModel</code> method to define the model. In VB.NET, you can use an in-line parameter list to define the values of the parameters.
 
'''VBA'''
{{APIComment|'Define a new model name and values for beta and eta.}}
  {{APIPrefix|Dim}} ModelParams(1) {{APIPrefix|As}} Double   
  ModelParams(0) = 2
  ModelParams(1) = 150
 
  {{APIPrefix|Call}} AModel.SetModel(ModelTypeEnum_Weibull2, ModelCategoryEnum_Reliability, {{APIString|"MyNewModel_Updated"}}, ModelParams)
 
'''VB.NET'''
{{APIComment|'Define a new model name and values for beta and eta.}}
  AModel.SetModel(ModelTypeEnum.Weibull2, ModelCategoryEnum.Reliability, {{APIString|"MyNewModel_Updated"}}, {{APIPrefix|New Double}}() {2, 150})
5. 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)
 
'''VB.NET'''
 
{{APIComment|'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 &#61; 2 and eta &#61; 150.
 
'''VBA'''
Sub Main()
{{APIComment|'Connect to the 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|'Retrieve the model with ID# 21 from the repository.}}
  {{APIPrefix|Dim}} Amodel {{APIPrefix|As New}} cModel
  {{APIPrefix|Set}} AModel = MyRepository.Model.GetModel(21)
  {{APIComment|'Add a description and part number for the model.}}
  Amodel.ItemDescription = {{APIString|"A specific type of light bulb."}}
  Amodel.ItemPartNumber = {{APIString|"PN5461"}} 
{{APIComment|'Define a new model name and values for beta and eta.}}
  {{APIPrefix|Dim}} ModelParams(1) {{APIPrefix|As}} Double   
  ModelParams(0) = 2
  ModelParams(1) = 150
 
  {{APIPrefix|Call}} AModel.SetModel(ModelTypeEnum_Weibull2, ModelCategoryEnum_Reliability, {{APIString|"MyNewModel_Updated"}}, ModelParams)
 
{{APIComment|'Apply the changes to the model.}}
  {{APIPrefix|Call}} MyRepository.Model.UpdateModel(AModel)
End Sub
 
'''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|'Retrieve the model with ID# 21 from the repository.}}
  {{APIPrefix|Dim}} Amodel {{APIPrefix|As New}} cModel
  AModel = MyRepository.Model.GetModel(21)
  {{APIComment|'Add a description and part number for the model.}}
  Amodel.ItemDescription = {{APIString|"A specific type of light bulb."}}
  Amodel.ItemPartNumber = {{APIString|"PN5461"}} 
 
{{APIComment|'Define a new model name and values for beta and eta.}}
  AModel.SetModel(ModelTypeEnum.Weibull2, ModelCategoryEnum.Reliability, {{APIString|"MyNewModel_Updated"}}, {{APIPrefix|New Double}}() {2, 150})
{{APIComment|'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:
 
*[[Repository.Model.GetModel|Repository.Model.GetModel Method]]
*[[Repository.Model.UpdateModel|Repository.Model.UpdateModel Method]]
 
 
 
 
'''<span style="color:#808080;">Next: [[APISynthesisResourcesTutorial4|Calculate Results from a Model >>]]</span>'''

Latest revision as of 23:48, 9 February 2016

Redirect to: