Edit Existing Synthesis Resources

In the previous tutorial, you learned how to create new Synthesis resources (e.g., models, actions, URDs, etc.) and save them to a database. In this tutorial, you'll learn how to retrieve an existing Synthesis resource from a database, and then overwrite existing data about the resource with new information.

You'll use a model resource to work with the example. A similar approach can be used when working with other types of Synthesis resources.

Prerequisites
Before you begin:


 * Create a Synthesis repository for testing purposes. Then create a model via the Resource Manager (Project > Synthesis> Resource Manager). Do not use published models for this tutorial (i.e., model resources that have been published from and are associated with an existing analysis/data source). Published models are read-only and therefore cannot be used to demonstrate the goals of this tutorial.


 * Note down the model's object ID. You will use the object ID to retrieve the model from the database.

Tutorial: Edit an Existing Synthesis Resource
The following example demonstrates how to retrieve a Synthesis resource from a repository and overwrite existing data about the resource with new information. A discussion of the example follows.

A VBA version of the code sample is available here.

VB.NET SynthesisAPI Module1 Main MyRepository Repository MyRepository.ConnectToRepository MyRepository.Project.SetCurrentProject(1) Amodel cModel AModel = MyRepository.Model.GetModel(21) Amodel.Name = Amodel.ItemDescription = Amodel.ItemPartNumber = MyRepository.Model.UpdateModel(AModel)

Discussion
Begin by connecting to a Synthesis repository and project (for details, see this tutorial.) 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 and that we're accessing project ID#1. If you're copying this section of code, be sure to replace the inputs with appropriate data for your test repository.

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

Once you are connected to the repository, use the Model.GetModel method to retrieve a single model from the repository. The following code assumes that the repository contains a model with ID#21.

Amodel cModel AModel = MyRepository.Model.GetModel(21)

You can then edit the model's properties. In this example, we edited the model's name, description and part number, as shown. (To update a model's parameters, category or type, use the cModel.SetModel method.)

Amodel.Name = Amodel.ItemDescription = Amodel.ItemPartNumber =

Use the Model.UpdateModel method to save the new information to the Synthesis repository.

MyRepository.Model.UpdateModel(AModel)

To verify that the model's properties have been updated, open the Resource Manager and look up the model. You may need to display the Description and Part Number columns of the Resource Manager by right-clicking a column header and choosing Select Columns.