#Requires -RunAsAdministrator $ErrorActionPreference = 'Continue' $dte = New-Object -ComObject TcXaeShell.DTE.17.0 $dte.MainWindow.Visible = $true try { $dte.SuppressUI = $false } catch {} $dte.Solution.Open('C:\Users\tonycao\work\twincat3-auto-cli\TwinCAT_EL6695_Primary\TwinCATProject1.sln') Start-Sleep 20 $sm = $null for ($i = 0; $i -lt 20; $i++) { try { $sm = $dte.Solution.Projects.Item(1).Object; if ($sm) { break } } catch {} Start-Sleep 3 } if (-not $sm) { Write-Host 'no sysmgr'; exit 1 } Write-Host '--- SysManager members matching Link ---' $sm | Get-Member | Where-Object Name -match 'Link' | ForEach-Object { Write-Host "$($_.MemberType) $($_.Name)" } Write-Host '--- All SysManager methods (first 60) ---' $sm | Get-Member -MemberType Method | Select-Object -First 60 -ExpandProperty Name Write-Host '--- Enumerate EL6695 box children ---' $box = $null foreach ($p in @('TIID^设备 1 (EtherCAT)^模块 3 (EK1100)^模块 10 (EL6695)')) { try { $box = $sm.LookupTreeItem($p) } catch { Write-Host "miss: $p : $_" } } if ($box) { Write-Host "box: $($box.Name) childcount=$($box.ChildCount)" for ($j = 1; $j -le [int]$box.ChildCount; $j++) { $ch = $box.Child($j) Write-Host " child[$j]: '$($ch.Name)' type=$($ch.ItemType) sub=$($ch.ItemSubType) cc=$($ch.ChildCount)" if ($ch.Name -match 'IO') { for ($k = 1; $k -le [int]$ch.ChildCount; $k++) { $g = $ch.Child($k) Write-Host " [$k] '$($g.Name)' type=$($g.ItemType) cc=$($g.ChildCount)" } } } }