Saving a TwinCAT project as an archive

TwinCAT supports two types of project export: The entire solution can be saved as a .tnzip archive. ExportChild exports individual subprojects – such as a PLC project or a POUs folder – as a .tpzip or .zip file.

Requirements

Saving a solution as an archive

The ITcArchivePersist interface is available via dte.GetObject("TcArchivePersist"). SaveAsArchive saves the entire solution as a .tnzip file. The archive contains all project files and can be restored on another computer.

using EnvDTE;

// Get ITcArchivePersist object via DTE
ITcArchivePersist persist = (ITcArchivePersist)dte.GetObject("TcArchivePersist");

// Save solution as .tnzip
persist.SaveAsArchive(@"C:\Archives\MyProject.tnzip");

// Optionally close solution afterwards
dte.Solution.Close();

Exporting subprojects

ExportChild, available at ITcSmTreeItem, can be used to export individual subprojects. The first parameter specifies the name of the child element to be exported, and the second specifies the target file path.

// Export PLC project as .tpzip
ITcSmTreeItem plc = sysManager.LookupTreeItem("TIPC");
plc.ExportChild("PLC1", @"C:\Archives\PLC1.tpzip");

// Export POUs as .zip
ITcSmTreeItem pous = sysManager.LookupTreeItem("TIPC^PLC1^PLC1 Project^POUs");
pous.ExportChild("", @"C:\Archives\POUs.zip");