Talk:Edit Existing Synthesis Resources/Notes: Difference between revisions

From ReliaWiki
Jump to navigation Jump to search
No edit summary
(Replaced content with '==DRAFT==')
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
{{Template:API}}
==DRAFT==
 
In the [[Add_New_Synthesis_Resources_to_a_Repository|previous tutorial]], you learned how to write data to a Synthesis repository; specifically, 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 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 number. This will help you trace the response from the API. To display the object IDs, choose '''File > Application Setup'''. Then click '''Other''' under the Synthesis Settings heading in the navigation panel. Select the check box for '''Display Object IDs'''. The object ID of the model is displayed in the Resource Manager.
 
 
==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 [[Edit_Existing_Synthesis_Resources/VBA|here]].
 
'''VB.NET'''
{{APIPrefix|Imports}} SynthesisAPI
{{APIPrefix|Public Module}} Module1
    {{APIPrefix|Sub}} Main()
 
  {{APIComment|'Connect to a Synthesis repository and project.}}
    {{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository
    MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr10"}}){{APIComment|'Replace with name and path to test repository.}}
    MyRepository.Project.SetCurrentProject(1){{APIComment|'Replace with the object ID of test project.}}
 
  {{APIComment|'Declare a new cModel object.}}
    {{APIPrefix|Dim}} Amodel {{APIPrefix|As New}} cModel
  {{APIComment|'Retrieve a model from the repository.}}
    AModel = MyRepository.Model.GetModel(21){{APIComment|'Replace with the object ID of test model.}}
  {{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"}} 
  {{APIComment|'Send the changes to the Synthesis repository.}}
    MyRepository.Model.UpdateModel(AModel)
    {{APIPrefix|End Sub}}
{{APIPrefix|End Module}}
 
 
===Discussion===
Begin by connecting to a Synthesis repository and project (for full instructions on how to do this, see [[Connect_or_Disconnect_from_a_Synthesis_Repository|this tutorial]].)
 
The section of code 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 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.rsr10"}}){{APIComment|'Replace with name and path to test repository.}}
    MyRepository.Project.SetCurrentProject(1){{APIComment|'Replace with the object ID of test project.}}
 
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 number 21.
 
  {{APIComment|'Declare a new cModel object.}}
    {{APIPrefix|Dim}} Amodel {{APIPrefix|As New}} cModel
  {{APIComment|'Retrieve a model from the repository.}}
    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 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"}} 
 
Use the [[Repository.Model.UpdateModel|Model.UpdateModel]] method to save the new information about the model to the Synthesis repository.
 
  {{APIComment|'Send the changes 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 item. 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===
You can use a similar approach to update the properties of other types of Synthesis resources. 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.
 
If you wish to get a list of all available models in a repository, use the [[Repository.Model.GetAllModels]] method. Similar methods exists for all other types of Synthesis resources.
 
 
===References===
*[[Repository.Model.GetModel|Repository.Model.GetModel Method]]
*[[Repository.Model.UpdateModel|Repository.Model.UpdateModel Method]]

Latest revision as of 22:51, 27 April 2016

DRAFT