Talk:Add New Synthesis Resources to a Repository/Notes

From ReliaWiki
Revision as of 18:55, 27 April 2016 by Kate Racaza (talk | contribs)
Jump to navigation Jump to search

The Synthesis API object library has a class for every type of Synthesis resource (e.g., models, tasks, actions, etc.). In this tutorial, you'll learn how to use the API to create a model resource, define its properties and then save it to a Synthesis repository. A similar approach can be used to create and save other types of Synthesis resources.

Tutorial: Add a New Synthesis Resource to a Repository

The following example demonstrates how to create a model resource and save it to Synthesis repository. A discussion of the example follows.

A VBA version of the code sample is available here.

VB.NET

Imports SynthesisAPI 

Module Module
  Sub Main()
 
 'Declare a new cModel object. 
  Dim Amodel As New cModel

 'Define the model. 
  Dim ModelCategory As ModelCategoryEnum
  Dim ModelType As ModelTypeEnum
  Dim ModelName As String
  Dim ModelParams(1) As Double

  ModelCategory = ModelCategoryEnum.Reliability
  ModelType = ModelTypeEnum.Weibull2
  ModelName = "MyNewModel"
  ModelParams(0) = 1
  ModelParams(1) = 100
 
  AModel.SetModel(ModelType, ModelCategory, ModelName, ModelParams)

 'Connect to a Synthesis repository and project. 
  Dim MyRepository As New Repository
  MyRepository.ConnectToRepository("C:\RSRepository1.rsr10")
  MyRepository.Project.SetCurrentProject(1)

 'Send the model to the project. 
  MyRepository.Model.AddModel(AModel)

  End Sub
End Module


Discussion

The cModel class represents a Synthesis model resource. Other Synthesis resources, such as actions, URDs, etc., are similarly named (e.g., cAction, cURD, etc.) and can be created using the same approach.

 'Declare a new cModel object. 
  Dim Amodel As New cModel

The next section of code sets the desired properties for the model. In this case, we want it to be a reliability model that follows a 2-parameter Weibull distribution with beta = 1 and eta = 100. We name it "MyNewModel."

 'Define the model. 
  Dim ModelCategory As ModelCategoryEnum
  Dim ModelType As ModelTypeEnum
  Dim ModelName As String
  Dim ModelParams(1) As Double

  ModelCategory = ModelCategoryEnum.Reliability
  ModelType = ModelTypeEnum.Weibull2
  ModelName = "MyNewModel"
  ModelParams(0) = 1
  ModelParams(1) = 100

After setting the properties, use the SetModel method to associate the properties with the model object.

  AModel.SetModel(ModelType, ModelCategory, ModelName, ModelParams)

When you are satisfied with the model, you can then choose to save it to a Synthesis repository.

The Repository class represents a Synthesis repository. All other objects in the Synthesis API object library use the functions in the Repository class to read or write data to a repository. The example below demonstrates how to connect to a standard repository and open one of its projects (for a full discussion, see this tutorial.)

 'Connect to a Synthesis repository and project. 
  Dim MyRepository As New Repository
  MyRepository.ConnectToRepository("C:\RSRepository1.rsr10")
  MyRepository.Project.SetCurrentProject(1)

You can then use the Model.AddModel method to save the model to the project. Note that for secure databases, you must have the necessary read/write permissions to perform this command.

 'Send the model to the project. 
  MyRepository.Model.AddModel(AModel)

To verify the result, open the repository in any Synthesis desktop application, then 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.)


Notes

The .NET version of the Synthesis API library includes parameterized constructors for most classes. This allows you to simplify, for example, the declaration of a cModel object to:

   Dim AModel As New cModel(ModelType, ModelCategory, ModelName, ModelParams())

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


References



Next Tutorial: Edit Existing Synthesis Resources >>