def PyFindMinPowerCableSize(argv): if (type(argv) == type([])) and (7 == len(argv)): Install = argv[0] TotalDF = SAFE_FLOAT(argv[1]) FLC = SAFE_FLOAT(argv[2]) SF = SAFE_FLOAT(argv[3]) UGCableAmbTemp = argv[4] AGCableAmbTemp = argv[5] NoOfCable = SAFE_FLOAT(argv[6]) CableAmbTemp = 0 try: if 'A/G' == Install: CableAmbTemp = SAFE_FLOAT(AGCableAmbTemp) elif 'U/G' == Install: CableAmbTemp = SAFE_FLOAT(UGCableAmbTemp) else: ELoadApp.AppendLogToOutputWnd(loadname + ': Install Value Error') return 'FAIL' if (FLC*SF) < (CableAmbTemp*TotalDF*NoOfCable): return 'SUCCESS' else: return 'FAIL' except: ELoadApp.AppendLogToOutputWnd(traceback.format_exc()) return 'FAIL'
def PySearchLoadTablePFandEFF(Rating_Capacity , Rated_Voltage , Poles, LF): res = ELoadApp.SearchLoadTable(Rating_Capacity,Rated_Voltage,Poles, LF) # TEST if type(res) is type([]) and (len(res) == 10): # °ªA≫ A¤≫oAuA¸·I A£¾O´U¸e ¸®½ºÆ®¿¡ ´a¾Æ ³N°UAØ´U. try: PF100 = SAFE_FLOAT(res[0]) PF100 = SAFE_ROUND(PF100 , 3) PF75 = SAFE_FLOAT(res[1]) PF75 = SAFE_ROUND(PF75 , 3) PF50 = SAFE_FLOAT(res[2]) PF50 = SAFE_ROUND(PF50 , 3) EFF100 = SAFE_FLOAT(res[3]) EFF100 = SAFE_ROUND(EFF100 , 3) EFF75 = SAFE_FLOAT(res[4]) EFF75 = SAFE_ROUND(EFF75 , 3) EFF50 = SAFE_FLOAT(res[5]) EFF50 = SAFE_ROUND(EFF50 , 3) PF = SAFE_FLOAT(res[6]) PF = SAFE_ROUND(PF , 3) EFF = SAFE_FLOAT(res[7]) EFF = SAFE_ROUND(EFF, 3) LRC = SAFE_FLOAT(res[8]) LRC = SAFE_ROUND(LRC , 3) PFlr = SAFE_FLOAT(res[9]) PFlr = SAFE_ROUND(PFlr , 3) return [PF100,PF75,PF50,EFF100,EFF75,EFF50,PF,EFF,LRC,PFlr] except: ELoadApp.AppendLogToOutputWnd(traceback.format_exc()) return [0,0,0,0,0,0,0,0,0,0]
def PyBHPAutoCalc(BHP,Load_Category,Rating_Capacity): if '' == BHP: # 사용자가 값을 입력하지 않았다면 자동으로 계산한다. if 'MOTOR' == Load_Category: if Rating_Capacity <= 19: return (Rating_Capacity/1.25) elif (Rating_Capacity > 19) and (Rating_Capacity < 75): return (Rating_Capacity/1.15) else: return (Rating_Capacity/1.1) else: LF = 0.9 # 기본값을 0.9로 둔다. if Load_Category == 'LTG': LF = SAFE_FLOAT(ELoadApp.GetFieldValueInProjectSettingTable('C_LTG_LF')) elif Load_Category == 'WELDING': LF = SAFE_FLOAT(ELoadApp.GetFieldValueInProjectSettingTable('C_WELDING_LF')) elif Load_Category == 'INST.': LF = SAFE_FLOAT(ELoadApp.GetFieldValueInProjectSettingTable('C_INST_LF')) elif Load_Category == 'COMM.': LF = SAFE_FLOAT(ELoadApp.GetFieldValueInProjectSettingTable('C_COMM_LF')) elif Load_Category == 'OTHERS': LF = SAFE_FLOAT(ELoadApp.GetFieldValueInProjectSettingTable('C_OTHERS_LF')) return Rating_Capacity*LF else: return BHP
def PyAutoCalculateStartingAmp(args): LRC = ELoadApp.GetLoadProp(args[0] , 'Characteristic' , 'LRC') FLC = ELoadApp.GetLoadProp(args[0] , 'Rating' , 'FLC') if (LRC != '') and (FLC != ''): StartingAmp = SAFE_FLOAT(LRC) * SAFE_FLOAT(FLC) * 0.01 return ('%.2f' % StartingAmp) return ''
def PyGenerateBusDiagram(argv): try: strExecPath = ELoadApp.GetExecPath() if '\\' != strExecPath[len(strExecPath) - 1]: strExecPath = strExecPath + '\\' except: ELoadApp.AppendLogToOutputWnd(traceback.format_exc()) try: dotfile = open(strExecPath + 'temp\BusDiagram.dot', 'w') contents = 'digraph G {' + '\n' #contents = contents + 'graph[\n rankdir = "LR"\n ];\n' contents = contents + 'node [shape = record,height=.1,fontsize=10, shape = box, fontname="Arial"];\n' #contents = contents + 'BusDiagram\n' drawed_bus_list = [] StartBusNameList = PyGetStartBus() # get all start bus name for bus in StartBusNameList: #if 'Not Assigned' == busgroup: # continue contents = contents + '"' + str(bus) + '"[label="' + str( bus) + '",shape=box];' + '\n' drawed_bus_list.append(str(bus)) contents = PyGenerateSubDiagramOf(contents, bus, drawed_bus_list) #* EQUIPMENT와 연결되지 않은 BUS들을 그린다. BusNameList = ELoadApp.GetBusNameList('ALL') label = '' for bus in BusNameList: drawed = False for drawed_bus in drawed_bus_list: if drawed_bus == bus: drawed = True break if False == drawed: contents = contents + '"' + str(bus) + '"[label="' + str( bus) + '",shape=box];' + '\n' drawed_bus_list.append(str(bus)) contents = PyGenerateSubDiagramOf(contents, bus, drawed_bus_list) #label = label + str(bus) + '|' #label = label[0:len(label)-1] #if label != '': # contents = contents + 'node [shape=record];' # contents = contents + 'struct1 [label="' + label + '",style=filled,fillcolor=gray];' contents = contents + '}' + '\n' dotfile.write(contents) dotfile.close() PyConvertDOTToJPEG(strExecPath + 'temp\BusDiagram.dot', strExecPath + 'temp\BusDiagram.jpg') except: ELoadApp.AppendLogToOutputWnd(traceback.format_exc())
def PyGetTrNameConnectedToBus(bus): res = [] TrNameList = ELoadApp.GetTransformerNameList() for tr in TrNameList: ConnectedBusID = ELoadApp.GetTransformerProp(tr, 'From', 'Bus Id') if bus == ConnectedBusID: res.append(tr) return res
def PyGetUPSDCNameConnectedToBus(bus): res = [] UPSDCItemList = ELoadApp.GetELoadItemListOf('UPSDC') for upsdc in UPSDCItemList: BusID1 = ELoadApp.GetELoadItemProp('UPSDC', upsdc, 'From1', 'Bus ID') BusID2 = ELoadApp.GetELoadItemProp('UPSDC', upsdc, 'From2', 'Bus ID') if (bus == BusID1) or (bus == BusID2): res.append(upsdc) return res
def PyGetPDBNameConnectedToBus(bus): res = [] LoadNameList = ELoadApp.GetLoadNameListInBus(bus) for load in LoadNameList: LoadCategory = ELoadApp.GetLoadProp(load, 'Type', 'Load Category') ConnectedBusID = ELoadApp.GetLoadProp(load, 'Panel', 'Connect Bus') if ('SubBUS' == LoadCategory) and (ConnectedBusID != ''): res.append(ConnectedBusID) return res
def PyCheckLoadPropForPowerCableCreation(argv): res = 'SUCCESS' if (type(argv) == type([])) and (1 == len(argv)): LoadCategory = ELoadApp.GetLoadProp(argv[0] , 'Type' , 'Load Category') if ('' == LoadCategory) or (('MOTOR' != LoadCategory) and ('LTG' != LoadCategory) and ('WELDING' != LoadCategory) and ('INST.' != LoadCategory) and ('COMM.' != LoadCategory) and ('OTHERS' != LoadCategory) and ('SubBUS' != LoadCategory)): ELoadApp.ELOAD_LOG4CXX(['ERROR' , argv[0] , 10]) return 'FAIL' value = ELoadApp.GetLoadProp(argv[0] , 'Cable Route' , 'Design Length') if '' == value: ELoadApp.ELOAD_LOG4CXX(['ERROR' , argv[0] , 16]) #res = 'FAIL' return 'FAIL' UseRealKVA = ELoadApp.GetLoadProp(argv[0] , 'Panel' , 'Real KVA For Power Cable') if ('SubBUS' == LoadCategory) and ('YES' == UseRealKVA.upper()): # Load Category가 SubBUS이고 Real KVA For Power Cable의 값이 YES일때에는 Connect Bus값이 설정되어야 한다. value = ELoadApp.GetLoadProp(argv[0] , 'Panel' , 'Connect Bus') if '' == value: ELoadApp.ELOAD_LOG4CXX(['ERROR' , argv[0] , 24]) #res = 'FAIL' return 'FAIL' else: # Load Category가 SubBUS가 아니거나 Real KVA For Power Cable의 값이 YES가 아닐때에는 FLC값이 있어야 한다. value = ELoadApp.GetLoadProp(argv[0] , 'Rating' , 'FLC') if ('' == value) or ('0' == value): ELoadApp.ELOAD_LOG4CXX(['ERROR' , argv[0] , 17]) # res = 'FAIL' return 'FAIL' #return 'SUCCESS' return 'SUCCESS'
def PyWriteTotalLoadSummaryToExcel(wb,type,FolderPath): projectno = ELoadApp.GetProjectNo() projectname = ELoadApp.GetProjectName() documentno = ELoadApp.GetDocumentNo() try: # ELoadApp.AppendLogToOutputWnd('bus') wb.Worksheets('TOTAL').Copy(Before=wb.Worksheets('TOTAL')) ws = wb.ActiveSheet ws.Name = 'TOTAL_' + type PROJECT_FOLDER = ELoadApp.GetProjectFolder() busfile = open(FolderPath + '\\Total' + type + '.bus', 'r') row = 10 no = 1 buffer = busfile.readlines() for index in range(1,len(buffer)-1): ws.Range('A'+str(row + 1) +':X'+str(row + 1)).Insert() ws.Cells(row,2).Value = str(no) row = row + 1 no = no + 1 row = 10 for line in buffer: list = line.rstrip('\n').split('\t') col = 3 for item in list: if (len(item) >= 1) and ('*' == item[len(item) - 1]): # it is modified item. so filled with red. ws.Cells(row,col).Value = item[0:len(item)-1] ws.Cells(row,col).Interior.ColorIndex = 44 else: ws.Cells(row,col).Value = item col = col + 1 row = row + 1 #if line.find('TOTAL') == -1 and line != '\n': # ws.Range('A'+str(row) +':X'+str(row)).Insert() ws.Cells(3,1).Value = 'PROJECT : ' + projectno ws.Cells(4,1).Value = 'PROJECT NAME : ' + projectname #ws.Cells(3,4).Value = ELoadApp.GetProjectClient() # 현재 날짜를 표기한다. now = time.localtime() ws.Cells(4,19).Value = 'DATE : ' + '%d' % now.tm_year + '.' + '%d' % now.tm_mon + '.' + '%d' % now.tm_mday #ws.Cells(3,8).Value = documentno ws.Columns('A:A').EntireColumn.AutoFit() except: ELoadApp.AppendLogToOutputWnd(traceback.format_exc())
def reloadall(): try: import sys modsreloaded = {} for sym, obj in globals().items(): if hasattr(obj, '__module__'): mod = obj.__module__ if mod.startswith('__'): continue if mod not in modsreloaded: modsreloaded[mod] = reload(sys.modules[obj.__module__]) globals()[sym] = getattr(modsreloaded[mod], sym) except: ELoadApp.AppendLogToOutputWnd(traceback.format_exc()) ELoadApp.AppendLogToOutputWnd('format_exc()')
def PyFindPowerCableSize(argv): if (type(argv) == type([])) and (9 == len(argv)): ID = argv[0] Phase = argv[1] L = SAFE_FLOAT(argv[2]) R = SAFE_FLOAT(argv[3]) X = SAFE_FLOAT(argv[4]) PF = argv[5] I = round(SAFE_FLOAT(argv[6]),2) MotorVD = SAFE_FLOAT(argv[7]) MULTIPLY = SAFE_FLOAT(argv[8]) try: COS = SAFE_FLOAT(PF) ELoadApp.AppendLogToOutputWnd('COS : ' + str(COS)) #Phase = ELoadApp.GetLoadProp(loadname , 'Rating' , 'Phase') #L = SAFE_FLOAT(ELoadApp.GetLoadProp(loadname , 'Cable Route' , 'Design Length')) #I = SAFE_FLOAT(I) #ELoadApp.GetLoadProp(loadname , 'Voltage Drop' , 'SF For FLC')) #R = SAFE_FLOAT(R) #X = SAFE_FLOAT(X) if '3' == Phase: # 3PH MOTOR or 3PH FEEDER SIN = math.sqrt(1 - math.pow(COS,2)) VD = (L*math.sqrt(3)*I*(R*COS + X*SIN))/1000. elif '1' == Phase: # 1PH FEEDER or 1PH MOTOR SIN = math.sqrt(1 - math.pow(COS,2)) VD = (L*2*I*(R*COS + X*SIN))/1000. elif 'DC' == Phase: # DC FEEDER VD = (L*2*I*R)/1000. else: ELoadApp.AppendLogToOutputWnd(ID + ': Phase Value Error') return ['FAIL',0.] VD = VD/MULTIPLY if VD <= (MotorVD): VD = round(VD,2) return ['SUCCESS',VD] else: VD = round(VD,2) return ['FAIL',VD] except: ELoadApp.AppendLogToOutputWnd(traceback.format_exc()) return ['FAIL',0.]
def SAFE_FLOAT(arg): try: res = float(arg) return res except ValueError: return 0 except TypeError: ELoadApp.AppendLogToOutputWnd('TypeError = ' + str(arg)) return 0 return 0
def PyGetPFIfLockIsYes(loadname,PFandEFF,LF): # item에서 PF,EFF 값을 가져온다.(LF값을 기준으로 찾아온다.) PFS = [0,0,0] PFS[0] = SAFE_FLOAT(ELoadApp.GetLoadProp(loadname,'Characteristic','PF(50% Load)')) PFS[1] = SAFE_FLOAT(ELoadApp.GetLoadProp(loadname,'Characteristic','PF(75% Load)')) PFS[2] = SAFE_FLOAT(ELoadApp.GetLoadProp(loadname,'Characteristic','PF(100% Load)')) # 100%의 값이 없을 경우에는 테이블에서 구한다. if 0. == PFS[2]: if type(PFandEFF) is type([]) and (len(PFandEFF) == 10): PFS[0] = PFandEFF[2] PFS[1] = PFandEFF[1] PFS[2] = PFandEFF[0] # 구한 값을 저장한다.(100%,75%,50%) param = [loadname,'Characteristic','PF(100% Load)','%.3f' % PFS[2]] ELoadApp.SetLoadProp(param) param[2] = 'PF(75% Load)' param[3] = '%.3f' % PFS[1] ELoadApp.SetLoadProp(param) param[2] = 'PF(50% Load)' param[3] = '%.3f' % PFS[0] ELoadApp.SetLoadProp(param) return PyFindPF(PFS , LF)
def PyCalculatePG1(argv): try: WL = SAFE_FLOAT(argv[0]) L = SAFE_FLOAT(argv[1]) COS= SAFE_FLOAT(argv[2]) PG1 = round((WL * L) / COS , 2) return str(PG1) except: ELoadApp.AppendLogToOutputWnd(traceback.format_exc()) return str('') return str('')
def PyCalculatePG2(argv): try: PLmax = SAFE_FLOAT(argv[0]) V = SAFE_FLOAT(argv[1]) Xd1= SAFE_FLOAT(argv[2]) Xd2= SAFE_FLOAT(argv[3]) PG2 = round(PLmax * ((Xd1 + Xd2) / 2.) * ((1 - V) / V) , 2) return str(PG2) except: ELoadApp.AppendLogToOutputWnd(traceback.format_exc()) return str('') return str('')
def PyCalculatePG3(argv): try: W0 = SAFE_FLOAT(argv[0]) Qlmax = SAFE_FLOAT(argv[1]) COSQl = SAFE_FLOAT(argv[2]) K = SAFE_FLOAT(argv[3]) COSQg = SAFE_FLOAT(argv[4]) PG3 = round((W0 + (Qlmax * COSQl)) / (K * COSQg),2) return str(PG3) except: ELoadApp.AppendLogToOutputWnd(traceback.format_exc()) return str('') return str('')
def PyWriteTotalDrumScheduleListToExcel(wb, FolderPath): PROJECT_FOLDER = ELoadApp.GetProjectFolder() projectno = ELoadApp.GetProjectNo() projectname = ELoadApp.GetProjectName() documentno = ELoadApp.GetDocumentNo() try: wb.Worksheets('DRUM TOTAL TEMP').Copy(Before=wb.Worksheets(wb.Worksheets.Count)) ws = wb.ActiveSheet ws.Name = 'TOTAL-DRUM' except: ELoadApp.AppendLogToOutputWnd(traceback.format_exc()) try: drumscheduleresultfile = open(FolderPath + '\\Total_DrumScheduleResult.txt', 'r') buffer = drumscheduleresultfile.readlines() row = 10 for index in range(1,len(buffer) - 1): ws.Range('A'+str(row + 1) +':I'+str(row + 1)).Insert() row = row + 1 row = 9 for line in buffer: list = line.rstrip('\n').split('\t') col = 1 for item in list: ws.Cells(row,col).Value = item col = col + 1 row = row + 1 ws.Cells(3,1).Value = 'PROJECT : ' + projectno ws.Cells(4,1).Value = 'PROJECT NAME : ' + projectname # 현재 날짜를 표기한다. now = time.localtime() ws.Cells(4,9).Value = 'DATE : ' + '%d' % now.tm_year + '.' + '%d' % now.tm_mon + '.' + '%d' % now.tm_mday ws.Columns('A:A').EntireColumn.AutoFit() drumscheduleresultfile.close() ELoadApp.AppendLogToOutputWnd('Total book End') except: ELoadApp.AppendLogToOutputWnd(traceback.format_exc()) return 'SUCCESS'
def CalculateFLC(Capacity , Motor_Voltage , PF , MotorType): try: if '3PH MOTOR' == MotorType: FLC = Capacity / (math.sqrt(3) * Motor_Voltage * PF) * 1000 elif '3PH FEEDER' == MotorType: KVA = Capacity FLC = KVA / (math.sqrt(3) * Motor_Voltage) * 1000 elif '1PH FEEDER' == MotorType: KVA = Capacity FLC = KVA / (Motor_Voltage) * 1000 else: # 'DC FEEDER' KVA = Capacity FLC = KVA / (Motor_Voltage) * 1000 FLC = round(FLC,2) except: ELoadApp.AppendLogToOutputWnd(traceback.format_exc()) return 0 return FLC
def PyGetEFFIfLockIsYes(loadname,PFandEFF,LF): EFFS= [0,0,0] EFFS[0] = SAFE_FLOAT(ELoadApp.GetLoadProp(loadname,'Characteristic','EFF(50% Load)')) EFFS[1] = SAFE_FLOAT(ELoadApp.GetLoadProp(loadname,'Characteristic','EFF(75% Load)')) EFFS[2] = SAFE_FLOAT(ELoadApp.GetLoadProp(loadname,'Characteristic','EFF(100% Load)')) if 0. == EFFS[2]: # 100%의 값이 없을 경우에는 테이블에서 구한다. if type(PFandEFF) is type([]) and (len(PFandEFF) == 10): EFFS[0] = PFandEFF[5] EFFS[1] = PFandEFF[4] EFFS[2] = PFandEFF[3] # 구한 값을 저장한다.(100%,75%,50%) param = [loadname,'Characteristic','EFF(100% Load)','%.3f' % (EFFS[2])] ELoadApp.SetLoadProp(param) param[2] = 'EFF(75% Load)' param[3] = '%.3f' % EFFS[1] ELoadApp.SetLoadProp(param) param[2] = 'EFF(50% Load)' param[3] = '%.3f' % EFFS[0] ELoadApp.SetLoadProp(param) return PyFindPF(EFFS , LF)
def PyCalculateFLC(loadname): res = '0' Phase = ELoadApp.GetLoadProp(loadname,'Rating','Phase') Rating_Capacity = SAFE_FLOAT(ELoadApp.GetLoadRatingCapacity(loadname)) Rated_Voltage = SAFE_FLOAT(ELoadApp.GetLoadProp(loadname,'Rating','Rated Voltage')) PF100 = SAFE_FLOAT(ELoadApp.GetLoadProp(loadname,'Characteristic','PF(100% Load)')) EFF100 = SAFE_FLOAT(ELoadApp.GetLoadProp(loadname,'Characteristic','EFF(100% Load)')) try: Rating_Capacity_Unit = ELoadApp.GetLoadPropUnitStr(loadname,'Rating','Rating Capacity') if '3' == Phase: if 'KVA' == Rating_Capacity_Unit: res = (Rating_Capacity / (math.sqrt(3)*Rated_Voltage)) else: res = (Rating_Capacity / (math.sqrt(3)*Rated_Voltage*PF100*EFF100)) res = str(round(res,2)) elif '1' == Phase: if 'KVA' == Rating_Capacity_Unit: res = (Rating_Capacity / (Rated_Voltage)) else: res = (Rating_Capacity / (Rated_Voltage*PF100*EFF100)) res = str(round(res,2)) elif 'DC' == Phase: # DC는 PF가 없다. if 'KVA' == Rating_Capacity_Unit: res = (Rating_Capacity / (Rated_Voltage)) else: res = (Rating_Capacity / (Rated_Voltage*EFF100)) res = str(round(res,2)) except: pass return res
def PyWriteCableSizingResultToExcel(args): if type(args) != type([]) or len(args) != 3: ELoadApp.AppendLogToOutputWnd('arguments error') return xl = win32com.client.gencache.EnsureDispatch ('Excel.Application') wb = xl.Workbooks.Open(args[0]) ws = wb.ActiveSheet xl.Visible = False # 보이지 않게 한다. FolderPath = args[2] # TOTAL DICTIONARY TOTAL = {} PROJECT_FOLDER = ELoadApp.GetProjectFolder() projectno = ELoadApp.GetProjectNo() projectname = ELoadApp.GetProjectName() documentno = ELoadApp.GetDocumentNo() BusNameList = ELoadApp.GetBusNameList('ALL') for bus in BusNameList: busgroup = ELoadApp.GetBusProp(bus,'General','Bus Group') #if busgroup == 'INCOMING': # continue try: wb.Worksheets('POWER_CABLE').Copy(Before=wb.Worksheets(wb.Worksheets.Count)) ws = wb.ActiveSheet ws.Name = bus except: ELoadApp.AppendLogToOutputWnd(traceback.format_exc()) try: row = 11 ifile = open(FolderPath + '\\' + bus + '.BUS', 'r') ELoadApp.AppendLogToOutputWnd(FolderPath + '\\' + bus + '.BUS') buffer = ifile.readlines() for index in range(1,len(buffer)): ws.Range('A'+str(row + 1) +':AD'+str(row + 1)).Insert() row = row + 1 row = 11 for line in buffer: list = line.rstrip('\n').split('\t') col = 1 for item in list: if (len(item) >= 1) and ('*' == item[len(item) - 1]): # it is modified item. so filled with red. ws.Cells(row,col).Value = item[0:len(item)-1] ws.Cells(row,col).Interior.ColorIndex = 44 # ? else: ws.Cells(row,col).Value = item col = col + 1 row = row + 1 BusVolt = ELoadApp.GetBusProp(bus,'General','Bus Voltage') ws.Cells(1,4).Value = projectno ws.Cells(2,4).Value = projectname ws.Cells(3,4).Value = ELoadApp.GetProjectClient() ws.Cells(5,4).Value = bus ws.Cells(5,8).Value = BusVolt # 현재 날짜를 표기한다. now = time.localtime() ws.Cells(2,12).Value = '%d' % now.tm_year + '.' + '%d' % now.tm_mon + '.' + '%d' % now.tm_mday ws.Cells(3,12).Value = documentno ws.Columns('A:A').EntireColumn.AutoFit() ifile.close() except: ELoadApp.AppendLogToOutputWnd(traceback.format_exc()) try: # TEMPLATE SHEET를 삭제합니다. xl.DisplayAlerts = False wb.Worksheets("POWER_CABLE").Delete() # SAVE AND 엑셀 APP 종료. wb.SaveAs(args[1]) xl.Visible = True #wb.Close() xl.DisplayAlerts = True # xl.Quit() # os.startfile(args[1]) except: ELoadApp.AppendLogToOutputWnd(traceback.format_exc()) return 'SUCCESS'
def WriteTotalLoadSummaryToDataFileA(BusNameList,TOTAL,rApplyTr): PROJECT_FOLDER = ELoadApp.GetProjectFolder() keylist = TOTAL.keys() keylistlen = len(keylist) C_SUM = [0,0] D_SUM = [0,0] E_SUM = [0,0] F_SUM = [0,0] G_SUM = [0,0] H_SUM = [0,0] I_SUM = [0,0] J_SUM = [0,0] K_SUM = [0,0] if False == os.path.exists(PROJECT_FOLDER + 'Load Summary Result'): os.mkdir(PROJECT_FOLDER + 'Load Summary Result') TotalBUSFile = open(PROJECT_FOLDER + 'Load Summary Result\\TotalBUS.bus','w') TotalSubBUSFile = open(PROJECT_FOLDER + 'Load Summary Result\\TotalSubBUS.bus','w') for busname in BusNameList: BusGroup = ELoadApp.GetBusGroupNameHasBus(busname) BusGroup = BusGroup.upper() if ('INCOMING' == busname): continue if 'SUBBUS' != BusGroup: f = TotalBUSFile else: f = TotalSubBUSFile try: BUS_ID = ELoadApp.GetBusProp(busname,'General','Bus ID') f.write(busname + '\t') # skip Bus Equip. No. DESC = ELoadApp.GetBusProp(busname,'General','Description') f.write(DESC + '\t') BUS_VOLT = ELoadApp.GetBusProp(busname, 'General', 'Bus Voltage') f.write(BUS_VOLT + '\t') LOAD_VOLT = ELoadApp.GetBusProp(busname, 'General', 'Load Voltage') f.write(LOAD_VOLT + '\t') valist = TOTAL.get(busname) Continuous = ELoadApp.GetBusProp(busname,'General','Continuous') Intermittent = ELoadApp.GetBusProp(busname,'General','Intermittent') Standby = ELoadApp.GetBusProp(busname,'General','Stand-by') C = SAFE_FLOAT(Continuous)*0.01*valist[0] + SAFE_FLOAT(Intermittent)*0.01*valist[2] + SAFE_FLOAT(Standby)*0.01*valist[4] if 'SUBBUS' != BusGroup: C_SUM[0] = C_SUM[0] + C else: C_SUM[1] = C_SUM[1] + C D = SAFE_FLOAT(Continuous)*0.01*valist[1] + SAFE_FLOAT(Intermittent)*0.01*valist[3] + SAFE_FLOAT(Standby)*0.01*valist[5] if 'SUBBUS' != BusGroup: D_SUM[0] = D_SUM[0] + D else: D_SUM[1] = D_SUM[1] + D if 0. != C: f.write(str('%.2f' % C) + '\t') else: f.write('\t') if 0. != D: f.write(str('%.2f' % D) + '\t') else: f.write('\t') E = SAFE_ROUND(math.sqrt(C*C + D*D),2) if 0. != E: f.write(str('%.2f' % E) + '\t') else: f.write('\t') if 'SUBBUS' != BusGroup: E_SUM[0] = E_SUM[0] + E else: E_SUM[1] = E_SUM[1] + E if '0' != Continuous: if Continuous == '100': Continuous = '1' else: Continuous = str(SAFE_FLOAT(Continuous) * 0.01) if '0' != Intermittent: if '100' == Intermittent: Intermittent = '1' else: Intermittent = str(SAFE_FLOAT(Intermittent) * 0.01) if '0' != Standby: if '100' == Standby: Standby = '1' else: Standby = str(SAFE_FLOAT(Standby) * 0.01) f.write(str(Continuous) + '\t') f.write(str(Intermittent) + '\t') f.write(str(Standby) + '\t') # 0. 인것은 뿌리지 않는다. if 0. != valist[0]: f.write(str('%.2f' % valist[0]) + '\t') else: f.write('\t') if 'SUBBUS' != BusGroup: F_SUM[0] = F_SUM[0] + valist[0] else: F_SUM[1] = F_SUM[1] + valist[0] if 0. != valist[1]: f.write(str('%.2f' % valist[1]) + '\t') else: f.write('\t') if 'SUBBUS' != BusGroup: G_SUM[0] = G_SUM[0] + valist[1] else: G_SUM[1] = G_SUM[1] + valist[1] if 0. != valist[2]: f.write(str('%.2f' % valist[2]) + '\t') else: f.write('\t') if 'SUBBUS' != BusGroup: H_SUM[0] = H_SUM[0] + valist[2] else: H_SUM[1] = H_SUM[1] + valist[2] if 0. != valist[3]: f.write(str('%.2f' % valist[3]) + '\t') else: f.write('\t') if 'SUBBUS' != BusGroup: I_SUM[0] = I_SUM[0] + valist[3] else: I_SUM[1] = I_SUM[1] + valist[3] if 0. != valist[4]: f.write(str('%.2f' % valist[4]) + '\t') else: f.write('\t') if 'SUBBUS' != BusGroup: J_SUM[0] = J_SUM[0] + valist[4] else: J_SUM[1] = J_SUM[1] + valist[4] if 0. != valist[5]: f.write(str('%.2f' % valist[5])) if 'SUBBUS' != BusGroup: K_SUM[0] = K_SUM[0] + valist[5] else: K_SUM[1] = K_SUM[1] + valist[5] f.write('\n') except: ELoadApp.AppendLogToOutputWnd(traceback.format_exc()) for i in range(0,2): if 0 == i: f = TotalBUSFile else: f = TotalSubBUSFile f.write('\n') if rApplyTr == 'TRUE': f.write('All Bus Capacity has been accumulated by the Sub-Bus Capacity (Down-Stream Bus Capacity).') else: f.write('TOTAL' + '\t\t\t\t') f.write(str('%.2f' % C_SUM[i]) + '\t') f.write(str('%.2f' % D_SUM[i]) + '\t') f.write(str('%.2f' % E_SUM[i]) + '\t') f.write('\t\t\t') if 0. != F_SUM[i]: f.write(str('%.2f' % F_SUM[i]) + '\t') else: f.write('\t') if 0. != G_SUM[i]: f.write(str('%.2f' % G_SUM[i]) + '\t') else: f.write('\t') if 0. != H_SUM[i]: f.write(str('%.2f' % H_SUM[i]) + '\t') else: f.write('\t') if 0. != I_SUM[i]: f.write(str('%.2f' % I_SUM[i]) + '\t') else: f.write('\t') if 0. != J_SUM[i]: f.write(str('%.2f' % J_SUM[i]) + '\t') else: f.write('\t') if 0. != K_SUM[i]: f.write(str('%.2f' % K_SUM[i])) f.close()
def PyLoadSummary(args): try: Load_Category= ELoadApp.GetLoadProp(args[0],'Type','Load Category') Load_Category = Load_Category.upper() # SUBBUS는 계산하지 않는다. if Load_Category == 'SUBBUS': return 'SUCCESS' Rating_Capacity= ELoadApp.GetLoadRatingCapacity(args[0]) if type(Rating_Capacity) != type(''): ELoadApp.ELOAD_LOG4CXX(['WARN' , args[0] , 52]) return 'ERROR' Rating_Capacity=SAFE_FLOAT(Rating_Capacity) #except ValueError: # ELoadApp.AppendLogToOutputWnd('Rating Capacity Value Error') # return 'Rating Capacity Value Error' BHP = ELoadApp.GetLoadProp(args[0],'Load','BHP <1>') BHP = PyBHPAutoCalc(BHP,Load_Category,Rating_Capacity) try: BHP = SAFE_ROUND(BHP,3) except: ELoadApp.AppendLogToOutputWnd(traceback.format_exc()) # BHP값을 저장한다. ELoadApp.SetLoadProp(args[0],'Load','BHP <1>','%.3f' % (BHP)) Load_Type = ELoadApp.GetLoadProp(args[0],'Type','Load Type') Poles= ELoadApp.GetLoadProp(args[0],'Rating','Poles') PFlock = ELoadApp.GetLoadProp(args[0],'Characteristic','PF LOCK') PFlock = PFlock.upper() EFFlock = ELoadApp.GetLoadProp(args[0],'Characteristic','EFF LOCK') EFFlock = EFFlock.upper() if 'MOTOR' == Load_Category: # MOTOR일 경우에는 계산을 수행한다. try: LF = SAFE_FLOAT(BHP) / SAFE_FLOAT(Rating_Capacity) except ZeroDivisionError: LF = 0 except: ELoadApp.AppendLogToOutputWnd(traceback.format_exc()) LF = SAFE_ROUND(LF,3) if LF < 0 or LF > 1: ELoadApp.AppendLogToOutputWnd('LF range error') return 'LF range error' #LF는 소수점 3자리로 param = [args[0],'Characteristic','LF','%.3f' % (LF)] ELoadApp.SetLoadProp(param) # Reference table에서 PF,EFF를 찾는다. Rated_Voltage= ELoadApp.GetLoadProp(args[0],'Rating','Rated Voltage') PFandEFF = PySearchLoadTablePFandEFF(Rating_Capacity , Rated_Voltage , Poles, LF) # LRC , PFlr의 값을 설정한다. LockStatus = ELoadApp.IsLoadPropLock(args[0] , 'Characteristic' , 'LRC') if 'FALSE' == LockStatus: param[2] = 'LRC' LRC = round(PFandEFF[8],0) param[3] = '%.0f' % LRC if 0 == LRC: param[3] = '' ELoadApp.SetLoadProp(param) LockStatus = ELoadApp.IsLoadPropLock(args[0] , 'Characteristic' , 'PF at Starting') if 'FALSE' == LockStatus: param[2] = 'PF at Starting' PFatStarting = round(PFandEFF[9],2) param[3] = '%.2f' % PFatStarting if 0 == PFatStarting: param[3] = '' ELoadApp.SetLoadProp(param) try: if PFlock == 'NO': if type(PFandEFF) is type([]) and (len(PFandEFF) == 10): PF = PFandEFF[6] # 100%,75%,50%의 값을 기입한다.(소수점 3자리로) # 값이 0일 경우에는 ''으로 대입한다. param = [args[0],'Characteristic','PF(100% Load)','%.3f' % PFandEFF[0]] if 0 == PFandEFF[0]: param[3] = '' ELoadApp.SetLoadProp(param) param[2] = 'PF(75% Load)' param[3] = '%.3f' % PFandEFF[1] if 0 == PFandEFF[1]: param[3] = '' ELoadApp.SetLoadProp(param) param[2] = 'PF(50% Load)' param[3] = '%.3f' % PFandEFF[2] if 0 == PFandEFF[2]: param[3] = '' ELoadApp.SetLoadProp(param) else: ELoadApp.ELOAD_LOG4CXX(['WARN' , args[0] , 12]) return 'ERROR IN SEARCH REF LOAD TABLE FROM PYTHON.' elif PFlock == 'YES': PF = PyGetPFIfLockIsYes(args[0],PFandEFF,LF) else: ELoadApp.ELOAD_LOG4CXX(['WARN' , args[0] , 19]) return 'PFlock type ERROR' except: ELoadApp.AppendLogToOutputWnd(traceback.format_exc()) try: if EFFlock == 'NO': if type(PFandEFF) is type([]) and (len(PFandEFF) == 10): EFF= PFandEFF[7] # 100%,75%,50%의 값을 기입한다.(소수점 3자리로) # 값이 0일 경우에는 ''으로 대입한다. param = [args[0],'Characteristic','EFF(100% Load)','%.3f' % PFandEFF[3]] if 0 == PFandEFF[3]: param[3] = '' ELoadApp.SetLoadProp(param) param[2] = 'EFF(75% Load)' param[3] = '%.3f' % PFandEFF[4] if 0 == PFandEFF[4]: param[3] = '' ELoadApp.SetLoadProp(param) param[2] = 'EFF(50% Load)' param[3] = '%.3f' % PFandEFF[5] if 0 == PFandEFF[5]: param[3] = '' ELoadApp.SetLoadProp(param) else: ELoadApp.ELOAD_LOG4CXX(['WARN' , args[0] , 12]) return 'ERROR IN SEARCH REF LOAD TABLE FROM PYTHON.' elif EFFlock == 'YES': EFF = PyGetEFFIfLockIsYes(args[0],PFandEFF,LF) else: ELoadApp.ELOAD_LOG4CXX(['WARN' , args[0] , 20]) return 'EFFlock type ERROR' except: ELoadApp.AppendLogToOutputWnd(traceback.format_exc()) else: try: LF = SAFE_FLOAT(BHP) / SAFE_FLOAT(Rating_Capacity) except ZeroDivisionError: LF = 0 except: ELoadApp.AppendLogToOutputWnd(traceback.format_exc()) LF = SAFE_ROUND(LF,2) if LF < 0 or LF > 1: ELoadApp.ELOAD_LOG4CXX(['WARN' , args[0] , 21]) return 'LF range error' #LF는 소수점 2자리로 param = [args[0],'Characteristic','LF','%.2f' % (LF)] ELoadApp.SetLoadProp(param) # Reference table에서 PF,EFF를 찾는다. Rated_Voltage= ELoadApp.GetLoadProp(args[0],'Rating','Rated Voltage') #PFandEFF = PySearchLoadTablePFandEFF(Rating_Capacity , Rated_Voltage , Poles, LF) # LRC , PFlr의 값을 설정한다. #param[2] = 'LRC' #param[3] = '%.3f' % PFandEFF[8] #ELoadApp.SetLoadProp(param) #param[2] = 'PF at Starting' #param[3] = '%.3f' % PFandEFF[9] #ELoadApp.SetLoadProp(param) # TABLE에서 Load Category에 따른 PF,EFF값을 가져온다. if 'NO' == PFlock.upper(): if Load_Category == 'LTG': PF = SAFE_FLOAT(ELoadApp.GetFieldValueInProjectSettingTable('C_LTG_PF')) elif Load_Category == 'WELDING': PF = SAFE_FLOAT(ELoadApp.GetFieldValueInProjectSettingTable('C_WELDING_PF')) elif Load_Category == 'INST.': PF = SAFE_FLOAT(ELoadApp.GetFieldValueInProjectSettingTable('C_INST_PF')) elif Load_Category == 'COMM.': PF = SAFE_FLOAT(ELoadApp.GetFieldValueInProjectSettingTable('C_COMM_PF')) elif Load_Category == 'OTHERS': PF = SAFE_FLOAT(ELoadApp.GetFieldValueInProjectSettingTable('C_OTHERS_PF')) else: ELoadApp.ELOAD_LOG4CXX(['ERROR' , args[0] , 10]) return 'LoadType is unset' param[1] = 'Characteristic' param[2] = 'PF(100% Load)' param[3] = '%.3f' % (PF) ELoadApp.SetLoadProp(param) elif 'YES' == PFlock.upper(): try: PFandEFF = PySearchLoadTablePFandEFF(Rating_Capacity , Rated_Voltage , Poles, LF) if type(PFandEFF) is type([]) and (len(PFandEFF) == 10): PF = PyGetPFIfLockIsYes(args[0],PFandEFF,LF) else: ELoadApp.ELOAD_LOG4CXX(['WARN' , args[0] , 11]) return 'SearchLoadTable is fail.' except: ELoadApp.AppendLogToOutputWnd(args[0] + ' : ' + traceback.format_exc()) return (args[0] + ' : ' + traceback.format_exc()) else: ELoadApp.ELOAD_LOG4CXX(['WARN' , args[0] , 19]) return 'PFlock type ERROR' if 'NO' == EFFlock.upper(): if Load_Category == 'LTG': EFF = SAFE_FLOAT(ELoadApp.GetFieldValueInProjectSettingTable('C_LTG_EFF')) elif Load_Category == 'WELDING': EFF = SAFE_FLOAT(ELoadApp.GetFieldValueInProjectSettingTable('C_WELDING_EFF')) elif Load_Category == 'INST.': EFF = SAFE_FLOAT(ELoadApp.GetFieldValueInProjectSettingTable('C_INST_EFF')) elif Load_Category == 'COMM.': EFF = SAFE_FLOAT(ELoadApp.GetFieldValueInProjectSettingTable('C_COMM_EFF')) elif Load_Category == 'OTHERS': EFF = SAFE_FLOAT(ELoadApp.GetFieldValueInProjectSettingTable('C_OTHERS_EFF')) else: ELoadApp.ELOAD_LOG4CXX(['ERROR' , args[0] , 10]) return 'LoadType is unset' param[1] = 'Characteristic' param[2] = 'EFF(100% Load)' param[3] = '%.3f' % (EFF) ELoadApp.SetLoadProp(param) elif 'YES' == EFFlock.upper(): try: PFandEFF = PySearchLoadTablePFandEFF(Rating_Capacity , Rated_Voltage , Poles, LF) if type(PFandEFF) is type([]) and (len(PFandEFF) == 10): EFF = PyGetEFFIfLockIsYes(args[0],PFandEFF,LF) else: ELoadApp.ELOAD_LOG4CXX(['WARN' , args[0] , 11]) return 'SearchLoadTable is fail.' except: ELoadApp.AppendLogToOutputWnd(args[0] + ' : ' + traceback.format_exc()) return (args[0] + ' : ' + traceback.format_exc()) else: ELoadApp.ELOAD_LOG4CXX(['WARN' , args[0] , 20]) return 'EFFlock type ERROR' PF = SAFE_ROUND(PF , 3) EFF= SAFE_ROUND(EFF, 3) Rating_Capacity_Unit = ELoadApp.GetLoadPropUnitStr(args[0],'Rating','Rating Capacity') if 'KVA' == Rating_Capacity_Unit: ## 'KVA'일 경우의 계산식 KW = SAFE_FLOAT(BHP)*SAFE_FLOAT(PF) else: ## 'KVA'이외의 경우의 계산식 KW = SAFE_FLOAT(BHP)/SAFE_FLOAT(EFF) KW = SAFE_ROUND(KW , 2) try: KVA = SAFE_FLOAT(KW)/SAFE_FLOAT(PF) KVA = SAFE_ROUND(KVA, 2) KVAR = math.sqrt(math.pow(KVA,2) - math.pow(KW,2)) KVAR = SAFE_ROUND(KVAR , 2) except: ELoadApp.AppendLogToOutputWnd(args[0] + ' : ' + traceback.format_exc()) param = [args[0] , 'Load Summary' , 'KW' , '%.2f' % (KW)] ELoadApp.SetLoadProp(param) param[2] = 'KVA' param[3] = '%.2f' % (KVA) ELoadApp.SetLoadProp(param) param[2] = 'KVAR' param[3] = '%.2f' % (KVAR) ELoadApp.SetLoadProp(param) param[2] = 'PF' param[3] = '%.3f' % (PF) ELoadApp.SetLoadProp(param) param[2] = 'EFF' param[3] = '%.3f' % EFF ELoadApp.SetLoadProp(param) # FLC값을 계산하여 저장한다. param[1] = 'Rating' param[2] = 'FLC' param[3] = PyCalculateFLC(args[0]) ELoadApp.SetLoadProp(param) return 'SUCCESS' except: ELoadApp.ELOAD_LOG4CXX(['ERROR' , args[0] + ' : ' + traceback.format_exc() , 1]) ELoadApp.AppendLogToOutputWnd(args[0] + ' : ' + traceback.format_exc())
def PyPostImportLoadDataFromExcel(args): if type(args) is type([]) and (len(args) == 1): LoadID = args[0] loadCategory = ELoadApp.GetLoadProp(LoadID,'Type','Load Category') loadCategory = loadCategory.upper() if 'L' == loadCategory: ELoadApp.SetLoadProp(LoadID,'Type','Load Category' , 'LTG') ELoadApp.SetLoadOriginalProp(LoadID,'Type','Load Category' , 'LTG') elif 'M' == loadCategory: ELoadApp.SetLoadProp(LoadID,'Type','Load Category' , 'MOTOR') ELoadApp.SetLoadOriginalProp(LoadID,'Type','Load Category' , 'MOTOR') elif 'O' == loadCategory: ELoadApp.SetLoadProp(LoadID,'Type','Load Category' , 'OTHERS') ELoadApp.SetLoadOriginalProp(LoadID,'Type','Load Category' , 'OTHERS') elif 'W' == loadCategory: ELoadApp.SetLoadProp(LoadID,'Type','Load Category' , 'WELDING') ELoadApp.SetLoadOriginalProp(LoadID,'Type','Load Category' , 'WELDING') elif 'I' == loadCategory: ELoadApp.SetLoadProp(LoadID,'Type','Load Category' , 'INST.') ELoadApp.SetLoadOriginalProp(LoadID,'Type','Load Category' , 'INST.') elif 'C' == loadCategory: ELoadApp.SetLoadProp(LoadID,'Type','Load Category' , 'COMM.') ELoadApp.SetLoadOriginalProp(LoadID,'Type','Load Category' , 'COMM.') elif 'S' == loadCategory: ELoadApp.SetLoadProp(LoadID,'Type','Load Category' , 'SubBus') ELoadApp.SetLoadOriginalProp(LoadID,'Type','Load Category' , 'SubBus') operMode = ELoadApp.GetLoadProp(LoadID,'Type','Operation Mode') operMode = operMode.upper() if 'C' == operMode: ELoadApp.SetLoadProp(LoadID,'Type','Operation Mode','CONTINUOUS') ELoadApp.SetLoadOriginalProp(LoadID,'Type','Operation Mode','CONTINUOUS') elif 'I' == operMode: ELoadApp.SetLoadProp(LoadID,'Type','Operation Mode','INTERMITTENT') ELoadApp.SetLoadOriginalProp(LoadID,'Type','Operation Mode','INTERMITTENT') elif 'S' == operMode: ELoadApp.SetLoadProp(LoadID,'Type','Operation Mode','STAND-BY') ELoadApp.SetLoadOriginalProp(LoadID,'Type','Operation Mode','STAND-BY') PF100 = SAFE_FLOAT(ELoadApp.GetLoadProp(LoadID,'Characteristic','PF(100% Load)')) if (0. != PF100): ELoadApp.SetLoadProp(LoadID,'Characteristic','PF LOCK','Yes') ELoadApp.SetLoadOriginalProp(LoadID,'Characteristic','PF LOCK','Yes') else: ELoadApp.SetLoadProp(LoadID,'Characteristic','PF LOCK','No') ELoadApp.SetLoadOriginalProp(LoadID,'Characteristic','PF LOCK','No') EFF100 = SAFE_FLOAT(ELoadApp.GetLoadProp(LoadID,'Characteristic','EFF(100% Load)')) if (0. != EFF100): ELoadApp.SetLoadProp(LoadID,'Characteristic','EFF LOCK','Yes') ELoadApp.SetLoadOriginalProp(LoadID,'Characteristic','EFF LOCK','Yes') else: ELoadApp.SetLoadProp(LoadID,'Characteristic','EFF LOCK','No') ELoadApp.SetLoadOriginalProp(LoadID,'Characteristic','EFF LOCK','No') busname = ELoadApp.GetLoadProp(LoadID , 'Panel' , 'Bus ID') if '' != busname: # BUS가 설정되어 있으면 BUS의 Load Voltage와 Phase의 값을 가져와서 각각 Rated Voltage,Phase에 설정한다. LoadVoltage = ELoadApp.GetBusProp(busname , 'General', 'Load Voltage') Phase = ELoadApp.GetBusProp(busname , 'General', 'Phase') ELoadApp.SetLoadProp(LoadID,'Rating','Rated Voltage',LoadVoltage) ELoadApp.SetLoadOriginalProp(LoadID,'Rating','Rated Voltage',LoadVoltage) ELoadApp.SetLoadProp(LoadID,'Rating','Phase',Phase) ELoadApp.SetLoadOriginalProp(LoadID,'Rating','Phase',Phase) # Rating Capacity는 소수점 2 BHP의 값을 소수점 3자리까지 표현한다. RatingCapacity = SAFE_FLOAT(ELoadApp.GetLoadRatingCapacity(LoadID)) ELoadApp.SetLoadProp(LoadID , 'Rating','Rating Capacity' , '%.2f' % RatingCapacity) ELoadApp.SetLoadOriginalProp(LoadID , 'Rating','Rating Capacity' , '%.2f' % RatingCapacity) BHP = ELoadApp.GetLoadProp(LoadID,'Load','BHP <1>') if '' != BHP: BHP = SAFE_FLOAT(BHP) ELoadApp.SetLoadProp(LoadID,'Load','BHP <1>' , '%.3f' % BHP) ELoadApp.SetLoadOriginalProp(LoadID,'Load','BHP <1>' , '%.3f' % BHP) ELoadApp.SetLoadProp(LoadID,'Circuit Breaker','LOCK','No') ELoadApp.SetLoadOriginalProp(LoadID,'Circuit Breaker','LOCK','No') ELoadApp.SetLoadProp(LoadID,'Control','LOCK','No') ELoadApp.SetLoadOriginalProp(LoadID,'Control','LOCK','No') ELoadApp.SetLoadProp(LoadID,'Control Cable','LOCK','No') ELoadApp.SetLoadOriginalProp(LoadID,'Control Cable','LOCK','No') return 'SUCCESS' return 'FAIL'
def WriteLoadSummaryDataOfSpecialItem(busfile , typeString , id , param , LoadSummaryCalcData): busfile.write(id + '\t') if typeString == 'TRANSFORMER': busfile.write('Connected BUS' + '\t') busfile.write('\t\t\t\t\t\t') elif typeString == 'UPSDC': SelectedCapacity = ELoadApp.GetELoadItemProp('UPSDC' , id , 'General' , 'SELECTED CAPACITY') if SelectedCapacity == 'UPS Capacity': busfile.write('Connected UPS' + '\t') LoadVolt = ELoadApp.GetELoadItemProp('UPSDC' , id , 'UPS Capacity' , 'Input Load Volt') busfile.write(LoadVolt + '\t') KVA = ELoadApp.GetELoadItemProp('UPSDC' , id , 'UPS Capacity' , 'KVA') busfile.write('%.2f' % SAFE_FLOAT(KVA) + '\t') busfile.write('KVA' + '\t') BHP = ELoadApp.GetELoadItemProp('UPSDC' , id , 'UPS Capacity' , 'BHP') busfile.write('%.2f' % SAFE_FLOAT(BHP) + '\t') else: busfile.write('Connected DC' + '\t') LoadVolt = ELoadApp.GetELoadItemProp('UPSDC' , id , 'DC Capacity' , 'AC Rating Load Volt') busfile.write(LoadVolt + '\t') KVA = ELoadApp.GetELoadItemProp('UPSDC' , id , 'DC Capacity' , 'AC Rating KVA') busfile.write('%.2f' % SAFE_FLOAT(KVA) + '\t') busfile.write('KVA' + '\t') BHP = ELoadApp.GetELoadItemProp('UPSDC' , id , 'DC Capacity' , 'AC Rating BHP') busfile.write('%.2f' % SAFE_FLOAT(BHP) + '\t') busfile.write('\t') # TYPE은 공백으로 둔다. OP = ELoadApp.GetELoadItemProp('UPSDC' , id , param , 'Operation Mode') if OP == 'CONTINUOUS': busfile.write('C' + '\t') elif OP == 'INTERMITTENT': busfile.write('I' + '\t') elif OP == 'STAND-BY': busfile.write('S' + '\t') else: busfile.write('\t') # LF if ('' != LoadSummaryCalcData[0]) and (0 != LoadSummaryCalcData[0]): busfile.write('%.2f' % LoadSummaryCalcData[0] + '\t') else: busfile.write('\t') # PF if ('' != LoadSummaryCalcData[1]) and (0 != LoadSummaryCalcData[1]): busfile.write('%.3f' % LoadSummaryCalcData[1] + '\t') else: busfile.write('\t') # EFF if ('' != LoadSummaryCalcData[2]) and (0 != LoadSummaryCalcData[2]): busfile.write('%.3f' % LoadSummaryCalcData[2] + '\t') else: busfile.write('\t') if ('' != LoadSummaryCalcData[3]) and (0 != LoadSummaryCalcData[3]): busfile.write('%.2f' % LoadSummaryCalcData[3] + '\t') else: busfile.write('\t') if ('' != LoadSummaryCalcData[4]) and (0 != LoadSummaryCalcData[4]): busfile.write('%.2f' % LoadSummaryCalcData[4] + '\t') else: busfile.write('\t') if ('' != LoadSummaryCalcData[5]) and (0 != LoadSummaryCalcData[5]): busfile.write('%.2f' % LoadSummaryCalcData[5] + '\t') else: busfile.write('\t') if ('' != LoadSummaryCalcData[6]) and (0 != LoadSummaryCalcData[6]): busfile.write('%.2f' % LoadSummaryCalcData[6] + '\t') else: busfile.write('\t') if ('' != LoadSummaryCalcData[7]) and (0 != LoadSummaryCalcData[7]): busfile.write('%.2f' % LoadSummaryCalcData[7] + '\t') else: busfile.write('\t') if ('' != LoadSummaryCalcData[8]) and (0 != LoadSummaryCalcData[8]): busfile.write('%.2f' % LoadSummaryCalcData[8] + '\t') else: busfile.write('\t') busfile.write('\t\n')
def WriteLoadSummaryToDataFileA(args): rApplyTr = 'TRUE' if type(args) is type([]) and (len(args) == 1): rApplyTr = args[0] # TOTAL DICTIONARY TOTAL = {} try: PROJECT_FOLDER = ELoadApp.GetProjectFolder() if False == os.path.exists(PROJECT_FOLDER + 'Load Summary Result'): os.mkdir(PROJECT_FOLDER + 'Load Summary Result') except: ELoadApp.AppendLogToOutputWnd(traceback.format_exc()) return DeleteAllBusFiles(PROJECT_FOLDER + 'Load Summary Result') # 먼저 BUS의 이름들을 가져온다. BusNameList = ELoadApp.GetBusNameList('ALL') for bus in BusNameList: BusGroup = ELoadApp.GetBusGroupNameHasBus(bus) if ('INCOMING' == bus): continue try: #if False == TOTAL.has_key(bus): TOTAL[bus] = [0,0,0,0,0,0] # CONTINUOUS(KW,KVAR) , INTERMITTENT(KW,KVAR) , STAND-BY(KW,KVAR) C_SUM = 0 D_SUM = 0 H_SUM = 0 I_SUM = 0 J_SUM = 0 K_SUM = 0 L_SUM = 0 M_SUM = 0 N_SUM = 0 O_SUM = 0 P_SUM = 0 Q_SUM = 0 row = 1 # BUS별 Load Summary 파일을 남긴다. busfile = open(PROJECT_FOLDER + 'Load Summary Result\\' + bus + '.bus','w') LoadNameList = ELoadApp.GetLoadNameListInBus(bus) LoadNameList.sort() LoadCount = len(LoadNameList) for loadname in LoadNameList: NAME = ELoadApp.GetLoadProp(loadname,'General','ITEM ID') busfile.write(NAME + '\t') DESC = ELoadApp.GetLoadProp(loadname,'General','Description') busfile.write(DESC + '\t') LoadCategory = ELoadApp.GetLoadProp(loadname , 'Type' , 'Load Category') LoadCategory = LoadCategory.upper() ConnectedBusID = ELoadApp.GetLoadProp(loadname , 'Panel' , 'Connect Bus') if (ConnectedBusID != '') and ('SUBBUS' != LoadCategory): ELoadApp.ELOAD_LOG4CXX(['WARN' , loadname , 22]) KW = ['','',''] KVAR = ['','',''] KVA = '' PF = '' EFF = '' OP = ELoadApp.GetLoadProp(loadname,'Type','Operation Mode') if (('SUBBUS' == LoadCategory) and ('' != ConnectedBusID)): LoadSummaryCalcData = ELoadApp.GetLoadSummaryCalcDataOfBus(ConnectedBusID) PF = str(LoadSummaryCalcData[1]) EFF = str(LoadSummaryCalcData[2]) KW[0] = str(LoadSummaryCalcData[3]) KVAR[0] = str(LoadSummaryCalcData[4]) KW[1] = str(LoadSummaryCalcData[5]) KVAR[1] = str(LoadSummaryCalcData[6]) KW[2] = str(LoadSummaryCalcData[7]) KVAR[2] = str(LoadSummaryCalcData[8]) else: if OP == 'CONTINUOUS': KW[0] = ELoadApp.GetLoadProp(loadname,'Load Summary','KW').strip() KVAR[0]= ELoadApp.GetLoadProp(loadname,'Load Summary','KVAR').strip() KVA = ELoadApp.GetLoadProp(loadname,'Load Summary','KVA').strip() elif OP == 'INTERMITTENT': KW[1] = ELoadApp.GetLoadProp(loadname,'Load Summary','KW').strip() KVAR[1]= ELoadApp.GetLoadProp(loadname,'Load Summary','KVAR').strip() KVA = ELoadApp.GetLoadProp(loadname,'Load Summary','KVA').strip() else: KW[2] = ELoadApp.GetLoadProp(loadname,'Load Summary','KW').strip() KVAR[2]= ELoadApp.GetLoadProp(loadname,'Load Summary','KVAR').strip() KVA = ELoadApp.GetLoadProp(loadname,'Load Summary','KVA').strip() if ('SUBBUS' != LoadCategory): RATED_VOLTS = ELoadApp.GetLoadProp(loadname, 'Rating','Rated Voltage') busfile.write(RATED_VOLTS + '\t') Rating_Capacity = ELoadApp.GetLoadRatingCapacity(loadname) if type(Rating_Capacity) == type(''): D_SUM = D_SUM + SAFE_FLOAT(Rating_Capacity) busfile.write(('%.2f' % SAFE_FLOAT(Rating_Capacity)) + '\t') Rating_Capacity_Unit = ELoadApp.GetLoadPropUnitStr(loadname,'Rating','Rating Capacity') busfile.write(Rating_Capacity_Unit + '\t') BHP = ELoadApp.GetLoadProp(loadname,'Load','BHP <1>') if ('' != BHP) and ('0' != BHP): busfile.write(BHP + '\t') Q_SUM = Q_SUM + SAFE_FLOAT(BHP) else: busfile.write('\t') TYPE = ELoadApp.GetLoadProp(loadname,'Type', 'Load Category') TYPE = TYPE.upper() if TYPE == 'MOTOR': busfile.write('M\t') elif TYPE == 'LTG': busfile.write('L\t') elif TYPE == 'WELDING': busfile.write('W\t') elif TYPE == 'INST.': busfile.write('I\t') elif TYPE == 'COMM.': busfile.write('C\t') elif TYPE == 'OTHERS': busfile.write('O\t') elif TYPE == 'SUBBUS': busfile.write('P\t') if OP == 'CONTINUOUS': busfile.write('C\t') elif OP == 'INTERMITTENT': busfile.write('I\t') else: busfile.write('S\t') LF = ELoadApp.GetLoadProp(loadname,'Characteristic','LF') H_SUM = H_SUM +SAFE_FLOAT(LF) busfile.write(LF + '\t') PF = ELoadApp.GetLoadProp(loadname,'Load Summary','PF') I_SUM = I_SUM + SAFE_FLOAT(PF) busfile.write(PF + '\t') EFF = ELoadApp.GetLoadProp(loadname,'Load Summary','EFF') J_SUM = J_SUM + SAFE_FLOAT(EFF) busfile.write(EFF + '\t') else: # SUBBUS일 경우.(Rated Volt.,Rating Capacity,UNIT,Load,Type,Duty,LF 는 공백으로 쓴다.) busfile.write('\t\t\t\t\t\t\t') busfile.write(PF + '\t') I_SUM = I_SUM + SAFE_FLOAT(PF) busfile.write(EFF + '\t') J_SUM = J_SUM + SAFE_FLOAT(EFF) if ('' != KW[0]) and ('0' != KW[0]): busfile.write(KW[0] + '\t') K_SUM = K_SUM + SAFE_FLOAT(KW[0]) else: busfile.write('\t') if ('' != KVAR[0]) and ('0' != KVAR[0]): busfile.write(KVAR[0] + '\t') L_SUM = L_SUM + SAFE_FLOAT(KVAR[0]) else: busfile.write('\t') if ('' != KW[1]) and ('0' != KW[1]): busfile.write(KW[1] + '\t') M_SUM = M_SUM + SAFE_FLOAT(KW[1]) else: busfile.write('\t') if ('' != KVAR[1]) and ('0' != KVAR[1]): busfile.write(KVAR[1] + '\t') N_SUM = N_SUM + SAFE_FLOAT(KVAR[1]) else: busfile.write('\t') if ('' != KW[2]) and ('0' != KW[2]): busfile.write(KW[2] + '\t') O_SUM = O_SUM + SAFE_FLOAT(KW[2]) else: busfile.write('\t') if ('' != KVAR[2]) and ('0' != KVAR[2]): busfile.write(KVAR[2] + '\t') P_SUM = P_SUM + SAFE_FLOAT(KVAR[2]) else: busfile.write('\t') # 2010.02.11 remark = ELoadApp.GetLoadProp(loadname,'Remark','REMARK') busfile.write(remark) # TOTAL[bus][0] = TOTAL[bus][0] + SAFE_FLOAT(KW[0]) TOTAL[bus][1] = TOTAL[bus][1] + SAFE_FLOAT(KVAR[0]) TOTAL[bus][2] = TOTAL[bus][2] + SAFE_FLOAT(KW[1]) TOTAL[bus][3] = TOTAL[bus][3] + SAFE_FLOAT(KVAR[1]) TOTAL[bus][4] = TOTAL[bus][4] + SAFE_FLOAT(KW[2]) TOTAL[bus][5] = TOTAL[bus][5] + SAFE_FLOAT(KVAR[2]) row = row + 1 busfile.write('\n') busfile.write('\n') #################################################################################################### UPSDCCount = 0 ## 연결된 UPS/DC가 있으면... UPSDCItemList = ELoadApp.GetELoadItemListOf('UPSDC') for upsdc in UPSDCItemList: BusID1 = ELoadApp.GetELoadItemProp('UPSDC' , upsdc , 'From1' , 'Bus ID') BusID2 = ELoadApp.GetELoadItemProp('UPSDC' , upsdc , 'From2' , 'Bus ID') if (bus == BusID1) or (bus == BusID2): LoadSummaryCalcData = ELoadApp.GetLoadSummaryCalcDataOfUPSDC(upsdc , bus) if bus == BusID1: WriteLoadSummaryDataOfSpecialItem(busfile , 'UPSDC' , upsdc , 'From1' , LoadSummaryCalcData) else: WriteLoadSummaryDataOfSpecialItem(busfile , 'UPSDC' , upsdc , 'From2' , LoadSummaryCalcData) SelectedCapacity = ELoadApp.GetELoadItemProp('UPSDC' , upsdc , 'General' , 'SELECTED CAPACITY') if SelectedCapacity == 'UPS Capacity': KVA = SAFE_FLOAT(ELoadApp.GetELoadItemProp('UPSDC' , upsdc , 'UPS Capacity' , 'KVA')) D_SUM = D_SUM + KVA BHP = SAFE_FLOAT(ELoadApp.GetELoadItemProp('UPSDC' , upsdc , 'UPS Capacity' , 'BHP')) Q_SUM = Q_SUM + BHP else: KVA = SAFE_FLOAT(ELoadApp.GetELoadItemProp('UPSDC' , upsdc , 'DC Capacity' , 'AC Rating KVA')) D_SUM = D_SUM + KVA BHP = SAFE_FLOAT(ELoadApp.GetELoadItemProp('UPSDC' , upsdc , 'DC Capacity' , 'AC Rating BHP')) Q_SUM = Q_SUM + BHP H_SUM = H_SUM + SAFE_FLOAT(LoadSummaryCalcData[0]) I_SUM = I_SUM + SAFE_FLOAT(LoadSummaryCalcData[1]) J_SUM = J_SUM + SAFE_FLOAT(LoadSummaryCalcData[2]) TOTAL[bus][0] = TOTAL[bus][0] + SAFE_FLOAT(LoadSummaryCalcData[3]) K_SUM = K_SUM + SAFE_FLOAT(LoadSummaryCalcData[3]) TOTAL[bus][1] = TOTAL[bus][1] + SAFE_FLOAT(LoadSummaryCalcData[4]) L_SUM = L_SUM + SAFE_FLOAT(LoadSummaryCalcData[4]) TOTAL[bus][2] = TOTAL[bus][2] + SAFE_FLOAT(LoadSummaryCalcData[5]) M_SUM = M_SUM + SAFE_FLOAT(LoadSummaryCalcData[5]) TOTAL[bus][3] = TOTAL[bus][3] + SAFE_FLOAT(LoadSummaryCalcData[6]) N_SUM = N_SUM + SAFE_FLOAT(LoadSummaryCalcData[6]) TOTAL[bus][4] = TOTAL[bus][4] + SAFE_FLOAT(LoadSummaryCalcData[7]) O_SUM = O_SUM + SAFE_FLOAT(LoadSummaryCalcData[7]) TOTAL[bus][5] = TOTAL[bus][5] + SAFE_FLOAT(LoadSummaryCalcData[8]) P_SUM = P_SUM + SAFE_FLOAT(LoadSummaryCalcData[8]) UPSDCCount = UPSDCCount + 1 if UPSDCCount > 0: busfile.write('\n') LoadCount = LoadCount + UPSDCCount #################################################################################################### TrCount = 0 ## Transformer쪽을 포함한다면... if rApplyTr == 'TRUE': ## BUS에 연결된 Transformer를 구한 후 Transformer에 연결된 BUS의 Load Summary값을 합한다. TrNameList = ELoadApp.GetTrNameListInBus(bus) TrNameList.sort() for tr in TrNameList: trbus = ELoadApp.GetTransformerProp(tr , 'To' , 'Bus Id') #TrBusNameList = ELoadApp.GetConnectedBusNameListOfTr(tr) #for trbus in TrBusNameList: LoadSummaryCalcData = ELoadApp.GetLoadSummaryCalcDataOfBus(trbus) WriteLoadSummaryDataOfSpecialItem(busfile , 'TRANSFORMER' , trbus , '' , LoadSummaryCalcData) H_SUM = H_SUM + SAFE_FLOAT(LoadSummaryCalcData[0]) I_SUM = I_SUM + SAFE_FLOAT(LoadSummaryCalcData[1]) J_SUM = J_SUM + SAFE_FLOAT(LoadSummaryCalcData[2]) TOTAL[bus][0] = TOTAL[bus][0] + SAFE_FLOAT(LoadSummaryCalcData[3]) K_SUM = K_SUM + SAFE_FLOAT(LoadSummaryCalcData[3]) TOTAL[bus][1] = TOTAL[bus][1] + SAFE_FLOAT(LoadSummaryCalcData[4]) L_SUM = L_SUM + SAFE_FLOAT(LoadSummaryCalcData[4]) TOTAL[bus][2] = TOTAL[bus][2] + SAFE_FLOAT(LoadSummaryCalcData[5]) M_SUM = M_SUM + SAFE_FLOAT(LoadSummaryCalcData[5]) TOTAL[bus][3] = TOTAL[bus][3] + SAFE_FLOAT(LoadSummaryCalcData[6]) N_SUM = N_SUM + SAFE_FLOAT(LoadSummaryCalcData[6]) TOTAL[bus][4] = TOTAL[bus][4] + SAFE_FLOAT(LoadSummaryCalcData[7]) O_SUM = O_SUM + SAFE_FLOAT(LoadSummaryCalcData[7]) TOTAL[bus][5] = TOTAL[bus][5] + SAFE_FLOAT(LoadSummaryCalcData[8]) P_SUM = P_SUM + SAFE_FLOAT(LoadSummaryCalcData[8]) # # busfile.write(trbus + '\t') # busfile.write('\t\t\t\t\t\t\t') # if ('' != LoadSummaryCalcData[0]) and ('0' != LoadSummaryCalcData[0]): # busfile.write(str(LoadSummaryCalcData[0]) + '\t') # H_SUM = H_SUM + SAFE_FLOAT(LoadSummaryCalcData[0]) # else: # busfile.write('\t') # if ('' != LoadSummaryCalcData[1]) and ('0' != LoadSummaryCalcData[1]): # busfile.write(str(LoadSummaryCalcData[1]) + '\t') # I_SUM = I_SUM + SAFE_FLOAT(LoadSummaryCalcData[1]) # else: # busfile.write('\t') # if ('' != LoadSummaryCalcData[2]) and ('0' != LoadSummaryCalcData[2]): # busfile.write(str(LoadSummaryCalcData[2]) + '\t') # J_SUM = J_SUM + SAFE_FLOAT(LoadSummaryCalcData[2]) # else: # busfile.write('\t') # if ('' != LoadSummaryCalcData[3]) and ('0' != LoadSummaryCalcData[3]): # busfile.write(str(LoadSummaryCalcData[3]) + '\t') # TOTAL[bus][0] = TOTAL[bus][0] + SAFE_FLOAT(LoadSummaryCalcData[3]) # K_SUM = K_SUM + SAFE_FLOAT(LoadSummaryCalcData[3]) # else: # busfile.write('\t') # if ('' != LoadSummaryCalcData[4]) and ('0' != LoadSummaryCalcData[4]): # busfile.write(str(LoadSummaryCalcData[4]) + '\t') # TOTAL[bus][1] = TOTAL[bus][1] + SAFE_FLOAT(LoadSummaryCalcData[4]) # L_SUM = L_SUM + SAFE_FLOAT(LoadSummaryCalcData[4]) # else: # busfile.write('\t') # if ('' != LoadSummaryCalcData[5]) and ('0' != LoadSummaryCalcData[5]): # busfile.write(str(LoadSummaryCalcData[5]) + '\t') # TOTAL[bus][2] = TOTAL[bus][2] + SAFE_FLOAT(LoadSummaryCalcData[5]) # M_SUM = M_SUM + SAFE_FLOAT(LoadSummaryCalcData[5]) ## else: # busfile.write('\t') # if ('' != LoadSummaryCalcData[6]) and ('0' != LoadSummaryCalcData[6]): # busfile.write(str(LoadSummaryCalcData[6]) + '\t') # TOTAL[bus][3] = TOTAL[bus][3] + SAFE_FLOAT(LoadSummaryCalcData[6]) # N_SUM = N_SUM + SAFE_FLOAT(LoadSummaryCalcData[6]) # else: # busfile.write('\t') # if ('' != LoadSummaryCalcData[7]) and ('0' != LoadSummaryCalcData[7]): # busfile.write(str(LoadSummaryCalcData[7]) + '\t') # TOTAL[bus][4] = TOTAL[bus][4] + SAFE_FLOAT(LoadSummaryCalcData[7]) # O_SUM = O_SUM + SAFE_FLOAT(LoadSummaryCalcData[7]) # else: # busfile.write('\t') # if ('' != LoadSummaryCalcData[8]) and ('0' != LoadSummaryCalcData[8]): # busfile.write(str(LoadSummaryCalcData[8]) + '\t') # TOTAL[bus][5] = TOTAL[bus][5] + SAFE_FLOAT(LoadSummaryCalcData[8]) # P_SUM = P_SUM + SAFE_FLOAT(LoadSummaryCalcData[8]) # else: # busfile.write('\t') # busfile.write('\t\n') TrCount = TrCount + 1 if TrCount > 0: busfile.write('\n') LoadCount = LoadCount + TrCount #################################################################################################### busfile.write('TOTAL' + '\t\t') #if .0 != C_SUM: # busfile.write(str('%.2f' % C_SUM) + '\t') #else: # busfile.write('\t') busfile.write('\t') # UNIT if .0 != D_SUM: busfile.write(str('%.2f' % D_SUM) + '\t') else: busfile.write('\t') busfile.write('\t') if .0 != Q_SUM: busfile.write(str('%.2f' % Q_SUM) + '\t') else: busfile.write('\t') busfile.write('\t\t') # 평균값을 WRITE한다. if .0 != H_SUM: busfile.write(str('%.2f' % (H_SUM / LoadCount)) + '\t') else: busfile.write('\t') if .0 != I_SUM: busfile.write(str('%.3f' % (I_SUM / LoadCount)) + '\t') else: busfile.write('\t') if .0 != J_SUM: busfile.write(str('%.3f' % (J_SUM / LoadCount)) + '\t') else: busfile.write('\t') if .0 != K_SUM: busfile.write(str('%.2f' % K_SUM) + '\t') else: busfile.write('\t') if .0 != L_SUM: busfile.write(str('%.2f' % L_SUM) + '\t') else: busfile.write('\t') if .0 != M_SUM: busfile.write(str('%.2f' % M_SUM) + '\t') else: busfile.write('\t') if .0 != N_SUM: busfile.write(str('%.2f' % N_SUM) + '\t') else: busfile.write('\t') if .0 != O_SUM: busfile.write(str('%.2f' % O_SUM) + '\t') else: busfile.write('\t') if .0 != P_SUM: busfile.write(str('%.2f' % P_SUM) + '\t') else: busfile.write('\t') except: ELoadApp.AppendLogToOutputWnd(traceback.format_exc()) busfile.close() # TOTAL을 기입한다. WriteTotalLoadSummaryToDataFileA(BusNameList,TOTAL,rApplyTr) return "SUCCESS"
def PyWriteCableBMSummaryToExcel(args): if type(args) != type([]) or len(args) != 2: ELoadApp.AppendLogToOutputWnd('arguments error') return xl = win32com.client.gencache.EnsureDispatch ('Excel.Application') wb = xl.Workbooks.Open(args[0]) ws = wb.ActiveSheet xl.Visible = False # 보이지 않게 한다. # TOTAL DICTIONARY TOTAL = {} TOTAL['CONTROL'] = 0;TOTAL['HV'] = 0;TOTAL['LV'] = 0 AREA = {} PROJECT_FOLDER = ELoadApp.GetProjectFolder() projectno = ELoadApp.GetProjectNo() projectname = ELoadApp.GetProjectName() documentno = ELoadApp.GetDocumentNo() try: wb.Worksheets('Cable_BM').Copy(Before=wb.Worksheets(wb.Worksheets.Count)) ws = wb.ActiveSheet ws.Name = 'Cable BM' except: ELoadApp.AppendLogToOutputWnd(traceback.format_exc()) try: Total = 0 row = 33 ifile = open(PROJECT_FOLDER + '\\Working\\CABLE_BM_SUMMARY_CONTROL_CABLE.txt', 'r') buffer = ifile.readlines() for index in range(len(buffer) - 1): ws.Range('A'+str(row + 1) +':IV'+str(row + 1)).Insert() sum = 0 row = 33;col = 2;index = 0 for line in buffer: line = line.rstrip('\n') if 0 == index: # area부분을 write한다. cols = line.rstrip('\n').split('\t') col = 7 for item in cols: ws.Cells(row - 1,col).Value = item AREA[col] = 0 col = col + 1 index = index + 1 continue col = 2 cols = line.rstrip('\n').split('\t') for item in cols: ws.Cells(row,col).Value = item if (col >= 7) and ('' != item): # store area length AREA[col] = AREA[col] + SAFE_FLOAT(item) col = col + 1 sum = sum + SAFE_FLOAT(cols[4]) TOTAL['CONTROL'] = TOTAL['CONTROL'] + SAFE_FLOAT(cols[4]) row = row + 1 index = index + 1 ws.Cells(row + 2 , 6).Value = str(TOTAL['CONTROL']) # 각 AREA별 length를 기입한다. dickeys = AREA.keys() for key in dickeys: ws.Cells(row + 2,key).Value = str(AREA[key]) ifile.close() row = 25 ifile = open(PROJECT_FOLDER + '\\Working\\CABLE_BM_SUMMARY_LV_POWER_CABLE.txt', 'r') buffer = ifile.readlines() # 구한 row 갯수 만큼 insert한다. for index in range(len(buffer) - 1): ws.Range('A'+str(row + 1) +':IV'+str(row + 1)).Insert() row = 25;col = -4;index = 0 for line in buffer: line = line.rstrip('\n') if 0 == index: # area부분을 write한다. cols = line.rstrip('\n').split('\t') col = 7 for item in cols: ws.Cells(row - 1,col).Value = item AREA[col] = 0 col = col + 1 index = index + 1 continue col = 2 cols = line.rstrip('\n').split('\t') for item in cols: ws.Cells(row,col).Value = item if (col >= 7) and ('' != item): # store area length AREA[col] = AREA[col] + SAFE_FLOAT(item) col = col + 1 sum = sum + SAFE_FLOAT(cols[4]) TOTAL['LV'] = TOTAL['LV'] + SAFE_FLOAT(cols[4]) row = row + 1 index = index + 1 ws.Cells(row + 2 , 6).Value = str(TOTAL['LV']) # 각 AREA별 length를 기입한다. dickeys = AREA.keys() for key in dickeys: ws.Cells(row + 2,key).Value = str(AREA[key]) ifile.close() row = 17 ifile = open(PROJECT_FOLDER + '\\Working\\CABLE_BM_SUMMARY_HV_POWER_CABLE.txt', 'r') buffer = ifile.readlines() # 구한 row 갯수 만큼 insert한다. for index in range(len(buffer) - 1): ws.Range('A'+str(row + 1) +':IV'+str(row + 1)).Insert() row = 17;col = -4;index = 0 for line in buffer: line = line.rstrip('\n') if 0 == index: # area부분을 write한다. cols = line.rstrip('\n').split('\t') col = 7 for item in cols: ws.Cells(row - 1,col).Value = item AREA[col] = 0 col = col + 1 index = index + 1 continue col = 2 cols = line.rstrip('\n').split('\t') for item in cols: ws.Cells(row,col).Value = item if (col >= 7) and ('' != item): # store area length AREA[col] = AREA[col] + SAFE_FLOAT(item) col = col + 1 sum = sum + SAFE_FLOAT(cols[4]) TOTAL['HV'] = TOTAL['HV'] + SAFE_FLOAT(cols[4]) row = row + 1 index = index + 1 ws.Cells(row + 2 , 6).Value = str(TOTAL['HV']) # 각 AREA별 length를 기입한다. dickeys = AREA.keys() for key in dickeys: ws.Cells(row + 2,key).Value = str(AREA[key]) ifile.close() ws.Cells(11,6).Value = str(Total) ws.Cells(1,3).Value = projectno ws.Cells(2,3).Value = projectname ws.Cells(3,3).Value = ELoadApp.GetProjectClient() ws.Cells(8,6).Value = str(TOTAL['HV']) ws.Cells(9,6).Value = str(TOTAL['LV']) ws.Cells(10,6).Value = str(TOTAL['CONTROL']) ws.Cells(11,6).Value = str(TOTAL['CONTROL']+TOTAL['HV']+TOTAL['LV']) # 현재 날짜를 표기한다. now = time.localtime() ws.Cells(2,8).Value = '%d' % now.tm_year + '.' + '%d' % now.tm_mon + '.' + '%d' % now.tm_mday #ws.Cells(3,12).Value = documentno ws.Columns('A:F').EntireColumn.AutoFit() except: ELoadApp.AppendLogToOutputWnd(traceback.format_exc()) try: # TEMPLATE SHEET를 삭제합니다. xl.DisplayAlerts = False wb.Worksheets("Cable_BM").Delete() # SAVE AND 엑셀 APP 종료. wb.SaveAs(args[1]) xl.Visible = True #wb.Close() xl.DisplayAlerts = True # xl.Quit() #os.startfile(args[1]) except: ELoadApp.AppendLogToOutputWnd(traceback.format_exc()) return 'SUCCESS'
def PyLogMsgToELOAD(msg): try: ELoadApp.AppendLogToOutputWnd('bwhy this is not run!!!') except: traceback.print_exc(file=open('c:\\test.at', 'a'))
def PyWriteTransformerSizingResultToExcel(args): if type(args) != type([]) or len(args) != 3: ELoadApp.AppendLogToOutputWnd('arguments error') return xl = win32com.client.gencache.EnsureDispatch ('Excel.Application') wb = xl.Workbooks.Open(args[0]) ws = wb.ActiveSheet xl.Visible = False # 보이지 않게 한다. FilePath = args[2] # TOTAL DICTIONARY TOTAL = {} PROJECT_FOLDER = ELoadApp.GetProjectFolder() projectno = ELoadApp.GetProjectNo() projectname = ELoadApp.GetProjectName() try: row = 10 ifile = open(FilePath , 'r') buffer = ifile.readlines() for index in range(1,len(buffer)): ws.Range('A'+str(row + 1) +':AD'+str(row + 1)).Insert() row = row + 1 tr_no = 1 row = 10 for line in buffer: list = line.rstrip('\n').split('\t') col = 3 if '' != list[0]: ws.Cells(row,col - 1).Value = str(tr_no) tr_no = tr_no + 1 for item in list: if (len(item) >= 1) and ('*' == item[len(item) - 1]): # it is modified item. so filled with red. ws.Cells(row,col).Value = item[0:len(item)-1] ws.Cells(row,col).Interior.ColorIndex = 44 # ? else: ws.Cells(row,col).Value = item col = col + 1 row = row + 1 ws.Cells(3,1).Value = '\' PROJECT :' + projectno ws.Cells(4,1).Value = '\' PROJECT NAME :' + projectname # 현재 날짜를 표기한다. now = time.localtime() ws.Cells(4,15).Value = '%d' % now.tm_year + '.' + '%d' % now.tm_mon + '.' + '%d' % now.tm_mday ws.Columns('A:A').EntireColumn.AutoFit() ifile.close() except: ELoadApp.AppendLogToOutputWnd(traceback.format_exc()) try: # TEMPLATE SHEET를 삭제합니다. xl.DisplayAlerts = False # SAVE AND 엑셀 APP 종료. wb.SaveAs(args[1]) xl.Visible = True #wb.Close() xl.DisplayAlerts = True # xl.Quit() # os.startfile(args[1]) except: ELoadApp.AppendLogToOutputWnd(traceback.format_exc()) return 'SUCCESS'