beckhoff TE1000 TwinCAT 3 — 4.2.1 Accessing TwinCAT configuration

Configuration | Basics In addition, the Visual Studio API (the Visual Studio DTE ) offers developers many other functions, e.g. access to the error output window. Further information on Visual Studio DTE can be found on the Microsoft MSDN website. Please note: When creating a new TwinCAT project in a Visual Studio solution, you must specify a path to the TwinCAT project template [ } 28] . Please adjust this path in the code snippets below according to your environment. The following code snippets use dynamic linking for the Visual Studio DTE objects, which means that the actual type of the object is only determined during the course of the application runtime.

If you do not want to use dynamic linking but want to define the data type in advance, you must include the EnvDTE.DTE namespace in your project. Creating TwinCAT Projects via templates Please note that you need to add a reference to the COM object TcatSysManagerLib and EnvDTE.DTE (Microsoft Developement) in order to be able to use the TwinCAT Automation Interface and the Visual Studio API. The ProgID that is used in the GetTypeFromProdID() method depends on the Visual Studio version that should be used. Please have a look at this [ } 32] documentation article for more information about the different ProgIDs. Code Snippet (C#):

Type t = System.Type.GetTypeFromProgID("VisualStudio.DTE.10.0"); EnvDTE.DTE dte = System.Activator.CreateInstance(t); dte.SuppressUI = false; dte.MainWindow.Visible = true; if (Directory.Exists(@"C:\Temp\SolutionFolder")) Directory.Delete(@"C:\Temp\SolutionFolder", true); Directory.CreateDirectory(@"C:\Temp\SolutionFolder"); Directory.CreateDirectory(@"C:\Temp\SolutionFolder\MySolution1"); dynamic solution = dte.Solution; solution.Create(@"C:\Temp\SolutionFolder", "MySolution1"); solution.SaveAs(@"C:\Temp\SolutionFolder\MySolution1\MySolution1.sln"); string template = @"C:\TwinCAT\3.1\Components\Base\PrjTemplate\TwinCAT Project.tsproj"; //path to project template dynamic project = solution.AddFromTemplate(template, @"C:\Temp\SolutionFolder\MySolution1", "MyProject"); ITcSysManager sysManager = project.Object as ITcSysManager; sysManager.ActivateConfiguration(); sysManager.StartRestartTwinCAT(); project.Save(); solution.SaveAs(@"C:\Temp\SolutionFolder\MySolution1\MySolution1.sln"); Code Snippet (Powershell):

You can copy and paste the following code snippet into a textfile and save it as "someName.ps1". After that you can execute it directly via Windows PowerShell. TE1000 23 Version: 1.7.0