|
|
Line 1: |
Line 1: |
| 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.
| | ===DRAFTS=== |
| | |
| ==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
| |
|
| |
| {{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}} ModelCategory {{APIPrefix|As}} ModelCategoryEnum
| |
| {{APIPrefix|Dim}} ModelType {{APIPrefix|As}} ModelTypeEnum
| |
| {{APIPrefix|Dim}} ModelName {{APIPrefix|As}} String
| |
| {{APIPrefix|Dim}} ModelParams(1) {{APIPrefix|As}} Double
| |
|
| |
| ModelCategory = ModelCategoryEnum.Reliability
| |
| ModelType = ModelTypeEnum.Weibull2
| |
| 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===
| |
| 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|'Declare a new cModel object.}}
| |
| {{APIPrefix|Dim}} Amodel {{APIPrefix|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."
| |
| | |
| {{APIComment|'Define the model.}}
| |
| {{APIPrefix|Dim}} ModelCategory {{APIPrefix|As}} ModelCategoryEnum
| |
| {{APIPrefix|Dim}} ModelType {{APIPrefix|As}} ModelTypeEnum
| |
| {{APIPrefix|Dim}} ModelName {{APIPrefix|As}} String
| |
| {{APIPrefix|Dim}} ModelParams(1) {{APIPrefix|As}} Double
| |
|
| |
| ModelCategory = ModelCategoryEnum.Reliability
| |
| ModelType = ModelTypeEnum.Weibull2
| |
| ModelName = {{APIString|"MyNewModel"}}
| |
| ModelParams(0) = 1
| |
| ModelParams(1) = 100
| |
| | |
| After setting the properties, use the [[CModel.SetModel|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|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 [[Connect_or_Disconnect_from_a_Synthesis_Repository|this tutorial]].)
| |
| | |
| {{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)
| |
| | |
| You can then use the [[Repository.Model.AddModel|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.
| |
| | |
| {{APIComment|'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:
| |
| | |
| {{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. 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.
| |
| | |
| | |
| ===References===
| |
| *[[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 Tutorial: [[Edit Existing Synthesis Resources|Edit Existing Synthesis Resources >>]]</span>'''
| |