APISynthesisResourcesTutorial3: Difference between revisions
Kate Racaza (talk | contribs) mNo edit summary |
Kate Racaza (talk | contribs) No edit summary |
||
Line 10: | Line 10: | ||
</div> | </div> | ||
In this section, we'll update the properties of the model we've created in the previous section | In this section, we'll update the properties of the model we've created in the previous section. | ||
Line 46: | Line 46: | ||
AModel = MyRepository.Model.GetModel(21) | AModel = MyRepository.Model.GetModel(21) | ||
3. Let's update the model's properties. Use the following code to | 3. Let's update the model's properties. Use the following code to edit the model's name, description and part number. | ||
'''VBA|VB.NET''' | '''VBA|VB.NET''' | ||
{{APIComment|' | {{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.ItemDescription = {{APIString|"A specific type of light bulb."}} | ||
Amodel.ItemPartNumber = {{APIString|"PN5461"}} | Amodel.ItemPartNumber = {{APIString|"PN5461"}} | ||
4 | 4. Use the <code>UpdateModel</code> method to apply the changes to the model. | ||
'''VBA''' | '''VBA''' | ||
Line 83: | Line 68: | ||
===Test the Code=== | ===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 | 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''' | '''VBA''' | ||
Line 98: | Line 83: | ||
{{APIPrefix|Set}} AModel = MyRepository.Model.GetModel(21) | {{APIPrefix|Set}} AModel = MyRepository.Model.GetModel(21) | ||
{{APIComment|' | {{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.ItemDescription = {{APIString|"A specific type of light bulb."}} | ||
Amodel.ItemPartNumber = {{APIString|"PN5461"}} | Amodel.ItemPartNumber = {{APIString|"PN5461"}} | ||
{{APIComment|'Apply the changes to the model.}} | {{APIComment|'Apply the changes to the model.}} | ||
Line 127: | Line 106: | ||
AModel = MyRepository.Model.GetModel(21) | AModel = MyRepository.Model.GetModel(21) | ||
{{APIComment|' | {{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.ItemDescription = {{APIString|"A specific type of light bulb."}} | ||
Amodel.ItemPartNumber = {{APIString|"PN5461"}} | Amodel.ItemPartNumber = {{APIString|"PN5461"}} | ||
{{APIComment|'Apply the changes to the model.}} | {{APIComment|'Apply the changes to the model.}} |
Revision as of 22:30, 22 October 2015
Synthesis Resources Tutorial
- Connect to a Synthesis Repository and Project
- Create a New Synthesis Resource
- Update an Existing Resource
- Calculate Results from a Model
In this section, we'll 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 '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. Next, use the GetModel
method to the retrieve the model (called "MyNewModel") from the repository. The following code assumes that the model's ID number is 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. Let's update the model's properties. Use the following code to edit the model's name, description and part number.
VBA|VB.NET '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 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() '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 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 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
References
To learn more, see the reference documentation for the methods discussed in this section: