Code example: Get name of the active Trimble Connect project
This code example provides step by step instructions for creating the first simple application with Trimble Connect for Desktop API.
You will be using Microsoft Visual Studio as the development environment. Instructions are connected to an example provided in the class level API Reference documentation to support familiarization of the whole API.
-
Open Microsoft Visual Studio
-
Create a new Visual C# Console Application project
-
Add References to the following class libraries from the Trimble Connect for Desktop installation folder:
-
Trimble.Connect.Desktop.API.dll
-
Trimble.Connect.Desktop.API.Common.dll
-
-
Check the Properties of the added references. Make sure that they have the option Copy Local set to false.
-
Open the class level documentation from the Namespaces section
-
Open the documentation for TrimbleConnectDesktopClient class
-
Copy the code example from the TrimbleConnectDesktopClient class documentation. The code should look like this:
namespace TrimbleConnectDesktopAPISampleApplication { using System; using Trimble.Connect.Desktop.API; class Program { static void Main(string[] args) { var example = new Example(); Console.WriteLine("Connect to Trimble Connect for Desktop by pressing any key..."); Console.ReadKey(); Console.WriteLine(); if (example.Connect()) { Console.WriteLine("Connection succeeded! Press any key to start the operation..."); Console.ReadKey(); Console.WriteLine(); example.Example1(); Console.WriteLine("Operation completed! Press any key to continue..."); Console.ReadKey(); Console.WriteLine(); example.Disconnect(); } else { Console.WriteLine("Connection to Trimble Connect for Desktop failed."); } } } public class Example { private readonly TrimbleConnectDesktopClient client = new TrimbleConnectDesktopClient(); private bool connected = false; public bool Connect() { this.connected = this.client.Connect(); return this.connected; } public void Disconnect() { this.client.Disconnect(); this.connected = false; } public void Example1() { if (this.connected) { var activeProject = this.client.ProjectManager.GetActiveProject(); if (activeProject != null) { Console.WriteLine("The name of the active project is: {0}", activeProject.Name); } } } } }
-
Replace the existing content in the Microsoft Visual Studio's code editor with the copied content
-
Build the application
-
Run Trimble Connect for Desktop and open a project
-
Start debugging the application by pressing Start button with green triangle on the main toolbar
-
Verify that the output written to console application is correct
-
Close the application