Add New Synthesis Resources to a Repository: Difference between revisions

From ReliaWiki
Jump to navigation Jump to search
(Created page with '{{Template:API}} <div style="border:1px solid #AAA; background:#f9f9f9; border-radius:10px; width:auto; margin:0 0 1em 1em; padding:1em; float:right;"> <nowiki><<</nowiki> [[API …')
 
No edit summary
 
(10 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Template:API}}
{{Template:API}}{{Template:BacktoPrevPage}}
<div style="border:1px solid #AAA; background:#f9f9f9; border-radius:10px; width:auto; margin:0 0 1em 1em; padding:1em; float:right;">
<nowiki><<</nowiki> [[API Tutorials|Back to API Tutorials]]


'''Basics'''
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.
#[[Connect or Disconnect from a Synthesis Repository]]
#Add New Synthesis Resources to a Repository
#[[APISynthesisResourcesTutorial3|Update an Existing Resource]]
#[[APISynthesisResourcesTutorial4|Calculate Results from a Model]]
</div>


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


==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 [[Add_New_Synthesis_Resources_to_a_Repository/VBA|here]].


 
'''VB.NET'''
 
 
  {{APIPrefix|Imports}} SynthesisAPI
 
 
==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.
 
  {{APIComment|'Connect to the Synthesis repository and set project ID#1 as the current project.}}
  {{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository
  MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr10"}})
  MyRepository.Project.SetCurrentProject(1)
 
2. Use the constructor in the <code>cModel</code> class to create a model. Then use the <code>SetModel</code> 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'''
   
   
  {{APIComment|'Declare a new instance of the cModel class.}}
{{APIPrefix|Module}} Module1
  {{APIPrefix|Sub}} Main()
 
  {{APIComment|'Declare a new cModel object.}}
   {{APIPrefix|Dim}} Amodel {{APIPrefix|As New}} cModel
   {{APIPrefix|Dim}} Amodel {{APIPrefix|As New}} cModel
   
   
  {{APIComment|'Fill the properties.}}
  {{APIComment|'Define the model.}}
  {{APIPrefix|Dim}} ModelCategory {{APIPrefix|As}} ModelCategoryEnum
   {{APIPrefix|Dim}} ModelType {{APIPrefix|As}} ModelTypeEnum
   {{APIPrefix|Dim}} ModelType {{APIPrefix|As}} ModelTypeEnum
  {{APIPrefix|Dim}} ModelCategory {{APIPrefix|As}} ModelCategoryEnum
   {{APIPrefix|Dim}} ModelName {{APIPrefix|As}} String
   {{APIPrefix|Dim}} ModelName {{APIPrefix|As}} String
   {{APIPrefix|Dim}} ModelParams(1) {{APIPrefix|As}} Double
   {{APIPrefix|Dim}} ModelParams(1) {{APIPrefix|As}} Double
   
   
   ModelType = ModelTypeEnum_Weibull2
   ModelCategory = ModelCategoryEnum.Reliability
   ModelCategory = ModelCategoryEnum_Reliability
   ModelType = ModelTypeEnum.Weibull2
   ModelName = {{APIString|"MyNewModel"}}
   ModelName = {{APIString|"MyNewModel"}}
   ModelParams(0) = 1
   ModelParams(0) = 1
   ModelParams(1) = 100
   ModelParams(1) = 100
 
  AModel.SetModel(ModelType, ModelCategory, ModelName, ModelParams)
   
   
  {{APIComment|'Define the model.}}
{{APIComment|'Connect to a Synthesis repository and project.}}
   {{APIPrefix|Call}} AModel.SetModel(ModelType, ModelCategory, ModelName, ModelParams)
   {{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository
 
  MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr11"}}){{APIComment|'Replace with name and path to test repository.}}
'''VB.NET'''
  MyRepository.Project.SetCurrentProject(1){{APIComment|'Replace with the object ID of test project.}}
   
   
  {{APIComment|'Declare a new instance of the cModel class. You can use an in-line parameter list to define the model.}}
  {{APIComment|'Send the model to the project.}}
   {{APIPrefix|Dim}} AModel {{APIPrefix|As New}} cModel(ModelTypeEnum.Weibull2, ModelCategoryEnum.Reliability, {{APIString|"MyNewModel"}}, 1, 100)
   MyRepository.Model.AddModel(AModel)
   
   
3. Use the <code>AddModel</code> method to save the new model to the repository.
  {{APIPrefix|End Sub}}
{{APIPrefix|End Module}}


'''VBA'''
===Discussion===
The [[cModel Class|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.
  {{APIComment|'Add the new model to the current project.}}
 
   {{APIPrefix|Call}} MyRepository.Model.AddModel(AModel)
  {{APIComment|'Declare a new cModel object.}}
   {{APIPrefix|Dim}} Amodel {{APIPrefix|As New}} cModel


'''VB.NET'''
The next section of code sets the desired properties for the model. The [[ModelCategoryEnum_Enumeration|ModelCategoryEnum]] type specifies how the model can be used; whether it represents a reliability or probability of failure, or cost model, etc. The [[ModelTypeEnum_Enumeration|ModelTypeEnum]] type specifies the model type (e.g., distribution, constant, dynamic). The ModelParams type is an array of the model's  parameters.
{{APIComment|'Add the new model to the current project.}}
  MyRepository.Model.AddModel(AModel)


===Test the Code===
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."
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'''
  {{APIComment|'Define the model.}}
   {{APIPrefix|Dim}} ModelCategory {{APIPrefix|As}} ModelCategoryEnum
Sub Main()
 
  {{APIComment|'Connect to the Synthesis repository and set project ID#1 as the current project.}}
   {{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository
  MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr10"}})
  MyRepository.Project.SetCurrentProject(1)
{{APIComment|'Declare a new instance of the cModel class.}}
  {{APIPrefix|Dim}} Amodel {{APIPrefix|As New}} cModel
{{APIComment|'Fill the properties.}}
   {{APIPrefix|Dim}} ModelType {{APIPrefix|As}} ModelTypeEnum
   {{APIPrefix|Dim}} ModelType {{APIPrefix|As}} ModelTypeEnum
  {{APIPrefix|Dim}} ModelCategory {{APIPrefix|As}} ModelCategoryEnum
   {{APIPrefix|Dim}} ModelName {{APIPrefix|As}} String
   {{APIPrefix|Dim}} ModelName {{APIPrefix|As}} String
   {{APIPrefix|Dim}} ModelParams(1) {{APIPrefix|As}} Double
   {{APIPrefix|Dim}} ModelParams(1) {{APIPrefix|As}} Double
   
   
   ModelType = ModelTypeEnum_Weibull2
   ModelCategory = ModelCategoryEnum.Reliability
   ModelCategory = ModelCategoryEnum_Reliability
   ModelType = ModelTypeEnum.Weibull2
   ModelName = {{APIString|"MyNewModel"}}
   ModelName = {{APIString|"MyNewModel"}}
   ModelParams(0) = 1
   ModelParams(0) = 1
   ModelParams(1) = 100
   ModelParams(1) = 100
  {{APIComment|'Define the model.}}
  {{APIPrefix|Call}} AModel.SetModel(ModelType, ModelCategory, ModelName, ModelParams)
{{APIComment|'Add the new model to the current project.}}
  {{APIPrefix|Call}} MyRepository.Model.AddModel(AModel)
End Sub


'''VB.NET'''
After setting the properties, use the [[CModel.SetModel|SetModel]] method to associate the properties with the object.
  AModel.SetModel(ModelType, ModelCategory, ModelName, ModelParams)
{{APIPrefix|Imports}} SynthesisAPI
 
Next, we'll save the model to a Synthesis repository.
{{APIPrefix|Public Class}} Form1
 
  {{APIPrefix|Private Sub}} Button1_Click(sender {{APIPrefix|As}} System.Object, e {{APIPrefix|As}} System.EventArgs) {{APIPrefix|Handles}} Button1.Click
The [[Repository Class|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 [[Connect_or_Disconnect_from_a_Synthesis_Repository|this tutorial]].)
 
 
  {{APIComment|'Connect to the Synthesis repository and set project ID#1 as the current project.}}
{{APIComment|'Connect to a Synthesis repository and 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.rsr11"}}){{APIComment|'Replace with name and path to test repository.}}
    MyRepository.Project.SetCurrentProject(1)
  MyRepository.Project.SetCurrentProject(1){{APIComment|'Replace with the object ID of test project.}}
 
  {{APIComment|'Declare a new instance of the cModel class. You can use an in-line parameter list to define the model.}}
Now that we have access to a project, we can use the [[Repository.Model.AddModel|Model.AddModel]] method to save the model to the project.  
    {{APIPrefix|Dim}} AModel {{APIPrefix|As New}} cModel(ModelTypeEnum.Weibull2, ModelCategoryEnum.Reliability, {{APIString|"MyNewModel"}}, 1, 100)
 
   
  {{APIComment|'Send the model to the project.}}
  {{APIComment|'Add the new model to the current project.}}
  MyRepository.Model.AddModel(AModel)
    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.)
  {{APIPrefix|End Sub}}
 
{{APIPrefix|End Class}}
 
==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|cURD]] class, and then use the [[Repository.URD.AddURD|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:


===Notes===
    {{APIPrefix|Dim}} AModel {{APIPrefix|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 to the project. For example, to create a Universal Reliability Definition (URD) resource, you would use the methods and properties in the <code>[[CURD_Class|cURD]]</code> class, and then use the <code>[[Repository.URD.AddURD|Repository.URD.AddURD]]</code> method to save the URD to the project.


===References===
===References===
To learn more, see the reference documentation for the classes and methods discussed in this section:
*[[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]]


Line 142: Line 110:




'''<span style="color:#808080;">Next: [[APISynthesisResourcesTutorial3|Update an Existing Resource >>]]</span>'''
'''<span style="color:#808080;">Next Tutorial: [[Edit Existing Synthesis Resources|Edit Existing Synthesis Resources >>]]</span>'''

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