APISynthesisResourcesTutorial: Difference between revisions
Kate Racaza (talk | contribs) No edit summary |
Kate Racaza (talk | contribs) No edit summary |
||
Line 12: | Line 12: | ||
This four-part tutorial introduces you to the basic functionalities of the Synthesis API. You will learn how to use the API to connect to a Synthesis repository, create a new resource, update an existing resource and obtain calculated results from a model. | This four-part tutorial introduces you to the basic functionalities of the Synthesis API. You will learn how to use the API to connect to a Synthesis repository, create a new resource, update an existing resource and obtain calculated results from a model. | ||
Revision as of 18:20, 30 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
This four-part tutorial introduces you to the basic functionalities of the Synthesis API. You will learn how to use the API to connect to a Synthesis repository, create a new resource, update an existing resource and obtain calculated results from a model.
The Synthesis Platform uses repositories to store projects and analysis data. Projects, in turn, hold resources that contain various types of information that can be shared between analyses. Therefore, to create or update a resource in a Synthesis repository, we must begin by first connecting to the repository and then accessing the project that holds that resource.
Part 1: Connect to a Synthesis Repository and Project
1. Let's start with the Repository
class, which represents a Synthesis repository. This class provides several methods for connecting to either a standard or enterprise repository. In this example, we'll use the basic ConnectToRepository
method.
Create a new module and start with the following basic code for connecting to a standard Synthesis repository.
VBA|VB.NET 'Declare a new instance of the Repository class. Dim MyRepository As New Repository 'Specify the full path to the Synthesis repository. 'The following code assumes that a standard repository called "RSRepository1.rsr10" exists in the C drive. MyRepository.ConnectToRepository("C:\RSRepository1.rsr10")
2. Next, we'll specify the current (or active) project to use.
Use the Project.GetAllProjects
method to get an array of all the projects in the repository, and then use the Project.SetCurrentProject
method to select the ID number of the first project in the array.
VBA|VB.NET 'Declare a new instance of the NameIdPair class. Dim ListofProjects() As NameIdPair 'Get a list of all projects in the repository. ListOfProjects = MyRepository.Project.GetAllProjects 'Set the first available project as the current project. MyRepository.Project.SetCurrentProject(ListofProjects(0).ID) 'Display the name and ID number of the current project. Dim ProjectName As String Dim ProjectID As Integer ProjectName = MyRepository.Project.GetCurrentProject.Name ProjectID = MyRepository.Project.GetCurrentProject.ID MsgBox ("You are currently connected to: " & ProjectName & ", ID#" & ProjectID)
Any time you wish to switch to another project in the repository, you can always use the Project.SetCurrentProject
method to specify a new active project.
However, if you wish to access projects from another repository, you’ll first need to disconnect from the current repository by using the DisconnectFromRepository
method, and then use the ConnectToRepository
method again to connect to the desired repository.
VBA|VB.NET
'Disconnect from the Synthesis repository.
MyRepository.DisconnectFromRepository
Test the Code
Let’s verify that our connections to the repository and project work.
Below are the VBA and VB.NET code lists for this example. On the Debug menu, click Start to run the application. A message box displays the name and ID number of the current project in the repository.
VBA Sub Main() 'Declare a new instance of the Repository class. Dim MyRepository As New Repository 'Specify the full path to the Synthesis repository. 'The following code assumes that a standard repository called "RSRepository1.rsr10" exists in the C drive. MyRepository.ConnectToRepository("C:\RSRepository1.rsr10") 'Declare a new instance of the NameIdPair class. Dim ListofProjects() As NameIdPair 'Get a list of all projects in the repository. ListOfProjects = MyRepository.Project.GetAllProjects 'Set the first available project as the current project. MyRepository.Project.SetCurrentProject(ListofProjects(0).ID) 'Display the name and ID number of the current project. Dim ProjectName As String Dim ProjectID As Integer ProjectName = MyRepository.Project.GetCurrentProject.Name ProjectID = MyRepository.Project.GetCurrentProject.ID MsgBox ("You are currently connected to: " & ProjectName & ", ID#" & ProjectID) 'Disconnect from the Synthesis repository. MyRepository.DisconnectFromRepository End Sub
VB.NET Imports SynthesisAPI Public Class Form1 Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click 'Declare a new instance of the Repository class. Dim MyRepository As New Repository 'Specify the full path to the Synthesis repository. 'The following code assumes that a standard repository called "RSRepository1.rsr10" exists in the C drive. MyRepository.ConnectToRepository("C:\RSRepository1.rsr10") 'Declare a new instance of the NameIdPair class. Dim ListofProjects() As NameIdPair 'Get a list of all projects in the repository. ListOfProjects = MyRepository.Project.GetAllProjects 'Set the first available project as the current project. MyRepository.Project.SetCurrentProject(ListofProjects(0).ID) 'Display the name and ID number of the current project. Dim ProjectName As String Dim ProjectID As Integer ProjectName = MyRepository.Project.GetCurrentProject.Name ProjectID = MyRepository.Project.GetCurrentProject.ID MsgBox ("You are currently connected to: " & ProjectName & ", ID#" & ProjectID) 'Disconnect from the Synthesis repository. MyRepository.DisconnectFromRepository End Sub End Class
References
To learn more, see the reference documentation for the classes and methods discussed in this section:
- Repository Class
- NameIdPair Class
- Repository.ConnectToRepository Method
- Repository.DisconnectFromRepository Method
- Repository.Project.GetAllProjects Method
- Repository.Project.SetCurrentProject Method
- Repository.Project.GetCurrentProject Method