How to create a PLC project

A new PLC project is created on the PLC node TIPC via CreateChild. You can use either a standard template or your own .plcproj template file.

Requirements

C# sample

ITcSmTreeItem plcNode = sysManager.LookupTreeItem("TIPC");

// Simple: use standard template
ITcSmTreeItem plcProject = plcNode.CreateChild("PLC1", 0, "", "Standard PLC Template");

// Explicit path — named form (object[]):
object[] vInfoNamed = new object[] {
    new string[] { "path", @"C:\tmp\Template.plcproj" },
    new string[] { "pathType", "template" }   // "template" or "existing"
};
ITcSmTreeItem plcProjectFromTemplate = plcNode.CreateChild("NewPlcFromTmplt", 0, "", vInfoNamed);

// Explicit path — positional form (string[]):
string[] vInfoPositional = new string[] { @"C:\tmp\ExistingProject.plcproj", "existing" };
ITcSmTreeItem plcExisting = plcNode.CreateChild("ExistingPLC", 0, "", vInfoPositional);

PowerShell sample

$plcNode = $sysManager.LookupTreeItem("TIPC")

# Standard template
$plcProject = $plcNode.CreateChild("PLC1", 0, "", "Standard PLC Template")
How to create a PLC project 1:

The vInfo parameter distinguishes between "template" for creating a new PLC from a template and "existing" for inserting an existing project. When you click "template", a copy of the template is created in the project folder. The project is referenced at "existing". The named and positional forms are equivalent.

Standard template paths

TwinCAT includes two standard templates. Both are represented by a template file in the TwinCAT directory.

Up to TwinCAT 3.1 4024

Template name

Template file

Standard PLC template

C:/TwinCAT3/.xComponents/Plc/PlcTemplate/Plc TemplatesStandard/PLC Template.plcproj

Empty PLC template

C:/TwinCAT3/.xComponents/Plc/PlcTemplate/Plc TemplatesEmpty/PLC Template.plcproj

From TwinCAT 4026

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

How to create a PLC project 2:

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)
How to create a PLC project 3:

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")