Configure TMC and TPY file creation

TwinCAT can automatically generate .tmc and .tpy files during the build process. The TMC file (TwinCAT module class) contains the type description of the PLC project and is required for TcCOM modules and the module description in the TwinCAT environment. The TPY file contains the process image of the PLC project and allows variables to be imported into other projects.

Both settings are configured in the PLC project root via ConsumeXml. In addition, the process image of an existing TMC file can be imported into the I/O configuration tree as a PLC instance.

Requirements

Enabling TMC and TPY generation

The setting is configured in the PLC project root using a short XML fragment via ConsumeXml. For TmcFileCopy and TpyFileCopy, a single request is sufficient in each case.

ITcSmTreeItem plcProjectRoot = sysManager.LookupTreeItem(@"TIPC^PLC1^PLC1 Project");

// Generate TMC file on build
plcProjectRoot.ConsumeXml(
    "<TreeItem><PlcProjectDef><TmcFileCopy>true</TmcFileCopy></PlcProjectDef></TreeItem>");

// Generate TPY file on build (implicitly activates TmcFileCopy as well)
plcProjectRoot.ConsumeXml(
    "<TreeItem><PlcProjectDef><TpyFileCopy>true</TpyFileCopy></PlcProjectDef></TreeItem>");

Importing a process image from a TMC file

An existing TMC file can be imported into the I/O configuration tree as a PLC instance. The path to the TMC file is passed to CreateChild as the fourth parameter.

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

// Create PLC instance from TMC file
plcNode.CreateChild("ImportedPLC", 0, "", @"C:\Projects\MyModule.tmc");
Configure TMC and TPY file creation 1:

By default, the generated TMC and TPY files are saved in the project folder.