Add New Synthesis Resources to a Repository: Difference between revisions

From ReliaWiki
Jump to navigation Jump to search
No edit summary
Line 131: Line 131:


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


*[[CModel Class|cModel Class]]
*[[CModel Class|cModel Class]]

Revision as of 16:32, 17 February 2016

APIWiki.png


<< Back to API Tutorials

Basics

  1. Connect or Disconnect from a Synthesis Repository
  2. Add New Synthesis Resources to a Repository
  3. Edit Existing Synthesis Resources
  4. Calculate Results from a Model

In this tutorial, you'll learn how to create a Synthesis resource and add it to a Synthesis repository. We'll use the cModel class for this example.






Create a New Model

1. Create a new module and begin by connecting to a Synthesis repository and project. The following code assumes that a standard repository called "RSRepository1.rsr10" exists in the C drive.

 '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 constructor in the cModel class to create a model. Then use the SetModel method to define the model. Note that for VB.NET, you can use the parameterized contructor to create and define the model.

For this example, let's create a 2-parameter Weibull reliability model with beta 1 and eta 100. The model name is, "MyNewModel."

VBA

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

 'Fill the properties. 
  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

  'Define the model. 
  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 complete code lists for this example. To test them, run the application by clicking Start on the Debug menu. Then in the Synthesis repository, open the project’s Resource Manager (Project > Synthesis> Resource Manager) and 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

 'Fill the properties. 
  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

  'Define the model. 
  Call AModel.SetModel(ModelType, ModelCategory, ModelName, ModelParams)

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

End Sub
VB.NET

Imports SynthesisAPI 

Public Class Form1
  Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
 
   '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
End Class

Notes

Now that you've learned how to add a model resource to a project, try adding other types of Synthesis resources to the project. For example, to create a Universal Reliability Definition (URD) resource, you would use the methods and properties in the cURD class, and then use the Repository.URD.AddURD method to save the URD to the project.

References

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



Next: Edit Existing Synthesis Resources >>