Edit Existing Synthesis Resources

From ReliaWiki
Jump to navigation Jump to search
APIWiki.png


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

 'Connect to the Synthesis repository and set project ID#1 as the current project. 
  Dim MyRepository As New Repository
  MyRepository.ConnectToRepository("C:\RSRepository1.rsr10")
  MyRepository.Project.SetCurrentProject(1)

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

VBA

 'Retrieve the model with ID# 21 from the repository. 
  Dim Amodel As New cModel
  Set AModel = MyRepository.Model.GetModel(21)
VB.NET

 'Retrieve the model with ID# 21 from the repository.  
  Dim Amodel As New 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.

  'Edit the model's name, description and part number. 
  Amodel.Name = "MyNewModel_Updated"
  Amodel.ItemDescription = "A specific type of light bulb."
  Amodel.ItemPartNumber = "PN5461"   

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

VBA

 'Apply the changes to the model. 
  Call MyRepository.Model.UpdateModel(AModel)
VB.NET
 
 'Apply the changes to the model. 
  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()

 'Connect to the Synthesis repository and set project ID#1 as the current project. 
  Dim MyRepository As New Repository
  MyRepository.ConnectToRepository("C:\RSRepository1.rsr10")
  MyRepository.Project.SetCurrentProject(1)

 'Retrieve the model with ID# 21 from the repository. 
  Dim Amodel As New cModel
  Set AModel = MyRepository.Model.GetModel(21)

  'Edit the model's name, description and part number. 
  Amodel.Name = "MyNewModel_Updated"
  Amodel.ItemDescription = "A specific type of light bulb."
  Amodel.ItemPartNumber = "PN5461"   
 
 'Apply the changes to the model. 
  Call MyRepository.Model.UpdateModel(AModel)

End Sub
VB.NET

Imports SynthesisAPI 

Public Class Form1
   Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
  
   'Connect to the Synthesis repository and set project ID#1 as the current project. 
    Dim MyRepository As New Repository
    MyRepository.ConnectToRepository("C:\RSRepository1.rsr10")
    MyRepository.Project.SetCurrentProject(1)
  
   'Retrieve the model with ID# 21 from the repository.  
    Dim Amodel As New cModel
    AModel = MyRepository.Model.GetModel(21)

   'Edit the model's name, description and part number. 
    Amodel.Name = "MyNewModel_Updated"
    Amodel.ItemDescription = "A specific type of light bulb."
    Amodel.ItemPartNumber = "PN5461"   

   'Apply the changes to the model. 
    MyRepository.Model.UpdateModel(AModel)

   End Sub
End Class

Notes

You can use a similar approach to update the properties of other types of Synthesis repositories. For example, to update the properties of an existing URD, you would use the Repository.URD.GetURD method to retrieve the URD from the repository, and then use the Repository.URD.UpdateURD method to apply the changes.

References

To learn more, see the reference documentation for the methods discussed in this tutorial:



Next: Calculate Results from a Model >>