Add New Synthesis Resources to a Repository

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 a Synthesis repository. A discussion of the example follows.

A VBA version of the code sample is available here.

VB.NET SynthesisAPI Module1 Main Amodel cModel ModelCategory ModelCategoryEnum ModelType ModelTypeEnum ModelName String ModelParams(1) Double ModelCategory = ModelCategoryEnum.Reliability ModelType = ModelTypeEnum.Weibull2 ModelName = ModelParams(0) = 1 ModelParams(1) = 100 AModel.SetModel(ModelType, ModelCategory, ModelName, ModelParams) MyRepository Repository MyRepository.ConnectToRepository MyRepository.Project.SetCurrentProject(1) MyRepository.Model.AddModel(AModel)

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.

Amodel 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."

ModelCategory ModelCategoryEnum ModelType ModelTypeEnum ModelName String ModelParams(1) Double ModelCategory = ModelCategoryEnum.Reliability ModelType = ModelTypeEnum.Weibull2 ModelName = 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.rsr10" exists in the C drive (for a full discussion on the method, see this tutorial.)

MyRepository Repository MyRepository.ConnectToRepository MyRepository.Project.SetCurrentProject(1)

Now that we have access to a project, we can use the Model.AddModel method in the class to save the model to the project. Note that for secure databases, you must have the necessary read/write permissions to perform this command.

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