beckhoff TE1000 TwinCAT 3 — 4.2.1 Accessing TwinCAT configuration

Configuration | Basics $targetDir = "C:\tmp\TestSolution" $targetName = "TestSolution.tsp" $template = "C:\TwinCAT\3.1\Components\Base\PrjTemplate\TwinCAT Project.tsproj" $dte = new-object -com VisualStudio.DTE.10.0 $dte.SuppressUI = $false $dte.MainWindow.Visible = $true if(test-path $targetDir -pathtype container) { Remove-Item $targetDir -Recurse -Force } New-Item $targetDir -type directory $sln = $dte.Solution $project = $sln.AddFromTemplate($template,$targetDir,$targetName) $systemManager = $project.Object $targetNetId = $systemManager.GetTargetNetId() write-host $targetNetId $systemManager.ActivateConfiguration() $systemManager.StartRestartTwinCAT() $project.Save() $solutionPath = $targetDir + "\" + $targetName $sln.SaveAs($solutionPath) Code Snippet (C++) :

Within appropriate Header file (e.g the stdafx.h): //the following #import imports EnvDTE based on its LIBID. #import"libid:80cc9f66-e7d8-4ddd-85b6-d9e6cd0e93e2" version("10.0") lcid("0") raw_interfaces_only named_guids // Imports die "Beckhoff TCatSysManager 1.1 Type Library" #import"libid:3C49D6C3-93DC-11D0-B162-00A0248C244B" version("1.1") lcid("0") Because a known issue within VisualStudio 2010 (SP1), the generated proxy code will not be included into the C++ project. Please use the workaround described in #import Known Issue import Known Issue.

#include using namespace std using namespace TCatSysManagerLib; using namespace EnvDTE; int _tmain(int argc, _TCHAR* argv[]) { CoInitialize(NULL); // COM initialisieren cout // creating a new instance of Visual Studio CComPtr m_pDTE; HRESULT hr = m_pDTE.CoCreateInstance(L"VisualStudio.DTE.10.0", 0, CLSCTX_ALL); if (FAILED(hr)) { cout cout // retrieves the EnvDTE.Solution-Objekt CComPtr pSolution; m_pDTE->get_Solution(&pSolution); CComBSTR strSolutionFolder(_T("C:\\SolutionFolder")); // Solution-main directory (has to exist) CComBSTR strSolutionName(_T("MySolution1")); CComBSTR strTemplatePath(_T("C:\\TwinCAT\\3.1\\Components\\Base\\PrjTemplate\\TwinCAT Project.tsproj")); CComBSTR strSolutionPath; // Solution-Pfad (doesn't exist!) strSolutionPath=strSolutionFolder; strSolutionPath.Append(_T("\\")); strSolutionPath.Append(strSolutionName); strSolutionPath.Append(_T(".sln")); // create the solution hr = pSolution->Create(strSolutionFolder,strSolutionName); CComBSTR strProjectPath(strSolutionFolder); // project path strProjectPath.Append(_T("\\")); strProjectPath.Append(strSolutionName); CComBSTR strProjectName = "MyProject"; // project name // create projekt from a template TE1000 24 Version:

1.7.0