-- BatchProcess.lua by Egaltech s.r.l. 2022/05/10 -- Gestione calcolo batch disposizione e lavorazioni per Travi -- 2019/07/11 Aggiunta gestione stato rotazione di feature per TS3. -- 2019/07/16 Aggiunta gestione modalità oltre 10 per impostazione macchina e uscita. -- 2019/07/19 Aggiunta gestione collisioni. -- 2019/07/24 Aggiunta gestione extra-corse. -- 2019/08/29 Aggiunta possibilità di processare file NGE. -- 2019/10/04 Migliorato log dei parametri ricevuti. -- 2019/10/07 Aggiunta gestione Flag 4 = Check+Generate. -- 2019/10/09 In ImportBtl aggiunto flag per usare UserAttr. -- 2019/12/09 Gestione conservazione modifiche su barre. -- 2019/12/20 Gestione LOAD90 tramite file ausiliario (btm). -- 2019/12/28 Tolta uscita in caso di errore su features. -- 2020/01/08 Aggiunta seconda sezione limite (BD.MAX_WIDTH2 x BD.MAX_HEIGHT2). -- 2020/01/14 Si carica ultimo gruppo di lavoro. Corretto problema con nome non definito in segnalazione errore in generazione o stima. -- 2020/01/30 File Diff con nome del btl. -- 2020/02/12 Migliorie nella gestione degli errori. -- 2020/06/12 Si esegue sempre Processing se parametri macchina TS3 successivi al btl. -- 2021/02/04 Se necessario ricalcolo allora si aggiorna anche l'attrezzaggio. -- 2021/02/14 Modifica per macchine senza BD.MAX_WIDTH2 e BD.MAX_HEIGHT2. -- 2021/02/22 Aggiunto anche controllo su file macchina mlde per aggiornare calcoli. -- 2021/02/25 Aggiunta gestione tipo scarico (standard, lav. incomplete, a caduta). -- 2021/06/16 Se disponibile si aggiunge la versione dell'eseguibile alle info del programma CN. -- 2021/08/04 Direzione vista simulazione da BD.SIMUL_VIEW_DIR se esiste. -- 2022/04/28 In info generazione aggiunta indicazione se 64bit. -- 2023/05/03 Tolleranza su sezione portata a 0.1 mm (100 * GEO.EPS_SMALL). -- 2022/05/10 Dopo aver fatto rotazioni e inversioni dei pezzi cambio chiave Info relative. -- Intestazioni require( 'EgtBase') _ENV = EgtProtectGlobal() EgtEnableDebug( false) -- Per test --BEAM = {} --BEAM.FILE = 'c:\\EgtData\\Varie\\TestEssetreFast\\TestFilippo\\BTL\\Bar_20_1.btl' --BEAM.MACHINE = 'FAST' --BEAM.FLAG = 3 -- Log dati in input local sFlag = '' if BEAM.FLAG == 0 then sFlag = 'GENERATE' elseif BEAM.FLAG == 1 then sFlag = 'MODIFY' elseif BEAM.FLAG == 2 then sFlag = 'SIMULATE' elseif BEAM.FLAG == 3 then sFlag = 'CHECK' elseif BEAM.FLAG == 4 then sFlag = 'CHECK+GENERATE' elseif BEAM.FLAG == 11 then sFlag = 'TOOLS' elseif BEAM.FLAG == 12 then sFlag = 'JOBS' else sFlag = 'FLAG='..tostring( BEAM.FLAG) end local sLog = 'BatchProcess : ' .. BEAM.FILE .. ', ' .. BEAM.MACHINE .. ', ' .. sFlag EgtOutLog( sLog) local sLogFile = EgtChangePathExtension( BEAM.FILE, '.txt') -- in caso sia richiesta generazione senza check, verifico prima che il file log specifico non contenga errori: se sì, forzo il check if BEAM.FLAG == 0 then local hLogFile = io.open( sLogFile, 'r') if hLogFile then for line in hLogFile:lines() do if EgtStartsWith( line, 'ERR') and tonumber( EgtSplitString( line, '=')[2] or 0) > 0 then BEAM.FLAG = 4 break end end hLogFile:close() end end -- Cancello file di log specifico EgtEraseFile( sLogFile) -- Funzioni per scrittura su file di log specifico local function WriteErrToLogFile( nErr, sMsg, nRot, nCutId, nTaskId) local hFile = io.open( sLogFile, 'a') hFile:write( 'ERR=' .. tostring( nErr) .. '\n') hFile:write( sMsg .. '\n') hFile:write( 'ROT=' .. tostring( nRot or 0) .. '\n') hFile:write( 'CUTID=' .. tostring( nCutId or 0) .. '\n') hFile:write( 'TASKID=' .. tostring( nTaskId or 0) .. '\n') hFile:close() end local function WriteFallToLogFile( nErr, sMsg, nCutId, nFall) local hFile = io.open( sLogFile, 'a') hFile:write( 'ERR=' .. tostring( nErr) .. '\n') hFile:write( sMsg .. '\n') hFile:write( 'CUTID=' .. tostring( nCutId or 0) .. '\n') hFile:write( 'FALL=' .. tostring( nFall or 0) .. '\n') hFile:close() end local function WriteTimeToLogFile( dTime) local hFile = io.open( sLogFile, 'a') hFile:write( 'TIME=' .. EgtNumToString( dTime) .. '\n') hFile:close() end -- Funzioni per riportare stato lavorazione o pezzo in nge local function WriteErrToNge( nProcId, sErr, sMsg, sRot, sCutId, sTaskId) EgtSetInfo( nProcId, 'STATUS.ERR', sErr) EgtSetInfo( nProcId, 'STATUS.MSG', sMsg) EgtSetInfo( nProcId, 'STATUS.ROT', sRot) EgtSetInfo( nProcId, 'CUTID', sCutId) EgtSetInfo( nProcId, 'TASKID', sTaskId) end local function WriteFallToNge( nPartId, sErr, sMsg, sCutId, sFall) EgtSetInfo( nPartId, 'STATUS.ERR', sErr) EgtSetInfo( nPartId, 'STATUS.MSG', sMsg) EgtSetInfo( nPartId, 'CUTID', sCutId) EgtSetInfo( nPartId, 'STATUS.FALL', sFall) end -- Funzione per gestire visualizzazione dopo errore local function PostErrView( nErr, sMsg) if nErr ~= 0 and ( BEAM.FLAG == 1 or BEAM.FLAG == 2) then EgtSetView( SCE_VD.ISO_SW, false) EgtZoom( SCE_ZM.ALL) EgtOutBox( sMsg, 'BatchProcess (err=' .. tostring( nErr) .. ')', 'ERRORS') end end -- Funzione per gestire visualizzazione dopo warning local function PostWarnView( nWarn, sMsg) if nWarn ~= 0 and ( BEAM.FLAG == 1 or BEAM.FLAG == 2) then EgtSetView( SCE_VD.ISO_SW, false) EgtZoom( SCE_ZM.ALL) EgtOutBox( sMsg, 'BatchProcess (wrn=' .. tostring( nWarn) .. ')', 'WARNINGS') end end -- Funzione per aggiornare dati ausiliari local function UpdateAuxData( sAuxFile) local bModif = false local BtlInfoId = EgtGetFirstNameInGroup( GDB_ID.ROOT, 'BtlInfo') or GDB_ID.NULL -- Se definito LOAD90, aggiorno local sLoad90 = EgtGetStringFromIni( 'AuxData', 'LOAD90', '', sAuxFile) if sLoad90 ~= '' then EgtSetInfo( BtlInfoId, 'LOAD90', sLoad90) bModif = true end -- Se definito PROJID, aggiorno local sProjId = EgtGetStringFromIni( 'AuxData', 'PROJID', '', sAuxFile) if sProjId ~= '' then EgtSetInfo( BtlInfoId, 'PROJECTNUMBER', sProjId) bModif = true end -- Se definito PRODID, aggiorno local sProdId = EgtGetStringFromIni( 'AuxData', 'PRODID', '', sAuxFile) if sProdId ~= '' then EgtSetInfo( BtlInfoId, 'PRODID', sProdId) bModif = true end return bModif end -- Imposto direttorio libreria specializzata per Travi EgtAddToPackagePath( BEAM.BASEDIR .. '\\LuaLibs\\?.lua') -- Impostazione della macchina corrente EgtResetCurrMachGroup() local sMachine = 'Essetre-' .. BEAM.MACHINE if not EgtSetCurrMachine( sMachine) then BEAM.ERR = 11 BEAM.MSG = 'Error selecting machine : ' .. sMachine WriteErrToLogFile( BEAM.ERR, BEAM.MSG) PostErrView( BEAM.ERR, BEAM.MSG) return end -- Verifico che la macchina corrente sia abilitata per la lavorazione delle Travi local sMachDir = EgtGetCurrMachineDir() if not EgtExistsFile( sMachDir .. '\\Beam\\BeamData.lua') then BEAM.ERR = 12 BEAM.MSG = 'Error not configured for beams machine : ' .. sMachine WriteErrToLogFile( BEAM.ERR, BEAM.MSG) PostErrView( BEAM.ERR, BEAM.MSG) return end -- Elimino direttori altre macchine e imposto direttorio macchina corrente per ricerca librerie EgtRemoveBaseMachineDirFromPackagePath() EgtAddToPackagePath( sMachDir .. '\\Beam\\?.lua') -- Se modalità visualizzazione finestre per DB esco if BEAM.FLAG > 10 then BEAM.ERR = 0 return end -- Carico le librerie _G.package.loaded.BeamExec = nil local BE = require( 'BeamExec') local BL = require( 'BeamLib') -- Carico i dati globali local BD = require( 'BeamData') -- Dati del file local sDir, sTitle, sExt = EgtSplitPath( BEAM.FILE) local bBtl = ( string.upper( sExt or '') ~= '.NGE') local sNgeFile = sDir..sTitle..'.nge' local sBtmFile = sDir..sTitle..'.btm' -- In generale va completamente riprocessato local bToProcess = true local bToRecalc = false -- se BTL, barra ed esiste già il corrispondente progetto Nge if bBtl and string.find( sTitle, 'Bar_', 1, true) and EgtExistsFile( sNgeFile) then local sOriFile = sDir..sTitle..'.ori'..sExt local sDiffFile = sDir..sTitle..'.diff.txt' EgtEraseFile( sDiffFile) local _, nDiff = EgtTextFileCompare( BEAM.FILE, sOriFile, ';', sDiffFile) -- se BTL corrente coincide con originale, salto il riprocessamento if nDiff == 0 then bToProcess = false -- se cambiata configurazione macchina da ultima elaborazione, devo riprocessare if EgtCompareFilesLastWriteTime( sOriFile, sMachDir .. '\\Beam\\TS3Data.lua') == -1 or EgtCompareFilesLastWriteTime( sOriFile, sMachDir .. '\\Tools\\Tools.data') == -1 or EgtCompareFilesLastWriteTime( sOriFile, sMachDir .. '\\' .. sMachine ..'.mlde') == -1 then bToRecalc = true end end end -- Inizializzo contatori errori e avvisi local nErrCnt = 0 local nWarnCnt = 0 -- Se da elaborare if bToProcess then EgtOutLog( ' +++ Processing Parts >>>') -- Se Btl, lo importo if bBtl then -- cancello eventuale vecchio progetto omonimo EgtEraseFile( sNgeFile) -- eseguo import EgtNewFile() local nBtlFlag = EIB_FL.TS3_POS + EIB_FL.USEUATTR if BD.USE_PART_OFFSET then nBtlFlag = nBtlFlag + EIB_FL.PARTOFFSET end if not EgtImportBtl( BEAM.FILE, nBtlFlag) then BEAM.ERR = 13 BEAM.MSG = 'Error importing BTL file : ' .. BEAM.FILE WriteErrToLogFile( BEAM.ERR, BEAM.MSG) PostErrView( BEAM.ERR, BEAM.MSG) return end -- faccio copia del file btl originale EgtCopyFile( BEAM.FILE, sDir..sTitle..'.ori'..sExt) -- altrimenti Nge, lo apro else if not EgtOpenFile( BEAM.FILE) then BEAM.ERR = 13 BEAM.MSG = 'Error opening NGE file : ' .. BEAM.FILE WriteErrToLogFile( BEAM.ERR, BEAM.MSG) PostErrView( BEAM.ERR, BEAM.MSG) return end -- faccio copia del file originale EgtCopyFile( BEAM.FILE, sDir..sTitle..'.ori'..sExt) end -- Aggiorno eventuali dati ausiliari UpdateAuxData( sBtmFile) -- Recupero l'elenco ordinato delle travi local vBeam = {} local nPartId = EgtGetFirstPart() while nPartId do table.insert( vBeam, { Id = nPartId, Name = ( EgtGetName( nPartId) or ( 'Id=' .. tonumber( nPartId)))}) nPartId = EgtGetNextPart( nPartId) end if #vBeam == 0 then BEAM.ERR = 14 BEAM.MSG = 'Error no beams in the file : ' .. BEAM.FILE WriteErrToLogFile( BEAM.ERR, BEAM.MSG) PostErrView( BEAM.ERR, BEAM.MSG) return else local sOut = '' for i = 1, #vBeam do sOut = sOut .. vBeam[i].Name .. ', ' end sOut = sOut:sub( 1, -3) EgtOutLog( 'Travi trovate : ' .. sOut, 1) end -- Ne recupero le dimensioni for i = 1, #vBeam do local Ls = EgtGetFirstNameInGroup( vBeam[i].Id, 'Box') local b3Solid = EgtGetBBoxGlob( Ls or GDB_ID.NULL, GDB_BB.STANDARD) if not b3Solid then BEAM.ERR = 15 BEAM.MSG = 'Box undefined for beam ' .. vBeam[i].Name WriteErrToLogFile( BEAM.ERR, BEAM.MSG) PostErrView( BEAM.ERR, BEAM.MSG) return else vBeam[i].Box = b3Solid end end -- Ne recupero la posizione for i = 1, #vBeam do local PosX = EgtGetInfo( vBeam[i].Id, 'POSX', 'd') vBeam[i].PosX = PosX end -- Se non già eseguite, applico eventuali rotazioni e inversioni testa-coda for i = 1, #vBeam do local b3Solid = vBeam[i].Box -- rotazione local dRotAng = EgtGetInfo( vBeam[i].Id, 'ROTATED', 'd') or 0 if abs( dRotAng) > GEO.EPS_ANG_SMALL then local ptRotCen = b3Solid:getCenter() EgtRotate( vBeam[i].Id, ptRotCen, X_AX(), dRotAng, GDB_RT.GLOB) b3Solid:rotate( ptRotCen, X_AX(), dRotAng) end EgtRemoveInfo( vBeam[i].Id, 'ROTATED') EgtSetInfo( vBeam[i].Id, 'ROTATED_OK', dRotAng) -- inversione local dInvAng = 180 - ( EgtGetInfo( vBeam[i].Id, 'INVERTED', 'd') or 0) if abs( dInvAng) > GEO.EPS_ANG_SMALL then local ptInvCen = b3Solid:getCenter() EgtRotate( vBeam[i].Id, ptInvCen, Z_AX(), dInvAng, GDB_RT.GLOB) end EgtRemoveInfo( vBeam[i].Id, 'INVERTED') EgtSetInfo( vBeam[i].Id, 'INVERTED_OK', 180 - dInvAng) end -- Ne verifico le dimensioni local dRawW = vBeam[1].Box:getDimY() local dRawH = vBeam[1].Box:getDimZ() local vBeamErr = {} for i = 2, #vBeam do local dDimW = vBeam[i].Box:getDimY() local dDimH = vBeam[i].Box:getDimZ() if ( abs( dDimW - dRawW) > 100 * GEO.EPS_SMALL or abs( dDimH - dRawH) > 100 * GEO.EPS_SMALL) and ( abs( dDimH - dRawW) > 100 * GEO.EPS_SMALL or abs( dDimW - dRawH) > 100 * GEO.EPS_SMALL) then table.insert( vBeamErr, i) end end if #vBeamErr > 0 then local sOut = 'Rimosse travi con sezioni diverse dalla prima :\n' for i = #vBeamErr, 1, -1 do sOut = sOut .. vBeam[vBeamErr[i]].Name .. '\n' table.remove( vBeam, vBeamErr[i]) end BEAM.ERR = 16 BEAM.MSG = sOut WriteErrToLogFile( BEAM.ERR, BEAM.MSG) PostErrView( BEAM.ERR, BEAM.MSG) return end -- Verifico sezione barra non troppo grande if not BD.MAX_WIDTH2 or not BD.MAX_HEIGHT2 then if ( dRawW > BD.MAX_WIDTH + 10 * GEO.EPS_SMALL or dRawH > BD.MAX_HEIGHT + 10 * GEO.EPS_SMALL) then local sOut = 'Sezione (' .. EgtNumToString( dRawW, 2) .. ' x ' .. EgtNumToString( dRawH, 2) .. ') ' .. 'oltre i limiti della macchina (' .. EgtNumToString( BD.MAX_WIDTH, 2) .. ' x ' .. EgtNumToString( BD.MAX_HEIGHT, 2) .. ') ' BEAM.ERR = 17 BEAM.MSG = sOut WriteErrToLogFile( BEAM.ERR, BEAM.MSG) PostErrView( BEAM.ERR, BEAM.MSG) return end else if ( dRawW > BD.MAX_WIDTH + 10 * GEO.EPS_SMALL or dRawH > BD.MAX_HEIGHT + 10 * GEO.EPS_SMALL) and ( dRawW > BD.MAX_WIDTH2 + 10 * GEO.EPS_SMALL or dRawH > BD.MAX_HEIGHT2 + 10 * GEO.EPS_SMALL) then local sOut = 'Sezione (' .. EgtNumToString( dRawW, 2) .. ' x ' .. EgtNumToString( dRawH, 2) .. ') ' .. 'oltre i limiti della macchina (' .. EgtNumToString( BD.MAX_WIDTH, 2) .. ' x ' .. EgtNumToString( BD.MAX_HEIGHT, 2) .. ') ' .. 'e (' .. EgtNumToString( BD.MAX_WIDTH2, 2) .. ' x ' .. EgtNumToString( BD.MAX_HEIGHT2, 2) .. ')' BEAM.ERR = 17 BEAM.MSG = sOut WriteErrToLogFile( BEAM.ERR, BEAM.MSG) PostErrView( BEAM.ERR, BEAM.MSG) return end end -- Verifico sezione barra non troppo piccola if dRawW < BD.MIN_WIDTH - 10 * GEO.EPS_SMALL or dRawH < BD.MIN_HEIGHT - 10 * GEO.EPS_SMALL then local sOut = 'Sezione (' .. EgtNumToString( dRawW, 2) .. ' x ' .. EgtNumToString( dRawH, 2) .. ') ' .. 'sotto i limiti della macchina (' .. EgtNumToString( BD.MIN_WIDTH, 2) .. ' x ' .. EgtNumToString( BD.MIN_HEIGHT, 2) .. ')' BEAM.ERR = 17 BEAM.MSG = sOut WriteErrToLogFile( BEAM.ERR, BEAM.MSG) PostErrView( BEAM.ERR, BEAM.MSG) return end -- Se presente offset da btl, verifico se offset uguale per tutti i pezzi if BD.USE_PART_OFFSET then vBeamErr = {} local sPartOffset = EgtGetInfo( vBeam[1].Id, 'PARTOFFSET', 's') or '' local vPartOffset = EgtSplitString( sPartOffset) local dRotAng = EgtGetInfo( vBeam[1].Id, 'ROTATED_OK', 'd') or 0 for i = 2, #vBeam do local sPartOffsetCurrent = EgtGetInfo( vBeam[i].Id, 'PARTOFFSET', 's') or '' local vPartOffsetCurrent = EgtSplitString( sPartOffsetCurrent) local dRotAngCurrent = EgtGetInfo( vBeam[i].Id, 'ROTATED_OK', 'd') or 0 local dRotAngDelta = abs( dRotAngCurrent - dRotAng) if ( #vPartOffset == 5) and ( #vPartOffsetCurrent == 5) then if dRotAngDelta < GEO.EPS_ANG_SMALL then if ( vPartOffsetCurrent[2] ~= vPartOffsetCurrent[2]) or ( vPartOffsetCurrent[3] ~= vPartOffset[3]) or ( vPartOffsetCurrent[4] ~= vPartOffset[4]) or ( vPartOffsetCurrent[5] ~= vPartOffset[5]) then table.insert( vBeamErr, i) end elseif dRotAngDelta - 180 < GEO.EPS_ANG_SMALL then if ( vPartOffsetCurrent[2] ~= vPartOffsetCurrent[4]) or ( vPartOffsetCurrent[3] ~= vPartOffset[5]) or ( vPartOffsetCurrent[4] ~= vPartOffset[2]) or ( vPartOffsetCurrent[5] ~= vPartOffset[3]) then table.insert( vBeamErr, i) end -- se pezzo ruotato di 90deg rispetto al principale, al momento si dà sempre errore else table.insert( vBeamErr, i) end else if sPartOffsetCurrent ~= sPartOffset then table.insert( vBeamErr, i) end end end if #vBeamErr > 0 then local sOut = 'Part offset not consistent in beam(s) : ' for i = #vBeamErr, 1, -1 do local sSeparator = ', ' if i == 1 then sSeparator = '' end sOut = sOut .. vBeam[vBeamErr[i]].Name .. sSeparator end BEAM.ERR = 17 BEAM.MSG = sOut WriteErrToLogFile( BEAM.ERR, BEAM.MSG) PostErrView( BEAM.ERR, BEAM.MSG) return end end -- Lunghezza della barra local dRawL = ( EgtGetInfo( EgtGetFirstNameInGroup( GDB_ID.ROOT, 'BtlInfo') or GDB_ID.NULL, 'BARLEN', 'd') or 12000) + 0.1 -- Sovramateriale di testa local dOvmHead = vBeam[1].PosX or 0 -- Sistemo le travi nel grezzo local bPbOk, sPbErr = BE.ProcessBeams( dRawW, dRawH, dRawL, dOvmHead, nil, vBeam) if not bPbOk then BEAM.ERR = 18 BEAM.MSG = sPbErr WriteErrToLogFile( BEAM.ERR, BEAM.MSG) PostErrView( BEAM.ERR, BEAM.MSG) return end -- Imposto Nome file CN local _, sName, _ = EgtSplitPath( BEAM.FILE) EgtSetInfo( EgtGetCurrMachGroup(), 'NcName', sName .. '.cnc') -- Abilito Vmill EgtSetInfo( EgtGetCurrMachGroup(), 'Vm', '1') -- Lavoro le features local bPfOk, Stats = BE.ProcessFeatures() local sOutput = '' for i = 1, #Stats do local sMsg = Stats[i].Msg sMsg = string.gsub( sMsg, '\n', ' ', 10) sMsg = string.gsub( sMsg, '\r', ' ', 10) if Stats[i].Err == 0 then BEAM.ERR = 0 BEAM.MSG = '---' BEAM.ROT = Stats[i].Rot or 0 BEAM.CUTID = Stats[i].CutId BEAM.TASKID = Stats[i].TaskId WriteErrToLogFile( BEAM.ERR, BEAM.MSG, BEAM.ROT, BEAM.CUTID, BEAM.TASKID) if Stats[i].ProcId then WriteErrToNge( Stats[i].ProcId, BEAM.ERR, BEAM.MSG, BEAM.ROT, BEAM.CUTID, BEAM.TASKID) end elseif Stats[i].Err > 0 then nErrCnt = nErrCnt + 1 sOutput = sOutput .. string.format( '[%d,%d] %s\n', Stats[i].CutId, Stats[i].TaskId, sMsg) BEAM.ERR = 19 BEAM.MSG = sMsg BEAM.ROT = Stats[i].Rot or 0 BEAM.CUTID = Stats[i].CutId BEAM.TASKID = Stats[i].TaskId WriteErrToLogFile( BEAM.ERR, BEAM.MSG, BEAM.ROT, BEAM.CUTID, BEAM.TASKID) if Stats[i].ProcId then WriteErrToNge( Stats[i].ProcId, BEAM.ERR, BEAM.MSG, BEAM.ROT, BEAM.CUTID, BEAM.TASKID) end elseif Stats[i].Err < 0 then -- se segnalazione scarico pezzo standard, incompleto o a caduta if Stats[i].Err == -100 or Stats[i].Err == -101 or Stats[i].Err == -102 then BEAM.ERR = 0 BEAM.MSG = sMsg BEAM.CUTID = Stats[i].CutId BEAM.FALL = abs( Stats[i].Err + 100) WriteFallToLogFile( BEAM.ERR, BEAM.MSG, BEAM.CUTID, BEAM.FALL) if Stats[i].ProcId then WriteFallToNge( Stats[i].PartId, BEAM.ERR, BEAM.MSG, BEAM.CUTID, BEAM.FALL) end -- altri avvertimenti else nWarnCnt = nWarnCnt + 1 sOutput = sOutput .. string.format( '[%d,%d] %s\n', Stats[i].CutId, Stats[i].TaskId, sMsg) BEAM.ERR = -19 BEAM.MSG = sMsg BEAM.ROT = Stats[i].Rot or 0 BEAM.CUTID = Stats[i].CutId BEAM.TASKID = Stats[i].TaskId WriteErrToLogFile( BEAM.ERR, BEAM.MSG, BEAM.ROT, BEAM.CUTID, BEAM.TASKID) if Stats[i].ProcId then WriteErrToNge( Stats[i].ProcId, BEAM.ERR, BEAM.MSG, BEAM.ROT, BEAM.CUTID, BEAM.TASKID) end end end end -- Salvo il progetto EgtSaveFile( sNgeFile) -- Visualizzazione avvisi o errori if #sOutput > 0 then EgtOutLog( sOutput) end if nErrCnt > 0 then PostErrView( 19, sOutput) elseif nWarnCnt > 0 then PostWarnView( 19, sOutput) end -- Altrimenti carico il progetto salvato, rileggo gli errori da nge e riscrivo il log txt con gli stati precedenti else EgtOutLog( ' +++ Loading Project already processed >>>') -- Carico il progetto già fatto EgtOpenFile( sNgeFile) -- Riscrivo il log txt local nPartId = EgtGetFirstPart() while nPartId do local nCutId = EgtGetInfo( nPartId, 'CUTID') if nCutId then -- stato a livello di singola feature local nProcId = EgtGetFirstInGroup( EgtGetFirstNameInGroup( nPartId, 'Processings') or GDB_ID.NULL) while nProcId do local bIsFea = EgtExistsInfo( nProcId, 'GRP') and EgtExistsInfo( nProcId, 'PRC') local nTaskId = EgtGetInfo( nProcId, 'TASKID') local sErr = EgtGetInfo( nProcId, 'STATUS.ERR') or 0 local sMsg = EgtGetInfo( nProcId, 'STATUS.MSG') or '---' local sRot = EgtGetInfo( nProcId, 'STATUS.ROT') or 0 if bIsFea and nTaskId then BEAM.ERR = sErr BEAM.MSG = sMsg BEAM.ROT = sRot BEAM.CUTID = nCutId BEAM.TASKID = nTaskId WriteErrToLogFile( BEAM.ERR, BEAM.MSG, BEAM.ROT, BEAM.CUTID, BEAM.TASKID) end nProcId = EgtGetNext( nProcId) end -- stato a livello di pezzo local sErr = EgtGetInfo( nPartId, 'STATUS.ERR') or 0 if sErr == -100 or sErr == -101 or sErr == -102 then local sMsg = EgtGetInfo( nPartId, 'STATUS.MSG') or '---' local sFall = EgtGetInfo( nPartId, 'STATUS.FALL') or 0 BEAM.ERR = sErr BEAM.MSG = sMsg BEAM.CUTID = nCutId BEAM.FALL = sFall WriteFallToLogFile( BEAM.ERR, BEAM.MSG, BEAM.CUTID, BEAM.FALL) end end nPartId = EgtGetNextPart( nPartId) end -- Aggiorno eventuali dati ausiliari UpdateAuxData( sBtmFile) -- Anche se non è da riprocessare, imposto nome file CN. -- Se file TS7 importato da altro PC, 'BEAM.FILE' è cambiato da un PC all'altro. Di conseguenza si deve aggiornare nome file che si andrà a generare. local _, sName, _ = EgtSplitPath( BEAM.FILE) EgtSetInfo( EgtGetLastMachGroup(), 'NcName', sName .. '.cnc') -- Passo in modalità lavora EgtSetCurrMachGroup( EgtGetLastMachGroup()) -- Se necessario eseguo aggiornamento con setup corrente e ricalcolo delle lavorazioni if bToRecalc or BEAM.FLAG == 3 or BEAM.FLAG == 4 then EgtOutLog( ' +++ Recalculating all dispositions and machinings >>>') EgtImportSetup() EgtApplyAllMachinings() -- copia del file btl originale (per dichiarare progetto ricalcolato) EgtCopyFile( BEAM.FILE, sDir..sTitle..'.ori'..sExt) end -- Salvo il progetto EgtSaveFile( sNgeFile) end -- *** Eseguo simulazione con verifica collisione in cieco *** if ( BEAM.FLAG == 0 and ( bToProcess or bToRecalc)) or BEAM.FLAG == 3 or BEAM.FLAG == 4 then EgtOutLog( ' +++ Simulating with collision check >>>') -- verifico setup local bSetUpOk, SetUpErrors = EgtVerifyCurrSetup() if not bSetUpOk then local sToolsList = "" for ToolIndex = 1, #SetUpErrors do sToolsList = sToolsList .. SetUpErrors[ToolIndex] if ToolIndex ~= #SetUpErrors then sToolsList = sToolsList .. ", " end end WriteErrToLogFile( 19, 'Error in setup: tool/s ' .. sToolsList .. ' not found', 0, 0, 0) return end -- lancio simulazione local bSimOk, nErr, sErr = EgtSimulate() if not bSimOk then if nErr == MCH_SHE.INIT then BEAM.ERR = 19 BEAM.MSG = 'Error starting simulation' elseif nErr == MCH_SHE.COLLISION then BEAM.ERR = 22 BEAM.MSG = 'Head-part collision' elseif nErr == MCH_SHE.OUTSTROKE then BEAM.ERR = 23 BEAM.MSG = 'Axis outstroke ' .. sErr elseif nErr == MCH_SHE.SPECIAL then BEAM.ERR = 24 BEAM.MSG = 'Special error ' .. sErr else BEAM.ERR = 25 BEAM.MSG = 'General failure (contact supplier)' end BEAM.ROT = 0 BEAM.CUTID = 0 BEAM.TASKID = 0 local vItem = EgtSplitString( sErr, ';') or {} for i = 1, #vItem do vItem[i] = EgtTrim( vItem[i] or '') if string.find( vItem[i], 'CUTID', 1, true) then BEAM.CUTID = EgtGetVal( vItem[i], 'CUTID', 'i') or 0 elseif string.find( vItem[i], 'TASKID', 1, true) then BEAM.TASKID = EgtGetVal( vItem[i], 'TASKID', 'i') or 0 end end WriteErrToLogFile( BEAM.ERR, BEAM.MSG, BEAM.ROT, BEAM.CUTID, BEAM.TASKID) return end end -- *** Genero programma CN *** ( se richiesto) local bIsGenerationEnabled = ( EgtVerifyKeyOption( 110) == false) if bIsGenerationEnabled and ( BEAM.FLAG == 0 or BEAM.FLAG == 4) then EgtOutLog( ' +++ Generating NC part program >>>') local sInfo = 'EgtCAM5' .. EgtIf( EgtIs64bit(), ' 64bit', '') if EgtGetExeVersion then sInfo = sInfo .. ' ver.' .. EgtGetExeVersion() end sInfo = sInfo .. ' - ' if not EgtGenerate( '', sInfo .. sNgeFile) then BEAM.ERR = 20 local _, sName, _ = EgtSplitPath( BEAM.FILE) BEAM.MSG = 'Error generating NC part program : ' .. sName WriteErrToLogFile( BEAM.ERR, BEAM.MSG) PostErrView( BEAM.ERR, BEAM.MSG) return end end -- *** Eseguo stima tempi *** EgtOutLog( ' +++ Estimating T&L >>>') if not EgtEstimate( '', 'EgtCAM5 - ' .. sNgeFile) then BEAM.ERR = 21 local _, sName, _ = EgtSplitPath( BEAM.FILE) BEAM.MSG = 'Error estimating production time : ' .. sName WriteErrToLogFile( BEAM.ERR, BEAM.MSG) PostErrView( BEAM.ERR, BEAM.MSG) return end local Ttot = EgtGetInfo( EgtGetCurrMachGroup(), 'Ttot') local sTime = 'Total Time = ' .. EgtNumToString( Ttot, 1) EgtOutLog( sTime) -- Imposto la vista ISO 3d, se richiesto if BEAM.FLAG == 1 or BEAM.FLAG == 2 then local vView = { SCE_VD.ISO_NW, SCE_VD.ISO_SW, SCE_VD.ISO_NE, SCE_VD.ISO_SE} local nV = min( max( BD.SIMUL_VIEW_DIR or 2, 1), 4) EgtSetView( vView[nV], false) end -- Completamento senza errori e avvisi if nWarnCnt == 0 then BEAM.ERR = 0 BEAM.MSG = '---' WriteErrToLogFile( BEAM.ERR, BEAM.MSG) end -- Scrittura tempo totale stimato di lavorazione WriteTimeToLogFile( Ttot) EgtOutLog( ' +++ BatchProcess completed')