APISynthesisResourcesTutorial3: Difference between revisions

From ReliaWiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
Line 10: Line 10:
</div>
</div>


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




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 edit the model's name, description and part number.


  '''VBA|VB.NET'''
  '''VBA|VB.NET'''
   
   
   {{APIComment|'Add a description and part number for the model.}}
   {{APIComment|'Edit the model's name, description and part number.}}
  Amodel.Name = {{APIString|"MyNewModel_Updated"}}
   Amodel.ItemDescription = {{APIString|"A specific type of light bulb."}}
   Amodel.ItemDescription = {{APIString|"A specific type of light bulb."}}
   Amodel.ItemPartNumber = {{APIString|"PN5461"}}   
   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.
4. Use the <code>UpdateModel</code> method to apply the changes to the model.
 
'''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'''
  '''VBA'''
Line 83: Line 68:


===Test the Code===
===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.
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 properties have been updated. (You may need to display the '''Description''' and '''Part Number''' columns of the Resource Manager by right-clicking a column header and choosing '''Select Columns'''.)


  '''VBA'''
  '''VBA'''
Line 98: Line 83:
   {{APIPrefix|Set}} AModel = MyRepository.Model.GetModel(21)
   {{APIPrefix|Set}} AModel = MyRepository.Model.GetModel(21)
   
   
   {{APIComment|'Add a description and part number for the model.}}
   {{APIComment|'Edit the model's name, description and part number.}}
  Amodel.Name = {{APIString|"MyNewModel_Updated"}}
   Amodel.ItemDescription = {{APIString|"A specific type of light bulb."}}
   Amodel.ItemDescription = {{APIString|"A specific type of light bulb."}}
   Amodel.ItemPartNumber = {{APIString|"PN5461"}}   
   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.}}
  {{APIComment|'Apply the changes to the model.}}
Line 127: Line 106:
   AModel = MyRepository.Model.GetModel(21)
   AModel = MyRepository.Model.GetModel(21)
   
   
   {{APIComment|'Add a description and part number for the model.}}
   {{APIComment|'Edit the model's name, description and part number.}}
  Amodel.Name = {{APIString|"MyNewModel_Updated"}}
   Amodel.ItemDescription = {{APIString|"A specific type of light bulb."}}
   Amodel.ItemDescription = {{APIString|"A specific type of light bulb."}}
   Amodel.ItemPartNumber = {{APIString|"PN5461"}}   
   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.}}
  {{APIComment|'Apply the changes to the model.}}

Revision as of 22:30, 22 October 2015

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.






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 edit the model's name, description and part number.

VBA|VB.NET

  'Edit the model's name, description and part number. 
  Amodel.Name = "MyNewModel_Updated"
  Amodel.ItemDescription = "A specific type of light bulb."
  Amodel.ItemPartNumber = "PN5461"   

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)

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 properties have been updated. (You may need to display the Description and Part Number columns of the Resource Manager by right-clicking a column header and choosing Select Columns.)

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)

  'Edit the model's name, description and part number. 
  Amodel.Name = "MyNewModel_Updated"
  Amodel.ItemDescription = "A specific type of light bulb."
  Amodel.ItemPartNumber = "PN5461"   
 
 'Apply the changes to the model. 
  Call MyRepository.Model.UpdateModel(AModel)

End Sub
VB.NET

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
  AModel = MyRepository.Model.GetModel(21)

  'Edit the model's name, description and part number. 
  Amodel.Name = "MyNewModel_Updated"
  Amodel.ItemDescription = "A specific type of light bulb."
  Amodel.ItemPartNumber = "PN5461"   

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