APISynthesisResourcesTutorial: Difference between revisions
Kate Racaza (talk | contribs) No edit summary |
Kate Racaza (talk | contribs) No edit summary |
||
Line 39: | Line 39: | ||
{{APIComment|'Get a list of all projects in the repository.}} | {{APIComment|'Get a list of all projects in the repository.}} | ||
ListOfProjects = MyRepository.Project.GetAllProjects | ListOfProjects = MyRepository.Project.GetAllProjects | ||
{{APIComment|'Set the first available project as the current project.}} | {{APIComment|'Set the first available project as the current project.}} | ||
Line 48: | Line 48: | ||
{{APIPrefix|Dim}} ProjectID {{APIPrefix|As}} Integer | {{APIPrefix|Dim}} ProjectID {{APIPrefix|As}} Integer | ||
ProjectName = MyRepository.Project.GetCurrentProject | ProjectName = MyRepository.Project.GetCurrentProject.Name | ||
ProjectID = MyRepository.Project.GetCurrentProject | ProjectID = MyRepository.Project.GetCurrentProject.ID | ||
MsgBox ({{APIString|"You are currently connected to: "}} & ProjectName & {{APIString|", ID#"}} & ProjectID) | MsgBox ({{APIString|"You are currently connected to: "}} & ProjectName & {{APIString|", ID#"}} & ProjectID) | ||
Line 81: | Line 81: | ||
{{APIComment|'Get a list of all projects in the repository.}} | {{APIComment|'Get a list of all projects in the repository.}} | ||
ListOfProjects = MyRepository.Project.GetAllProjects | ListOfProjects = MyRepository.Project.GetAllProjects | ||
{{APIComment|'Set the first available project as the current project.}} | {{APIComment|'Set the first available project as the current project.}} | ||
Line 90: | Line 90: | ||
{{APIPrefix|Dim}} ProjectID {{APIPrefix|As}} Integer | {{APIPrefix|Dim}} ProjectID {{APIPrefix|As}} Integer | ||
ProjectName = MyRepository.Project.GetCurrentProject | ProjectName = MyRepository.Project.GetCurrentProject.Name | ||
ProjectID = MyRepository.Project.GetCurrentProject | ProjectID = MyRepository.Project.GetCurrentProject.ID | ||
MsgBox ({{APIString|"You are currently connected to: "}} & ProjectName & {{APIString|", ID#"}} & ProjectID) | MsgBox ({{APIString|"You are currently connected to: "}} & ProjectName & {{APIString|", ID#"}} & ProjectID) | ||
Revision as of 17:28, 23 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. We'll start with the Repository
class, which provides several methods for connecting to standard or enterprise repositories. In this example, we will use the basic ConnectToRepository
method to create a simple application.
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, use the Project.SetCurrentProject
method to specify the current (or active) project by using the project's ID number. In this example, we'll first use the Project.GetAllProjects
method to get an array of all projects in the repository, and then use the ID number of the first project in the array to set it as the current project.
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 is the code list 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|VB.NET 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
References
To learn more, see the reference documentation for the classes and methods discussed in this section:
- Repository Class
- Repository.ConnectToRepository Method
- Repository.DisconnectFromRepository Method
- Repository.Project.GetAllProjects Method
- Repository.Project.SetCurrentProject Method
- Repository.Project.GetCurrentProject Method
- NameIdPair Class