APISynthesisResourcesTutorial3: Difference between revisions

From ReliaWiki
Jump to navigation Jump to search
(Undo revision 61205 by Kate Racaza (Talk))
(Redirected page to API Tutorials)
 
Line 1: Line 1:
{{DISPLAYTITLE:Synthesis Resources Tutorial}}{{Template:API}}
#REDIRECT [[API_Tutorials]]
<div style="border:1px solid #AAA; background:#f9f9f9; border-radius:10px; width:auto; margin:0 0 1em 1em; padding:1em; float:right;">
<nowiki><<</nowiki> [[APIQuickStartGuide|Back to Quick Start Guide]]
 
'''Synthesis Resources Tutorial'''
#[[APISynthesisResourcesTutorial|Connect to a Synthesis Repository and Project]]
#[[APISynthesisResourcesTutorial2|Create a New Synthesis Resource]]
#Update an Existing Resource
#[[APISynthesisResourcesTutorial4|Calculate Results from a Model]]
</div>
 
In this section, we'll learn how to update the properties of the model we've created in the previous section.
 
 
 
 
 
 
 
 
 
 
==Part 3: Update an Existing Resource==
 
1. Create a new module and add code to connect to the Synthesis repository and project.
 
'''VBA|VB.NET'''
{{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. Next, retrieve the model from the repository so we can edit it. Use the <code>GetModel</code> method to the retrieve the model (called "MyNewModel"). The following code assumes that the model's ID number is 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'''
{{APIComment|'Retrieve the model with ID# 21 from the repository.}}
  {{APIPrefix|Dim}} Amodel {{APIPrefix|As New}} cModel
  AModel = MyRepository.Model.GetModel(21)
 
3. Edit the model's properties. Use the following code to edit the model's name, description and part number.
 
'''VBA|VB.NET'''
  {{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 VBA and VB.NET code lists for this example. On the Debug menu, click '''Start''' to run the application, and then check the project's Resource Manager to verify that the properties have been updated. (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.}}
  Amodel.Name = {{APIString|"MyNewModel_Updated"}}
  Amodel.ItemDescription = {{APIString|"A specific type of light bulb."}}
  Amodel.ItemPartNumber = {{APIString|"PN5461"}} 
 
{{APIComment|'Apply the changes to the model.}}
  {{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
    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
    AModel = MyRepository.Model.GetModel(21)
  {{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|'Apply the changes to the model.}}
    MyRepository.Model.UpdateModel(AModel)
    {{APIPrefix|End Sub}}
{{APIPrefix|End Class}}
 
 
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===
To learn more, see the reference documentation for the methods discussed in this section:
 
*[[Repository.Model.GetModel|Repository.Model.GetModel Method]]
*[[Repository.Model.UpdateModel|Repository.Model.UpdateModel Method]]
 
 
 
 
 
'''<span style="color:#808080;">Next: [[APISynthesisResourcesTutorial4|Calculate Results from a Model >>]]</span>'''

Latest revision as of 23:48, 9 February 2016

Redirect to: