APISynthesisResourcesTutorial2: Difference between revisions

From ReliaWiki
Jump to navigation Jump to search
(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…')
 
mNo edit summary
Line 110: Line 110:
  Sub Main()
  Sub Main()
    
    
  {{APIComment|'Connect to the Synthesis repository and set the first available project in the repository as the active project.}}
  {{APIComment|'Connect to the 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"}})

Revision as of 16:40, 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

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.






Part 2: Create a New Synthesis Resource

1. Create a new module and begin again by connecting 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. 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. 
  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 AModel 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)

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. 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. (You may need to click the Refresh or Show All command to update the display.)

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)

 'Declare a new instance of the cModel class. 
  Dim Amodel As New cModel

 'Define the model. 
  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 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)

 'Declare a new instance of the cModel class. You can use an in-line parameter list to define the model. 
  Dim AModel As New cModel(ModelTypeEnum.Weibull2, ModelCategoryEnum.Reliability, "MyNewModel", 1, 100)

 'Add the new model to the current project. 
  MyRepository.Model.AddModel(AModel)

End Sub

References

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



Next: Update an Existing Resource >>