How to add child items (devices, boxes, terminals, variables etc.)

Requirements

To add child items (devices, boxes, terminals, variables etc.) in a configuration, an instance of the TwinCAT System Manager has to be created and a configuration has to be opened. The LookupTreeItem method of the ITcSysManager interface returns a ITcSmTreeItem interface pointer implemented by the parent tree item referenced by the parents pathname.

This interface contains a CreateChild method.

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 add a child item to a tree item "TIID^Device 1 (FC310x)" the following vbscript code can be used:

Sample (vbscript):

dim tsm
dim item
dim str
dim itemChild
set tsm = CreateObject("TCatSysManager.TcSysManager")
call tsm.OpenConfiguration("c:\twincat\myConfig.wsm")
set item = tsm.LookupTreeItem("TIID^Device 1(FC310x)")
call item.CreateChild("Box 1 (BK3100)",BOXTYPE_BK3100) 

The tree item type of the child is implicit given by the parent type (e.g. child of I/O devices are always I/O boxes, child of bus couplers are always terminals...). The item sub type must be specified as a parameter of  CreateChild. The CreateChild method has same optional parameters that are described in the documentation of that method. 

Optional CreateChild() parameter 'vInfo':

See CreateChild.

See Also

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

Built on Tuesday, Mai 01, 2001