Difference between revisions of "Add New Synthesis Resources to a Repository"

From ReliaWiki
Jump to navigation Jump to search
 
Line 103: Line 103:
 
*[[CModel Class|cModel Class]]
 
*[[CModel Class|cModel Class]]
 
**[[CModel.SetModel|cModel.SetModel Method]]
 
**[[CModel.SetModel|cModel.SetModel Method]]
**[[CModel_Constructors|cModel Constructor (VB.NET Only)]]
+
**[[CModel_Constructors|cModel Constructor (.NET Only)]]
 
*[[Repository.Model.AddModel|Repository.Model.AddModel Method]]
 
*[[Repository.Model.AddModel|Repository.Model.AddModel Method]]
  

Latest revision as of 15:12, 3 August 2017

APIWiki.png


<< Back to Tutorials Main Page

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.


Prerequisites

Before you begin, please create a Synthesis repository for testing purposes.


Tutorial: Add a New Synthesis Resource to a Repository

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

A VBA version of the code sample is available here.

VB.NET

Imports SynthesisAPI 

Module Module1
  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.rsr11") 'Replace with name and path to test repository. 
  MyRepository.Project.SetCurrentProject(1) 'Replace with the object ID of test project. 

 '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. The ModelCategoryEnum type specifies how the model can be used; whether it represents a reliability or probability of failure, or cost model, etc. The ModelTypeEnum type specifies the model type (e.g., distribution, constant, dynamic). The ModelParams type is an array of the model's parameters.

In this case, we want the object 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 object.

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

Next, we'll save the model to a Synthesis repository.

The Repository class represents a Synthesis repository. This class contains all the functions that enable you 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. It assumes that a standard repository called "RSRepository1.rsr11" exists in the C drive (for a full discussion on the method, see this tutorial.)

 'Connect to a Synthesis repository and project. 
  Dim MyRepository As New Repository
  MyRepository.ConnectToRepository("C:\RSRepository1.rsr11") 'Replace with name and path to test repository. 
  MyRepository.Project.SetCurrentProject(1) 'Replace with the object ID of test project. 

Now that we have access to a project, we can use the Model.AddModel method to save the model to the project.

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


Notes

In secure databases, you must have the necessary permissions to read/write to a project and create/edit resources.

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.

Parameterized Constructors

Parameterized constructors are available in the .NET version of the Synthesis API object library. This allows you to simplify, for example, the declaration of a cModel object to:

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

References



Next Tutorial: Edit Existing Synthesis Resources >>