Samples | PLC From TwinCAT 4026 For standard Beckhoff PLC templates, only the template name should be used, e.g., "Standard PLC Template" , not the full path. Access to the nested project and the project instance TwinCAT PLC projects consist of two areas: the nested project and the project instance. The nested project has Tree Item SubType 56 and contains the source code of the PLC program, while the project instance contains the declared input and output variables of the PLC program. Accessing both areas requires different methods. C#:
ITcSmTreeItem plcProject = sysManager.LookupTreeItem("TIPC^PLC1"); ITcProjectRoot projectRoot = (ITcProjectRoot)plcProject; ITcSmTreeItem nestedProject = projectRoot.NestedProject; ITcSmTreeItem projectInstance = plcProject.childitems[1]; PowerShell: $plcProject = $sysManager.LookupTreeItem("TIPC^PLC1") $nestedProject = $plcProject.NestedProject $projectInstance = $plcProject.childitems.item(1) TwinCAT 3.1 Build 4018 or later is required to access the ITcProjectRoot interface. After creating the PLC project, it can be further edited by converting it to the ITcPlcIECProject interface, which offers additional functions and access to project-specific attributes: C#:
ITcSmTreeItem plcProject = sysManager.LookupTreeItem("TIPC^NameOfProject^NameOfProject Project"); ITcPlcIECProject iecProject = (ITcPlcIECProject) plcProject; PowerShell: $plcProject = $systemManager.LookupTreeItem("TIPC^NameOfProject^NameOfProject Project") 6.5.2 Compiling PLC projects | Compiling PLC projects Individual projects within a TwinCAT solution can be compiled selectively using SolutionBuild.BuildProject without having to rebuild the entire solution. Before calling BuildProject , the target platform must be set to the desired configuration using ConfigurationManager.ActiveTargetPlatform . The result can be retrieved via SolutionBuild.LastBuildInfo :
0 indicates success; any other value indicates an error. TE1000 226 Version: 1.7.0 Template name Template file Empty PLC template C:/TwinCAT3/.xComponents/Plc/ PlcTemplate/Plc TemplatesEmpty/PLC Template.plcproj Template name Template file Standard PLC template C:/ProgramData/Beckhoff/TwinCAT/ PlcEngineering/PlcTemplates/1.1.0.1/ Standard PLC Template/Standard PLC Template.plcproj Empty PLC template C:/ProgramData/Beckhoff/TwinCAT/ PlcEngineering/PlcTemplates/1.1.0.1/ Empty PLC Template/Empty PLC Template.plcproj