Loading a TwinCAT project from an archive
TwinCAT supports two methods for importing projects: The entire solution can be restored from a .tnzip archive. Individual subprojects can be imported into a Tree Item via ImportChild.
Requirements
- TwinCAT XAE is installed and started.
- A DTE connection to the target instance is active.
ITcSysManageris initialized in an STA thread.- An archive file named
.tnzipor.zipexists.
Loading a solution from archive
The ITcArchivePersist interface is available via dte.GetObject("TcArchivePersist"). LoadFromArchive restores the solution to the specified target folder. An empty path uses the default folder.
using EnvDTE;
// Load entire solution from .tnzip
ITcArchivePersist persist = (ITcArchivePersist)dte.GetObject("TcArchivePersist");
// Second parameter: target folder (empty = default folder)
persist.LoadFromArchive(@"C:\Archives\MyProject.tnzip", @"C:\Projects\Restored");
Importing subprojects
// Import PLC from .tpzip
ITcSmTreeItem plc = sysManager.LookupTreeItem("TIPC");
plc.ImportChild(@"C:\Archives\PLC1.tpzip", "", false, "");
// Import POUs from .zip
ITcSmTreeItem pous = sysManager.LookupTreeItem("TIPC^PLC1^PLC1 Project");
pous.ImportChild(@"C:\Archives\POUs.zip", "", false, "");
Individual subprojects are imported via ImportChild onto the higher-level Tree Item. The first parameter is the path to the archive file.