Edit Existing Synthesis Resources: Difference between revisions

From ReliaWiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Template:API}}
{{Template:API}}{{Template:BacktoPrevPage}}
<div style="border:1px solid #AAA; background:#f9f9f9; border-radius:10px; width:auto; margin:0 0 1em 1em; padding:1em; float:right;">
<nowiki><<</nowiki> [[API Tutorials|Back to API Tutorials]]


'''Basics'''
In the [[Add_New_Synthesis_Resources_to_a_Repository|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.
#[[Connect or Disconnect from a Synthesis Repository]]
#[[Add New Synthesis Resources to a Repository]]
#Edit Existing Synthesis Resources
#[[Calculate Results from a Model]]
</div>


In this tutorial, you'll learn how to retrieve a Synthesis resource from a repository and edit its properties. We'll use the <code>cModel</code> class for this example.  
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.  


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.
==Prerequisites==
Before you begin:


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]]).
*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 [[Synthesis_API_Object_IDs|object ID]]. You will use the object ID to retrieve the model from the database.




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


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.
A VBA version of the code sample is available [[Edit_Existing_Synthesis_Resources/VBA|here]].  
 
{{APIComment|'Connect to the Synthesis repository and set project ID#1 as the current project.}}
  {{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository
  MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr10"}})
  MyRepository.Project.SetCurrentProject(1)
 
2. Retrieve a model from the repository. Use the <code>GetModel</code> method to retrieve the model. The following code assumes that the repository contains a model with ID number 21.
 
'''VBA'''
{{APIComment|'Retrieve the model with ID# 21 from the repository.}}
  {{APIPrefix|Dim}} Amodel {{APIPrefix|As New}} cModel
  {{APIPrefix|Set}} AModel = MyRepository.Model.GetModel(21)


  '''VB.NET'''
  '''VB.NET'''
   
   
  {{APIComment|'Retrieve the model with ID# 21 from the repository.}}
  {{APIPrefix|Imports}} SynthesisAPI
  {{APIPrefix|Dim}} Amodel {{APIPrefix|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.
 
  {{APIComment|'Edit the model's name, description and part number.}}
  Amodel.Name = {{APIString|"MyNewModel_Updated"}}
  Amodel.ItemDescription = {{APIString|"A specific type of light bulb."}}
  Amodel.ItemPartNumber = {{APIString|"PN5461"}} 
 
4. Use the <code>UpdateModel</code> method to apply the changes to the model.
 
'''VBA'''
{{APIComment|'Apply the changes to the model.}}
  {{APIPrefix|Call}} MyRepository.Model.UpdateModel(AModel)
 
'''VB.NET'''
 
{{APIComment|'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()
{{APIComment|'Connect to the Synthesis repository and set project ID#1 as the current project.}}
  {{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository
  MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr10"}})
  MyRepository.Project.SetCurrentProject(1)
{{APIComment|'Retrieve the model with ID# 21 from the repository.}}
  {{APIPrefix|Dim}} Amodel {{APIPrefix|As New}} cModel
  {{APIPrefix|Set}} AModel = MyRepository.Model.GetModel(21)
   
   
  {{APIComment|'Edit the model's name, description and part number.}}
{{APIPrefix|Public Module}} Module1
  Amodel.Name = {{APIString|"MyNewModel_Updated"}}
    {{APIPrefix|Sub}} Main()
  Amodel.ItemDescription = {{APIString|"A specific type of light bulb."}}
  Amodel.ItemPartNumber = {{APIString|"PN5461"}} 
    
    
{{APIComment|'Apply the changes to the model.}}
   {{APIComment|'Connect to a Synthesis repository and project.}}
  {{APIPrefix|Call}} MyRepository.Model.UpdateModel(AModel)
End Sub
 
'''VB.NET'''
{{APIPrefix|Imports}} SynthesisAPI
{{APIPrefix|Public Class}} Form1
    {{APIPrefix|Private Sub}} Button1_Click(sender {{APIPrefix|As}} System.Object, e {{APIPrefix|As}} System.EventArgs) {{APIPrefix|Handles}} Button1.Click
 
   {{APIComment|'Connect to the Synthesis repository and set project ID#1 as the current project.}}
     {{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository
     {{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository
     MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr10"}})
     MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr11"}}){{APIComment|'Replace with name and path to test repository.}}
     MyRepository.Project.SetCurrentProject(1)
     MyRepository.Project.SetCurrentProject(1){{APIComment|'Replace with the object ID of test project.}}
    
    
   {{APIComment|'Retrieve the model with ID# 21 from the repository.}}  
   {{APIComment|'Declare a new cModel object.}}  
     {{APIPrefix|Dim}} Amodel {{APIPrefix|As New}} cModel
     {{APIPrefix|Dim}} Amodel {{APIPrefix|As New}} cModel
     AModel = MyRepository.Model.GetModel(21)
  {{APIComment|'Retrieve a model from the project.}}
     AModel = MyRepository.Model.GetModel(21){{APIComment|'Replace with the object ID of test model.}}
   
   
   {{APIComment|'Edit the model's name, description and part number.}}
   {{APIComment|'Edit the model's name, description and part number.}}
Line 107: Line 41:
     Amodel.ItemPartNumber = {{APIString|"PN5461"}}   
     Amodel.ItemPartNumber = {{APIString|"PN5461"}}   
   
   
   {{APIComment|'Apply the changes to the model.}}
   {{APIComment|'Send the changes to the project.}}
     MyRepository.Model.UpdateModel(AModel)
     MyRepository.Model.UpdateModel(AModel)
   
   
     {{APIPrefix|End Sub}}
     {{APIPrefix|End Sub}}
  {{APIPrefix|End Class}}
  {{APIPrefix|End Module}}
 
===Discussion===
Begin by connecting to a Synthesis repository and project (for details, see [[Connect_or_Disconnect_from_a_Synthesis_Repository|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.
 
{{APIComment|'Connect to a Synthesis repository and project.}}
  {{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository
  MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr11"}}){{APIComment|'Replace with name and path to test repository.}}
  MyRepository.Project.SetCurrentProject(1){{APIComment|'Replace with the object ID of test project.}}


===Notes===
Once you are connected to the repository, use the [[Repository.Model.GetModel|Model.GetModel]] method to retrieve a single model from the repository. The following code assumes that the repository contains a model with ID#21.  
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 <code>[[Repository.URD.GetURD]]</code> method to retrieve the URD from the repository, and then use the <code>[[Repository.URD.UpdateURD]]</code> method to apply the changes.


===References===
{{APIComment|'Declare a new cModel object.}}
To learn more, see the reference documentation for the methods discussed in this section:
  {{APIPrefix|Dim}} Amodel {{APIPrefix|As New}} cModel
{{APIComment|'Retrieve a model from the project.}}
  AModel = MyRepository.Model.GetModel(21){{APIComment|'Replace with the object ID of test model.}}
 
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|cModel.SetModel]] method.)
 
{{APIComment|'Edit the model's name, description and part number.}}
  Amodel.Name = {{APIString|"MyNewModel_Updated"}}
  Amodel.ItemDescription = {{APIString|"A specific type of light bulb."}}
  Amodel.ItemPartNumber = {{APIString|"PN5461"}} 
 
Use the [[Repository.Model.UpdateModel|Model.UpdateModel]] method to save the new information to the Synthesis repository.


*[[Repository.Model.GetModel|Repository.Model.GetModel Method]]
{{APIComment|'Send the changes to the project.}}
*[[Repository.Model.UpdateModel|Repository.Model.UpdateModel Method]]
  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'''.




==Notes==
*To retrieve all other types of Synthesis resources, you can use the same approach demonstrated in the example. For example, to update the properties of an existing URD, you would use the [[Repository.URD.GetURD]] method to retrieve a single URD from the repository, and then use the [[Repository.URD.UpdateURD]] method to apply the changes.


*To perform batch updates, use the [[Repository.Model.GetAllModels]] method to get an array of all available models in the repository. Similar methods exist for all other types of Synthesis resources (e.g., [[Repository.URD.GetAllURDs]], [[Repository.Action.GetAllActions]], etc.). See the [[Repository Class]] reference documentation for the complete list.


'''<span style="color:#808080;">Next: [[Calculate Results from a Model|Calculate Results from a Model >>]]</span>'''
===References===
*[[Repository Class]]
**[[Repository.Model.GetModel|Repository.Model.GetModel Method]]
**[[Repository.Model.UpdateModel|Repository.Model.UpdateModel Method]]

Latest revision as of 18:15, 3 April 2017

APIWiki.png


<< Back to Tutorials Main Page

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

Imports SynthesisAPI 

Public Module Module1
   Sub Main()
 
   'Connect to a Synthesis repository and project. 
    Dim MyRepository As New Repository
    MyRepository.ConnectToRepository("C:\RSRepository1.rsr11") 'Replace with name and path to test repository. 
    MyRepository.Project.SetCurrentProject(1) 'Replace with the object ID of test project. 
  
   'Declare a new cModel object.  
    Dim Amodel As New cModel

   'Retrieve a model from the project.  
    AModel = MyRepository.Model.GetModel(21) 'Replace with the object ID of test model. 

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

   'Send the changes to the project. 
    MyRepository.Model.UpdateModel(AModel)

   End Sub
End Module

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.

 'Connect to a Synthesis repository and project. 
  Dim MyRepository As New Repository
  MyRepository.ConnectToRepository("C:\RSRepository1.rsr11") 'Replace with name and path to test repository. 
  MyRepository.Project.SetCurrentProject(1) 'Replace with the object ID of test project. 

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.

 'Declare a new cModel object.  
  Dim Amodel As New cModel

 'Retrieve a model from the project.  
  AModel = MyRepository.Model.GetModel(21) 'Replace with the object ID of test model. 

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

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

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

 'Send the changes to the project. 
  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.


Notes

  • To retrieve all other types of Synthesis resources, you can use the same approach demonstrated in the example. For example, to update the properties of an existing URD, you would use the Repository.URD.GetURD method to retrieve a single URD from the repository, and then use the Repository.URD.UpdateURD method to apply the changes.

References