' Description: Connection List (Excel) ' ' Changes: ' 30.11.99 CIM-Team Initial Version ' 15.02.00 CIM-Team New layout ' 30.07.2002 CIM-Team Added multi language ' 30.07.2002 CIM-Team Added wire/cable information ' 13.07.2003 CIM-Team Changes for version 2003 ' 04.08.2003 CIM-Team [r]Changes for Logic Version ' 22.08.2003 CIM-Team Connections to shield symbols will be handled correctly ' 08.08.2004 CIM-Team [r1] IsLogic is now a method so obsolent call ' 18.08.2004 CIM-Team Added control of internal/external execution ' 04.04.2005 CIM-Team Added portuguese strings ' 28.07.2005 CIM-Team added strings for chinese and russian ' 03.01.2006 CIM-Team options will be handeled correctly [1a] ' - EOH - '... ' Connect to application and declare object variables to call methods later Set App = ConnectToE3 set Job = App.CreateJobObject set Con = Job.CreateConnectionObject set Dev = Job.CreateDeviceObject set Pin = Job.CreatePinObject set Cab = Job.CreateDeviceObject set Cor = Job.CreatePinObject set Net = Job.CreateNetSegmentObject set Sym = Job.CreateSymbolObject set Bnd = Job.CreateBundleObject set File = CreateObject( "Scripting.FileSystemObject" ) set WshShell = CreateObject("WScript.Shell") '[r1]IsLogic = App.GetLicense( "E3logic" ) '[r] If App.IsLogic Then '[r1] FileName = App.GetInstallationPath & "reports\ConnectionLogic.xlt" Else FileName = App.GetInstallationPath & "reports\Connection.xlt" End If WireNumber = "WireNumber" Set ShieldTab1 = CreateObject("Scripting.Dictionary") Set ShieldTab2 = CreateObject("Scripting.Dictionary") Set myOptionList = CreateObject( "Scripting.Dictionary" ) Set myNetSegmentList = CreateObject( "Scripting.Dictionary" ) message = """" & App.GetInstallationPath & "scripts\message.vbs" & """" language = App.GetInstallationLanguage select case language case "01" text1 = "From" text2 = "To" text3 = "Signal" text4 = "Device name" text5 = "Pin" text6 = "Connection List:" text7 = "Number" text8 = "Type" text9 = "Color" text10 = "Gauge" text11 = "Cable name" text12 = "Wire/Conductor" text13 = "_CON" text14 = "Connection List" case "44" text1 = "From" text2 = "To" text3 = "Signal" text4 = "Device name" text5 = "Pin" text6 = "Connection List:" text7 = "Number" text8 = "Type" text9 = "Colour" text10 = "Cross-section" text11 = "Cable name" text12 = "Wire/Core" text13 = "_CON" text14 = "Connection List" case "49" text1 = "Von" text2 = "Nach" text3 = "Signal" text4 = "Betriebsmittelk." text5 = "Anschluss" text6 = "Verbindungsliste:" text7 = "Nummer" text8 = "Typ" text9 = "Farbe" text10 = "Querschnitt" text11 = "Kabelname" text12 = "Draht-/Ader" text13 = "_VER" text14 = "Verbindungsliste" case "33" text1 = "De" text2 = "A" text3 = "Signal" text4 = "Nom d'appareil" text5 = "Broche" text6 = "Liste des connexions:" text7 = "Numéro" text8 = "Type" text9 = "Couleur" text10 = "Section" text11 = "Nom du câble" text12 = "fil/brin" text13 = "_CON" text14 = "Liste des connexions" case "34" text1 = "Desde" text2 = "Hasta" text3 = "Señal" text4 = "Designación de dispositivo:" text5 = "Pin" text6 = "Liste de conexiones:" text7 = "Número" text8 = "Tipo" text9 = "Color" text10 = "Sección cruzada" text11 = "Nombre manguera" text12 = "Hilo/vena" text13 = "_CON" text14 = "Liste de conexiones" case "39" text1 = "Da" text2 = "A" text3 = "Segnale" text4 = "Sigla dispositivo" text5 = "Pin" text6 = "Lista connessioni:" text7 = "Numero" text8 = "Tipo" text9 = "Colore" text10 = "Sezione" text11 = "Nome cavo" text12 = "Filo/conduttore" text13 = "_CON" text14 = "Lista connessioni" case "55" text1 = "De" text2 = "Para" text3 = "Sinal" text4 = "Nome de dispositivo" text5 = "Pino" text6 = "Lista de conexões:" text7 = "Número" text8 = "Tipo" text9 = "Cor" text10 = "Secção" text11 = "Nome do Cabo" text12 = "Fio/Condutor" text13 = "_CON" text14 = "Lista de Conexões" case "07" text1 = "Откуда" text2 = "Куда" text3 = "Цепь" text4 = "Поз. обозначение" text5 = "Вывод" text6 = "Таблица соединений:" text7 = "Номер" text8 = "Тип" text9 = "Цвет" text10 = "Сечение" text11 = "Кабель" text12 = "Провод/Жила" text13 = "_CON" text14 = "Таблица соединений" case "86" text1 = "来自" text2 = "到" text3 = "信号" text4 = "设备名" text5 = "针脚" text6 = "连接列表:" text7 = "号码" text8 = "类型" text9 = "颜色" text10 = "电缆横截面" text11 = "电缆名" text12 = "电线/芯线" text13 = "_CON" text14 = "连接列表" case "90" text1 = "From" text2 = "To" text3 = "Signal" text4 = "Device name" text5 = "Pin" text6 = "Connection List:" text7 = "Number" text8 = "Type" text9 = "Colour" text10 = "Cross-section" text11 = "Cable name" text12 = "Wire/Core" text13 = "_CON" text14 = "Connection List" case else text1 = "From" text2 = "To" text3 = "Signal" text4 = "Device name" text5 = "Pin" text6 = "Connection List:" text7 = "Number" text8 = "Type" text9 = "Colour" text10 = "Cross-section" text11 = "Cable name" text12 = "Wire/Core" text13 = "_CON" text14 = "Connection List" end select if Job.GetId = 0 then ' check connection to project WshShell.run message & " No_Project" set app = nothing set File = nothing set WshShell = nothing Set ShieldTab1 = nothing Set ShieldTab2 = nothing wscript.quit end if nCons = Job.GetConnectionIds (ConIds) ' get connection ids if nCons = 0 then WshShell.run message & " No_Connections" set app = nothing set File = nothing set WshShell = nothing Set ShieldTab1 = nothing Set ShieldTab2 = nothing wscript.quit end if ReDim SortField(nCons,2) JobName = Job.GetName ' read project name nCabs = Job.GetCableIds (CabIds) for i = 1 to nCabs Cab.SetId CabIds(i) nBunds = Cab.GetBundleIds (BundIds) for j = 1 to nBunds Bnd.SetId BundIds(j) if Bnd.IsShield = 1 then nSyms = Bnd.GetSymbolIds (SymIds) for k = 1 to nSyms ShieldTab1.item(cstr(SymIds(k))) = CabIds(i) ShieldTab2.item(cstr(SymIds(k))) = Bnd.GetName next end if next next for n = 1 to nCons ' loop around formerly read connections Con.SetId ConIds(n) ' read signal name SortField(n-1,1) = ConIds(n) SortField(n-1,2) = Con.GetSignalName nPins = Con.GetPinIds (PinIds) ' read connected pins if nPins > 0 then Pin.SetId PinIds(1) SortField(n-1,2) = Pin.GetSignalName end if next ret = App.SortArrayByIndex (SortField, nCons, 3, 3, 0) ' sort by signal names if File.FileExists( FileName ) then ' check for existing file set ExcelApp = CreateObject("Excel.Application") ExcelApp.Visible = TRUE ' open EXCEL set Excel = ExcelApp.WorkBooks.Open(FileName) set Excel = ExcelApp.ActiveWorkBook.WorkSheets(1) Excel.Name = text14 excelName = Job.GetPath & Job.GetName & text13 if File.FileExists (excelName & ".xls") then File.DeleteFile excelName & ".xls" Excel.Cells(4,2).Value = text1 ' Write head lines Excel.Cells(4,4).Value = text2 Excel.Cells(5,1).Value = text3 Excel.Cells(5,2).Value = text4 Excel.Cells(5,3).Value = text5 Excel.Cells(5,4).Value = text4 Excel.Cells(5,5).Value = text5 If App.IsLogic = 0 Then '[r] Excel.Cells(4,6).Value = text12 Excel.Cells(5,6).Value = text7 Excel.Cells(5,7).Value = text8 Excel.Cells(5,8).Value = text9 Excel.Cells(5,9).Value = text10 Excel.Cells(5,10).Value = text11 End If '[r] Excel.Cells(2,1).Value = text6 Excel.Cells(2,4).Value = JobName nline = 5 for n = 0 to nCons-1 ' Loop around all connections Con.SetId SortField(n,1) Signal = SortField(n,2) If( IsConnectionActive( con ) ) Then ' [1a] nPins = Con.GetPinIds (PinIds) ' read connected pins if nPins = 2 and Con.IsValid then ' if we found a valid connection nline = nline + 1 ' write global connection data Pin.SetId PinIds(1) Sym.SetId PinIds(1) Dev.SetId PinIds(1) call write_first_destination Pin.SetId PinIds(2) Sym.SetId PinIds(2) Dev.SetId PinIds(2) call write_second_destination nCors = Con.GetCoreIds (CoreIds) if nCors = 0 then call write_wire_number else for i = 1 to nCors Cor.SetId CoreIds(i) If( IsCoreActive( cor ) ) Then ' [1a] Cab.SetId CoreIds(i) If( IsCableActive( Cab ) ) Then ' [1a] if Cab.IsWireGroup = 0 then Excel.Cells(nline,10) = "'" & trim(Cab.GetAssignment & Cab.GetLocation & Cab.GetName) Excel.Cells(nline,7) = Cab.GetComponentName else Cor.GetWireType WireTyp1, WireTyp2 Excel.Cells(nline,7) = WireTyp1 & "-" & WireTyp2 end if Excel.Cells(nline,6) = Cor.GetName Excel.Cells(nline,9) = Cor.GetCrossSectionDescription Excel.Cells(nline,8) = Cor.GetColourDescription end if end if next end if elseif nPins > 1 then ' for non unique connections nline = nline + 1 ' write each pin on a seperate line for n2 = 1 to nPins if n2 = 2 then Signal = " '' " Pin.SetId PinIds(n2) Sym.SetId PinIds(n2) Dev.SetId PinIds(n2) call write_first_destination call write_wire_number nline = nline + 1 next nline = nline -1 end if end if next nline = nline + 2 ' Write trailer Excel.Range("A"&nline&":E"&nline).Select ExcelApp.Selection.Font.Bold = True ExcelApp.Selection.Font.Italic = True ExcelApp.Selection.Font.ColorIndex = 3 Excel.Cells(nline,2).Value = "***** Created by CIM-Team " & App.GetName & " *****" ExcelApp.ActiveWorkbook.SaveAs excelName ' ExcelApp.Quit Set Excel = Nothing Set ExcelApp = Nothing else WshShell.run message & " File_Not_Existing", 7, true App.PutInfo 0, FileName end if set app = nothing set File = nothing set WshShell = nothing Set ShieldTab1 = nothing Set ShieldTab2 = nothing wscript.quit ' ------------------------------------------------------------------------------------------------- sub write_first_destination Excel.Cells(nline,1).Value = Signal if ShieldTab1.exists(cstr(Sym.GetId)) then Dev.SetId ShieldTab1.item(cstr(Sym.GetId)) Excel.Cells(nline,2).Value = "'" & trim(Dev.GetAssignment & Dev.GetLocation & Dev.GetName) if ShieldTab2.exists(cstr(Sym.GetId)) then Excel.Cells(nline,3).Value = ":" & ShieldTab2.item(cstr(Sym.GetId)) else Excel.Cells(nline,3).Value = ":" & GetInternalDevice & Pin.GetName end if end sub ' ------------------------------------------------------------------------------------------------- sub write_second_destination if ShieldTab1.exists(cstr(Sym.GetId)) then Dev.SetId ShieldTab1.item(cstr(Sym.GetId)) Excel.Cells(nline,4).Value = "'" & trim(Dev.GetAssignment & Dev.GetLocation & Dev.GetName) if ShieldTab2.exists(cstr(Sym.GetId)) then Excel.Cells(nline,5).Value = ":" & ShieldTab2.item(cstr(Sym.GetId)) else Excel.Cells(nline,5).Value = ":" & GetInternalDevice & Pin.GetName end if end sub ' ------------------------------------------------------------------------------------------------- sub write_wire_number zWireNum = Con.GetAttributeValue (WireNumber) if zWireNum = "" then nSegs = Con.GetNetSegmentIds (NetSegIds) if nSegs > 0 then Net.SetId NetSegIds(1) zWireNum = Net.GetAttributeValue (WireNumber) end if end if if zWireNum <> "" then Excel.Cells(nline,6).Value = zWireNum end sub ' ------------------------------------------------------------------------------------------------- function GetInternalDevice text = Pin.GetAttributeValue (".CONNECTOR_NAME") if text <> "" then text = text & "." GetInternalDevice = text end function ' ---------------------------------------------------------------------------------------------- ' check for several E3 processes and if process is running internally or externally function ConnectToE3 if InStr(WScript.FullName, "E³") then set ConnectToE3 = WScript ' internal else strComputer = "." set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") set colItems = objWMIService.ExecQuery("Select * from Win32_Process",,48) ProcessCnt = 0 for each objItem in colItems if InStr(objItem.Caption, "E3.series") then ProcessCnt = ProcessCnt + 1 next set objWMIService = Nothing set colItems = Nothing if ProcessCnt > 1 then MsgBox "More than one E3-Application running. Script can't run as external program." & vbCrLf &_ "Please close the other E3-Applications.", 48 WScript.Quit else set ConnectToE3 = CreateObject ("CT.Application") ' external end if end if end function ' ---[1a]------------------------------------------------------------------------------------------- Function IsObjectActive( obj, cnt ) ' IsObjectActive() ---------------------------------------------- IsObjectActive = True ' Default is active Dim ids, o, opt cnt = obj.GetAssignedOptionIds( ids ) If( cnt > 0 ) Then ' But if it has options, at least one must be active IsObjectActive = False For o = 1 To cnt Set opt = GetOption( ids(o) ) If( opt.active = 1 ) Then IsObjectActive = True Exit For End If Next End If End Function Function IsConnectionActive( cx ) ' IsConnectionActive() --------------------------------------- IsConnectionActive = False ' Default is inactive here Dim nscnt, nsids, n, ns ' if any ns is inactive, it deactivates the connection nscnt = cx.GetNetSegmentIds( nsids ) For n = 1 To nscnt Set ns = GetNetSegment( nsids(n) ) If( ns.active = 0 ) Then Exit Function End If Next IsConnectionActive = True End Function Function IsCoreActive( cor ) ' IsCoreActive() --------------------------------------- IsCoreActive = False ' Default is inactive here Dim cnt ' Core itself deactivated? If( Not IsObjectActive( cor, cnt ) ) Then Exit Function Dim nscnt, nsids, n, ns ' if any ns is inactive, it deactivates the core nscnt = cor.GetNetSegmentIds( nsids ) For n = 1 To nscnt Set ns = GetNetSegment( nsids(n) ) If( ns.active = 0 ) Then Exit Function End If Next IsCoreActive = True End Function Function IsCableActive( cab ) ' IsCoreActive() --------------------------------------- IsCableActive = False ' Default is inactive here Dim cnt ' Cable itself deactivated? If( Not IsObjectActive( cab, cnt ) ) Then Exit Function IsCableActive = True End Function '------------------------------------------------------------------------------ CNetSegment ----------------------------- Class CNetSegment Dim app, id, Name, view, active, optcnt Sub Dump( msg ) ' Dump( msg ) If( myDebugLevel > 0 ) Then e3.PutMessage msg & ": NetSegment" _ & " id=" & id _ & " name=" & Name _ & " view=" & view _ & " #opts=" & optcnt _ & " active=" & active End Sub Sub Init( ns ) ' Init( id ) Set app = ns id = ns.GetId Name = ns.GetName view = ns.IsView active = IsObjectActive( app, optcnt ) Dump "init" End Sub End Class Function GetNetSegment( anyid ) ' GetNetSegment() returns a CNetSegment Dim app, id, obj Set app = Job.CreateNetSegmentObject: app.SetId anyid: id = app.GetId Set obj = New CNetSegment If( myNetSegmentList.Exists( id ) ) Then Set GetNetSegment = myNetSegmentList(id) Else obj.Init( app ) myNetSegmentList.Add id, obj Set GetNetSegment = obj End If End Function '------------------------------------------------------------------------------ COption ----------------------------- Class COption Dim app, id, Name, active Sub Dump( msg ) ' Dump( msg ) If( myDebugLevel <= 0 ) Then Exit Sub e3.PutMessage msg & ": Option" _ & " id=" & id _ & " name=" & name _ & " active=" & active End Sub Sub Init( opt ) ' Init( id ) Set app = opt id = app.GetId Name = app.GetName active = 0 If( app.IsActive() ) Then active = 1 Dump "init" End Sub End Class Function GetOption( anyid ) ' GetOption() returns a COption Dim app, id, obj Set app = Job.CreateOptionObject: app.SetId anyid: id = app.GetId Set obj = New COption If( myOptionList.Exists( id ) ) Then Set GetOption = myOptionList(id) Else obj.Init( app ) myOptionList.Add id, obj Set GetOption = obj End If End Function