Beckhoff Automation GmbH & Co. KG — 5.1.2 Browsing TwinCAT configuration

Configuration Browsing all tree items (unfiltered) To browse all tree items in an unfiltered way, the property ITcSmTreeItem [ } 37] ::_NewEnum may be used. _NewEnum iterates over all subnodes of the currently referenced ITcSmTreeItem [ } 37] . This (COM-) property is used by many Programming and Script languages that support the COM Enumerator model (e.g. .NET languages, VB6 or script languages) by a 'foreach' statement. For non-supporting languages like C++ the foreach loop must be implemented manually by using the IEnumVariant interface. We recommend to use this way to iterate through child nodes. Sample (C#):

ITcSmTreeItem parent = sysMan.LookupTreeItem("TIID^Device1^EK1100"); foreach(ITcSmTreeItem child in parent) { Console.WriteLine(child.Name); } Sample (C++): ... #import "C: \TwinCAT3\Components\Base\TCatSysManager.tlb" // Imports the System Manager / XAE Base Type library // Usage of automatically generated Auto-Pointers (see MSDN documentation of #import statement) ...

void CSysManDialog::IterateCollection(TCatSysManagerLib::ITcSmTreeItemPtr parentPtr) { IEnumVARIANTPtr spEnum = parentPtr->_NewEnum; ULONG nReturned = 0; VARIANT variant[1] = {0}; HRESULT hr = E_UNEXPECTED; do { hr = spEnum->Next(1, &variant[0], &nReturned); if(FAILED(hr)) break; for(ULONG i = 0; i { IDispatchPtr dispatchPtr; IDispatch* pDispatch; TCatSysManagerLib::ITcSmTreeItemPtr childPtr; HRESULT hr; if(variant[0].vt == VT_DISPATCH) { TCatSysManagerLib::ITcSmTreeItem* pChild = 0; dispatchPtr.Attach((variant[0].pdispVal)); hr = dispatchPtr.QueryInterface(__uuidof(TCatSysManagerLib::ITcSmTreeItem), rein terpret_cast(&pChild)); childPtr.Attach(pChild); _bstr_t strName = pChild->GetName(); } } } while(hr != S_FALSE); // S_FALSE indicates end of collection } Sample (IronPython):

parent = systemManager.LookupTreeItem("TIRC"); for child in parent : print child.Name Sample (PowerShell): $systemItem = $systemManager.LookupTreeItem("TIRC") foreach($child in $systemItem) { write-host$child.Name } Browsing Main Tree Items (Filtered) For browsing only the main childs of the current tree item use the ITcSmTreeItem::ChildCount [ } 37] and ITcSmTreeItem:Child(n) [ } 30] pair of properties. These methods only work on the direct childs (non- recursive). Automation Interface 19 Version: 1.2