How to change the path to a plc project and/or rescan the project

Requirements

To change the path to a plc project and/or rescan the project in a configuration, an instance of the TwinCAT System Manager must be created, and the configuration has to be opened. The LookupTreeItem method of the ITcSysManager interface returns a ITcSmTreeItem interface pointer implemented by the tree item referenced by its pathname

This interface contains a ConsumeXml method of the tree item.

Procedure

The ProgId "TCatSysManager.TcSysManager" can be used to create an instance of the System Manager that implements the ITcSysManager interface. This interface has a LookupTreeItem method that returns a ITcSmTreeItem pointer to a specific tree item given by its pathname. To change the path to a plc project and rescan the project "TIPC^MyProject" the following vbscript code can be used:

Sample (vbscript):

dim tsm
dim item
set tsm = CreateObject("TCatSysManager.TcSysManager")
call tsm.OpenConfiguration("c:\twincat\myConfig.wsm")
set item = tsm.LookupTreeItem("TIPC^MyProject")
call item.ConsumeXml("<TreeItem><PlcDef><ProjectPath>c:\twincat\plc\NewProject.pro</ProjectPath><ReScan>1</ReScan></PlcDef></TreeItem>")

call tsm.SaveConfiguration

The next sample just rescans the current project:

dim tsm
dim item
set tsm = CreateObject("TCatSysManager.TcSysManager")
call tsm.OpenConfiguration("c:\twincat\myConfig.wsm")
set item = tsm.LookupTreeItem("TIPC^MyProject")
call item.ConsumeXml("<TreeItem><PlcDef><ReScan>1</ReScan></PlcDef></TreeItem>")

call tsm.SaveConfiguration

See Also

How to... section, ITcSysManager, LookupTreeItem, ITcSmTreeItem, ConsumeXml

Built on Tuesday, Mai 01, 2001