From 1dae899c6e424622f76a51b85a2ab1e5e1ea620c Mon Sep 17 00:00:00 2001 From: "luca.mazzoleni" Date: Thu, 24 Apr 2025 15:08:33 +0200 Subject: [PATCH] - aggiunta BatchProcessNew copiata da automatismo vecchio, con poche modifiche --- BatchProcessNew.lua | 631 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 631 insertions(+) create mode 100644 BatchProcessNew.lua diff --git a/BatchProcessNew.lua b/BatchProcessNew.lua new file mode 100644 index 0000000..170921b --- /dev/null +++ b/BatchProcessNew.lua @@ -0,0 +1,631 @@ +-- BatchProcessNew.lua by Egaltech s.r.l. 2025/04/24 + +-- Intestazioni +require( 'EgtBase') +_ENV = EgtProtectGlobal() +EgtEnableDebug( false) + +-- Elimino direttori altre macchine e imposto direttorio macchina corrente per ricerca librerie +EgtRemoveBaseMachineDirFromPackagePath() +EgtAddToPackagePath( sMachDir .. '\\Beam\\?.lua') + +-- Carico le librerie +_G.package.loaded.BeamExec = nil +local BeamExec = require( 'BeamExec') +local BeamLib = require( 'BeamLib') + +-- Carico i dati globali +local BeamData = require( 'BeamData') + +-- Dati del file +local sDir, sTitle = EgtSplitPath( BEAM.FILE) +local sOriFile = sDir..sTitle..'.ori.bwe' +local sNgeFile = sDir..sTitle..'.bwe' +local sTxtLogFile = EgtChangePathExtension( BEAM.FILE, '.txt') + +------------------------------------------------------------------------------------------------------------- +-- Funzioni per scrittura su file di log specifico +local function WriteErrToLogFile( nErr, sMsg, nRot, nCutId, nTaskId) + local hFile = io.open( sTxtLogFile, '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( sTxtLogFile, '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( sTxtLogFile, 'a') + hFile:write( 'TIME=' .. EgtNumToString( dTime) .. '\n') + hFile:close() +end + +-- Funzioni per gestire visualizzazione dopo errore e dopo warning +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 + +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 di reset gruppo di lavoro in caso di impossibilità di inserire i pezzi +local function ResetMachGroup( vBeam) + for i = 1, #vBeam do + EgtErase( vBeam[i].Id) + end + EgtRemoveMachGroup( EgtGetCurrMachGroup() or GDB_ID.NULL) +end + +------------------------------------------------------------------------------------------------------------- +-- 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 == 6 then + sFlag = 'CREATE_BAR' +else + sFlag = 'FLAG='..tostring( BEAM.FLAG) +end +local sLog = 'BatchProcess : ' .. BEAM.FILE .. ', ' .. BEAM.MACHINE .. ', ' .. sFlag +EgtOutLog( sLog) + +-- 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( sTxtLogFile, '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( sTxtLogFile) + +-- Imposto direttorio libreria specializzata per Travi +EgtAddToPackagePath( BEAM.BASEDIR .. '\\LuaLibs\\?.lua') + +-- Se necessario, impostazione della macchina corrente +local sMachine = BEAM.MACHINE +if BEAM.FLAG ~= 6 then + EgtResetCurrMachGroup() + 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 +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 + +-- In generale va completamente riprocessato +local bToProcess = true +local bToRecalc = false +-- se BTL, barra ed esiste già il corrispondente progetto Nge +if EgtExistsFile( sOriFile) then + bToProcess = false + EgtCopyFile( sOriFile, sNgeFile) + -- se cambiata configurazione macchina da ultima elaborazione, devo aggiornare + 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 + +-- Inizializzo contatori errori e avvisi +local nErrCnt = 0 +local nWarnCnt = 0 + +-- Se da elaborare +if bToProcess then + EgtOutLog( ' +++ Processing Parts >>>') + + -- Flag di barra da creare + local bCreateBar + -- Lunghezza della barra ed elenco travi + local dBarLen + local vBeam = {} + + -- Se necessario, apro il file Bwe + if BEAM.FLAG ~= 6 then + if not EgtOpenFile( BEAM.FILE) then + BEAM.ERR = 13 + BEAM.MSG = 'Error opening BWE file : ' .. BEAM.FILE + WriteErrToLogFile( BEAM.ERR, BEAM.MSG) + PostErrView( BEAM.ERR, BEAM.MSG) + return + end + -- Faccio copia del file originale + EgtCopyFile( BEAM.FILE, sOriFile) + + -- Aggiorno eventuali dati ausiliari + --UpdateAuxData( sBtmFile) + + -- Se già presente un gruppo di lavoro + if EgtGetFirstMachGroup() then + -- Barra già presente + bCreateBar = false + -- Rendo corrente il gruppo di lavoro + EgtSetCurrMachGroup() + -- Area tavola + local b3Tab = EgtGetTableArea() + -- Sezione del grezzo + local nRawId = EgtGetFirstRawPart() + if not nRawId then + BEAM.ERR = 14 + BEAM.MSG = 'Error no Raw Parts in the file : ' .. BEAM.FILE + WriteErrToLogFile( BEAM.ERR, BEAM.MSG) + PostErrView( BEAM.ERR, BEAM.MSG) + return + end + local b3Raw = EgtGetRawPartBBox( nRawId) + -- Calcolo posizione estremo TR o BR della tavola rispetto a sua origine in BL + local dPosY = EgtIf( BeamData.CENTER_BEAM, ( b3Tab:getDimY() + b3Raw:getDimY() * EgtIf( BeamData.RIGHT_LOAD, -1, 1)) / 2, EgtIf( BeamData.RIGHT_LOAD, 0, b3Tab:getDimY())) + BeamData.OriXR = Point3d( b3Tab:getDimX(), dPosY, 0) + BeamData.PosXR = EgtIf( BeamData.RIGHT_LOAD, MCH_CR.BR, MCH_CR.TR) + -- Calcolo minimo grezzo scaricabile + BeamExec.CalcMinUnloadableRaw( b3Raw:getDimY(), b3Raw:getDimZ()) + -- altrimenti devo recuperare i pezzi per creare la barra + else + -- Barra da creare + bCreateBar = true + -- Recupero l'elenco ordinato delle travi + 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 + -- Assegno lunghezza della barra + dBarLen = vBeam[1].Box:getDimX() + 10 + if dBarLen < 2200 then + dBarLen = dBarLen + 1800 + end + -- Assegno posizione prima ed unica trave + vBeam[1].PosX = 10 + end + + -- Altrimenti, opero sul progetto corrente + else + -- Recupero l'identificativo del gruppo di lavoro corrente + local nMGrpId = EgtGetCurrMachGroup() + -- Barra da creare + bCreateBar = true + -- Lunghezza della barra + dBarLen = EgtGetInfo( nMGrpId, 'BARLEN', 'd') + -- Recupero l'elenco ordinato delle travi da inserire nella barra + for i = 1, 100 do + local sKey = 'PART'..tostring( i) + local sVal = EgtGetInfo( nMGrpId, sKey) + local vVal = EgtSplitString( sVal or '') + if not vVal or #vVal < 2 then break end + local nPartId = tonumber( vVal[1]) + local dPosX = tonumber( vVal[2]) + table.insert( vBeam, { Id = nPartId, PosX = dPosX, Name = ( EgtGetName( nPartId) or ( 'Id=' .. tonumber( nPartId)))}) + end + if #vBeam == 0 then + BEAM.ERR = 14 + BEAM.MSG = 'Error : no beams in the project' + WriteErrToLogFile( 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) + return + else + vBeam[i].Box = b3Solid + end + end + end + + -- Se devo creare la barra + if bCreateBar then + local dRawW + local dRawH + if #vBeam == 0 then + -- Recupero l'identificativo del gruppo di lavoro corrente + local nMGrpId = EgtGetCurrMachGroup() + -- Recupero le dimensioni della barra + dRawW = EgtGetInfo(nMGrpId, 'BARWIDTH', 'd') + dRawH = EgtGetInfo(nMGrpId, 'BARHEIGHT', 'd') + else + -- Ne verifico le dimensioni + dRawW = vBeam[1].Box:getDimY() + dRawH = vBeam[1].Box:getDimZ() + end + 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 + ResetMachGroup( vBeam) + 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 BeamData.MAX_WIDTH2 or not BeamData.MAX_HEIGHT2 then + if ( dRawW > BeamData.MAX_WIDTH + 10 * GEO.EPS_SMALL or dRawH > BeamData.MAX_HEIGHT + 10 * GEO.EPS_SMALL) then + ResetMachGroup( vBeam) + local sOut = 'Sezione (' .. EgtNumToString( dRawW, 2) .. ' x ' .. EgtNumToString( dRawH, 2) .. ') ' .. + 'oltre i limiti della macchina (' .. EgtNumToString( BeamData.MAX_WIDTH, 2) .. ' x ' .. EgtNumToString( BeamData.MAX_HEIGHT, 2) .. ') ' + BEAM.ERR = 17 + BEAM.MSG = sOut + WriteErrToLogFile( BEAM.ERR, BEAM.MSG) + PostErrView( BEAM.ERR, BEAM.MSG) + return + end + else + if ( dRawW > BeamData.MAX_WIDTH + 10 * GEO.EPS_SMALL or dRawH > BeamData.MAX_HEIGHT + 10 * GEO.EPS_SMALL) and + ( dRawW > BeamData.MAX_WIDTH2 + 10 * GEO.EPS_SMALL or dRawH > BeamData.MAX_HEIGHT2 + 10 * GEO.EPS_SMALL) then + ResetMachGroup( vBeam) + local sOut = 'Sezione (' .. EgtNumToString( dRawW, 2) .. ' x ' .. EgtNumToString( dRawH, 2) .. ') ' .. + 'oltre i limiti della macchina (' .. EgtNumToString( BeamData.MAX_WIDTH, 2) .. ' x ' .. EgtNumToString( BeamData.MAX_HEIGHT, 2) .. ') ' .. + 'e (' .. EgtNumToString( BeamData.MAX_WIDTH2, 2) .. ' x ' .. EgtNumToString( BeamData.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 < BeamData.MIN_WIDTH - 10 * GEO.EPS_SMALL or dRawH < BeamData.MIN_HEIGHT - 10 * GEO.EPS_SMALL then + ResetMachGroup( vBeam) + local sOut = 'Sezione (' .. EgtNumToString( dRawW, 2) .. ' x ' .. EgtNumToString( dRawH, 2) .. ') ' .. + 'sotto i limiti della macchina (' .. EgtNumToString( BeamData.MIN_WIDTH, 2) .. ' x ' .. EgtNumToString( BeamData.MIN_HEIGHT, 2) .. ')' + BEAM.ERR = 17 + BEAM.MSG = sOut + WriteErrToLogFile( BEAM.ERR, BEAM.MSG) + PostErrView( BEAM.ERR, BEAM.MSG) + return + end + + -- Lunghezza della barra + local dRawL = dBarLen + 0.1 + -- Sovramateriale di testa + local dOvmHead = 0 + if #vBeam > 0 then + dOvmHead = vBeam[1].PosX or 0 + end + + -- Sistemo le travi nel grezzo + local bPbOk, sPbErr = BeamExec.ProcessBeams( dRawW, dRawH, dRawL, dOvmHead, nil, vBeam, BEAM.FLAG == 6) + if not bPbOk then + BEAM.ERR = 18 + BEAM.MSG = sPbErr + WriteErrToLogFile( BEAM.ERR, BEAM.MSG) + PostErrView( BEAM.ERR, BEAM.MSG) + return + else + -- Scrivo altezza e larghezza barra nel gruppo di lavoro corrente + local nMGrpId = EgtGetCurrMachGroup() + EgtSetInfo(nMGrpId, 'BARHEIGHT', dRawH) + EgtSetInfo(nMGrpId, 'BARWIDTH', dRawW) + end + -- sistemazioni per pezzi nella barra + else + -- ciclo sui grezzi + local nRawId = EgtGetFirstRawPart() + while nRawId do + -- massimo un pezzo per grezzo + local nPartId = EgtGetFirstPartInRawPart( nRawId) + -- box del pezzo + local Ls = EgtGetFirstNameInGroup( nPartId, 'Box') + local b3Solid = EgtGetBBoxGlob( Ls or GDB_ID.NULL, GDB_BB.STANDARD) + -- se nel grezzo c'è un pezzo + if nPartId then + -- creo o pulisco gruppo geometrie aggiuntive + BeamLib.CreateOrEmptyAddGroup( nPartId) + -- aggiungo faccia per taglio iniziale al pezzo + BeamLib.AddPartStartFace( nPartId, b3Solid) + -- aggiungo faccia per taglio finale al pezzo + BeamLib.AddPartEndFace( nPartId, b3Solid) + end + -- passo al successivo grezzo + nRawId = EgtGetNextRawPart( nRawId) + end + -- elimino le lavorazioni + EgtRemoveAllOperations() + end + + -- Se richiesta solo barra, esco + if BEAM.FLAG == 6 then + -- Completamento senza errori e avvisi + if nWarnCnt == 0 then + BEAM.ERR = 0 + BEAM.MSG = '---' + WriteErrToLogFile( BEAM.ERR, BEAM.MSG) + end + EgtOutLog( ' +++ BatchProcess completed') + return + end + + -- Imposto Nome file CN + local _, sName, _ = EgtSplitPath( BEAM.FILE) + EgtSetInfo( EgtGetCurrMachGroup(), 'NcName', sName .. '.cnc') + + -- Abilito Vmill + EgtSetInfo( EgtGetCurrMachGroup(), 'Vm', '1') + + -- Aggiorno Setup utensili + EgtImportSetup() + + -- Lavoro le features + --local bPfOk, Stats = BeamExec.ProcessFeatures() + BeamExec.GetProcessings( PARTS) + local bOk, Stats = BeamExec.ProcessMachinings( PARTS) + local sOutput = '' + for i = 1, #Stats do + local sMsg = Stats[i].Msg + sMsg = string.gsub( sMsg or '', '\n', ' ', 10) + sMsg = string.gsub( sMsg or '', '\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) + 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) + 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) + -- 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) + end + end + end + + -- Salvo il progetto + EgtSaveFile( sNgeFile) + -- copio come originale (per dichiarare progetto ricalcolato) + EgtCopyFile( sNgeFile, sOriFile) + + -- 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 e dichiaro nessun errore +else + EgtOutLog( ' +++ Loading Project already processed >>>') + -- Carico il progetto già fatto + EgtOpenFile( sNgeFile) + -- 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() + -- Salvo il progetto + EgtSaveFile( sNgeFile) + -- copio come originale (per dichiarare progetto ricalcolato) + EgtCopyFile( sNgeFile, sOriFile) + end +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', 'd') +local sTime = 'Total Time = ' .. EgtNumToString( Ttot, 1) +EgtOutLog( sTime) + +-- Se modifica o simula, imposto la vista ISO 3d opportuna +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( BeamData.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')