|
|
(3 intermediate revisions by the same user not shown) |
Line 1: |
Line 1: |
| {{Template:API}}
| | ===DRAFTS=== |
| | |
| xxx -
| |
| | |
| The Synthesis API has a class for every type of Synthesis resource (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.
| |
| | |
| You will use the [[cModel Class|cModel]] class to create the resource and define its properties.
| |
| | |
| Repository class All other objects use the functions in this class to read or write data to the repository.
| |
| | |
| ==Tutorial: Add a New Synthesis Resource to a Repository== | |
| The following example demonstrates how to create a model resource. A discussion of the example follows.
| |
| | |
| '''VB.NET'''
| |
|
| |
| {{APIPrefix|Imports}} SynthesisAPI
| |
|
| |
| {{APIPrefix|Module}} Module
| |
| {{APIPrefix|Sub}} Main()
| |
|
| |
| {{APIComment|'Declare a new cModel object.}}
| |
| {{APIPrefix|Dim}} Amodel {{APIPrefix|As New}} cModel
| |
|
| |
| {{APIComment|'Define the model.}}
| |
| {{APIPrefix|Dim}} ModelType {{APIPrefix|As}} ModelTypeEnum
| |
| {{APIPrefix|Dim}} ModelCategory {{APIPrefix|As}} ModelCategoryEnum
| |
| {{APIPrefix|Dim}} ModelName {{APIPrefix|As}} String
| |
| {{APIPrefix|Dim}} ModelParams(1) {{APIPrefix|As}} Double
| |
|
| |
| ModelType = ModelTypeEnum.Weibull2
| |
| ModelCategory = ModelCategoryEnum.Reliability
| |
| ModelName = {{APIString|"MyNewModel"}}
| |
| ModelParams(0) = 1
| |
| ModelParams(1) = 100
| |
|
| |
| AModel.SetModel(ModelType, ModelCategory, ModelName, ModelParams)
| |
|
| |
| {{APIComment|'Connect to a Synthesis repository and project.}}
| |
| {{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository
| |
| MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr10"}})
| |
| MyRepository.Project.SetCurrentProject(1)
| |
|
| |
| {{APIComment|'Send the model to the project.}}
| |
| MyRepository.Model.AddModel(AModel)
| |
|
| |
| {{APIPrefix|End Sub}}
| |
| {{APIPrefix|End Module}}
| |
| | |
| ==Discussion==
| |
| To create a model resource, use [[cModel Class|cModel]]
| |
| | |
| | |
| =============
| |
| | |
| 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|Dim}} Amodel {{APIPrefix|As New}} cModel
| |
|
| |
| {{APIComment|'Fill the properties.}}
| |
| {{APIPrefix|Dim}} ModelType {{APIPrefix|As}} ModelTypeEnum
| |
| {{APIPrefix|Dim}} ModelCategory {{APIPrefix|As}} ModelCategoryEnum
| |
| {{APIPrefix|Dim}} ModelName {{APIPrefix|As}} String
| |
| {{APIPrefix|Dim}} ModelParams(1) {{APIPrefix|As}} Double
| |
|
| |
| ModelType = ModelTypeEnum_Weibull2
| |
| ModelCategory = ModelCategoryEnum_Reliability
| |
| ModelName = {{APIString|"MyNewModel"}}
| |
| ModelParams(0) = 1
| |
| ModelParams(1) = 100
| |
|
| |
| {{APIComment|'Define the model.}}
| |
| {{APIPrefix|Call}} AModel.SetModel(ModelType, ModelCategory, ModelName, ModelParams)
| |
| | |
| '''VB.NET'''
| |
|
| |
| {{APIComment|'Declare a new instance of the cModel class. You can use an in-line parameter list to define the model.}}
| |
| {{APIPrefix|Dim}} AModel {{APIPrefix|As New}} cModel(ModelTypeEnum.Weibull2, ModelCategoryEnum.Reliability, {{APIString|"MyNewModel"}}, 1, 100)
| |
|
| |
| 3. Use the <code>AddModel</code> method to save the new model to the repository.
| |
| | |
| '''VBA'''
| |
|
| |
| {{APIComment|'Add the new model to the current project.}}
| |
| {{APIPrefix|Call}} MyRepository.Model.AddModel(AModel)
| |
| | |
| '''VB.NET'''
| |
|
| |
| {{APIComment|'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()
| |
|
| |
| {{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}} ModelCategory {{APIPrefix|As}} ModelCategoryEnum
| |
| {{APIPrefix|Dim}} ModelName {{APIPrefix|As}} String
| |
| {{APIPrefix|Dim}} ModelParams(1) {{APIPrefix|As}} Double
| |
|
| |
| ModelType = ModelTypeEnum_Weibull2
| |
| ModelCategory = ModelCategoryEnum_Reliability
| |
| ModelName = {{APIString|"MyNewModel"}}
| |
| ModelParams(0) = 1
| |
| 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'''
| |
|
| |
| {{APIPrefix|Imports}} SynthesisAPI
| |
|
| |
| {{APIPrefix|Public Class}} Form1
| |
| {{APIPrefix|Private Sub}} Button1_Click(sender {{APIPrefix|As}} System.Object, e {{APIPrefix|As}} System.EventArgs) {{APIPrefix|Handles}} Button1.Click
| |
|
| |
| {{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. You can use an in-line parameter list to define the model.}}
| |
| {{APIPrefix|Dim}} AModel {{APIPrefix|As New}} cModel(ModelTypeEnum.Weibull2, ModelCategoryEnum.Reliability, {{APIString|"MyNewModel"}}, 1, 100)
| |
|
| |
| {{APIComment|'Add the new model to the current project.}}
| |
| MyRepository.Model.AddModel(AModel)
| |
|
| |
| {{APIPrefix|End Sub}}
| |
| {{APIPrefix|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 <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===
| |
| To learn more, see the reference documentation for the classes and methods discussed in this tutorial:
| |
| | |
| *[[CModel Class|cModel Class]]
| |
| *[[CModel.SetModel|cModel.SetModel Method]]
| |
| *[[CModel_Constructors|cModel Constructor (VB.NET Only)]]
| |
| *[[Repository.Model.AddModel|Repository.Model.AddModel Method]]
| |
| | |
| | |
| | |
| | |
| | |
| '''<span style="color:#808080;">Next: [[Edit Existing Synthesis Resources|Edit Existing Synthesis Resources >>]]</span>'''
| |