Edit Existing Synthesis Resources

 << Back to API Tutorials

Basics
 * 1) Connect or Disconnect from a Synthesis Repository
 * 2) Add New Synthesis Resources to a Repository
 * 3) Edit Existing Synthesis Resources
 * 4) Calculate Results from a Model

In this tutorial, you'll learn how to retrieve a Synthesis resource from a repository and edit its properties. We'll use the  class for this example.

Before you begin, be sure to create a model in your test repository 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). Those types of models are read-only and cannot be edited.

In addition, display the object IDs in the Synthesis application, so you can obtain the model's ID number and trace the response from the API. (For details, see Using Object IDs).

Edit an Existing Synthesis Resource
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.

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

2. Retrieve a model from the repository. Use the  method to retrieve the model. The following code assumes that the repository contains a model with ID number 21.

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

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

3. Edit the model's properties. For example, let's edit the model's name, description and part number, as shown in the following code.

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

4. Use the  method to apply the changes to the model.

VBA MyRepository.Model.UpdateModel(AModel)

VB.NET MyRepository.Model.UpdateModel(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 verify that the model's properties have been updated by checking the Resource Manager. (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.)

VBA Sub 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) End Sub

VB.NET SynthesisAPI Form1 Button1_Click(sender System.Object, e  System.EventArgs)  Button1.Click 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)