-- BatchProcess.lua by Egaltech s.r.l. 2025/07/17 -- Gestione calcolo batch disposizione e lavorazioni per Pareti -- 2020/07/24 Nuvola di punti riferita allo Zero Tavola. -- 2020/10/28 Corretto spostamento pezzi per rotazioni (0 o 180) e inversioni( 0, 90, 180, o 270). -- 2020/12/03 Ora riconosciute rotazioni di inversione con angoli negativi. -- 2021/03/05 Aggiunta gestione altri angoli di inversione e rotazione combinati. -- 2021/03/06 La creazione del file ori si fa solo alla fine se non ci sono stati errori o se edit. -- 2021/03/08 Aggiunta gestione lavorazione su macchine per travi. -- 2021/04/09 Corretto spostamento pezzi per rotazioni e inversioni. -- 2021/07/28 Aggiunta scelta direzione di vista per modifica e simulazione. -- 2021/10/27 Nel controllo spessore si deve considerare anche PosY. -- 2022/02/24 Se ricalcolo si aggiorna il setup. In ogni caso si verifica prima di simulazione. -- 2022/04/28 In info generazione aggiunta indicazione se 64bit. -- 2022/05/02 Consentito allargamento area disponibile per grezzi su tavola da WallData. -- 2023/04/09 Aggiunta gestione flag per taglio feature con outline (da WD.CUT_WITH_OUTLINE). -- 2023/04/17 Aggiunta gestione flag per rotazione grezzo di 180deg (da WD.RAWPART_ROT). -- 2024/02/20 Tolleranza su altezza pannello in grezzo portata a 0.1 mm. -- Intestazioni require( 'EgtBase') _ENV = EgtProtectGlobal() EgtEnableDebug( false) -- Per test --WALL = {} --WALL.FILE = 'c:\\TechnoEssetre7\\EgtData\\Prods\\0010\\Bar_10_1.btl' --WALL.MACHINE = '90480019_MW' --WALL.FLAG = 5 -- Log dati in input local sFlag = '' if WALL.FLAG == 0 then sFlag = 'GENERATE' elseif WALL.FLAG == 1 then sFlag = 'MODIFY' elseif WALL.FLAG == 2 then sFlag = 'SIMULATE' elseif WALL.FLAG == 3 then sFlag = 'CHECK' elseif WALL.FLAG == 4 then sFlag = 'CHECK+GENERATE' elseif WALL.FLAG == 5 then sFlag = 'CLOUD' elseif WALL.FLAG == 11 then sFlag = 'TOOLS' elseif WALL.FLAG == 12 then sFlag = 'JOBS' else sFlag = 'FLAG='..tostring( WALL.FLAG) end local sLog = 'BatchProcess : ' .. WALL.FILE .. ', ' .. WALL.MACHINE .. ', ' .. sFlag EgtOutLog( sLog) -- Cancello file di log specifico local sLogFile = EgtChangePathExtension( WALL.FILE, '.txt') 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 WriteTimeToLogFile( dTime) local hFile = io.open( sLogFile, 'a') hFile:write( 'TIME=' .. EgtNumToString( dTime) .. '\n') hFile:close() end -- Funzione per gestire visualizzazione dopo errore local function PostErrView( nErr, sMsg) if nErr ~= 0 and ( WALL.FLAG == 1 or WALL.FLAG == 2 or WALL.FLAG == 5) 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 ( WALL.FLAG == 1 or WALL.FLAG == 2 or WALL.FLAG == 5) 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 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 -- Se definito LOAD90, aggiorno local sLoad90 = EgtGetStringFromIni( 'AuxData', 'LOAD90', '', sAuxFile) if sLoad90 ~= '' then EgtSetInfo( BtlInfoId, 'LOAD90', sLoad90) bModif = true end -- Se definito REFPOS, aggiorno local sRefPos = EgtGetStringFromIni( 'AuxData', 'REFPOS', '', sAuxFile) if sRefPos ~= '' then EgtSetInfo( BtlInfoId, 'REFPOS', sRefPos) bModif = true end -- Se definito PANELDELTAX, aggiorno local sPanelDeltaX = EgtGetStringFromIni( 'AuxData', 'PANELDELTAX', '', sAuxFile) if sPanelDeltaX ~= '' then EgtSetInfo( BtlInfoId, 'PANELDELTAX', sPanelDeltaX) bModif = true end -- Se definito PANELDELTAY, aggiorno local sPanelDeltaY = EgtGetStringFromIni( 'AuxData', 'PANELDELTAY', '', sAuxFile) if sPanelDeltaY ~= '' then EgtSetInfo( BtlInfoId, 'PANELDELTAY', sPanelDeltaY) bModif = true end -- Se definito PANELDELTAZ, aggiorno local sPanelDeltaZ = EgtGetStringFromIni( 'AuxData', 'PANELDELTAZ', '', sAuxFile) if sPanelDeltaZ ~= '' then EgtSetInfo( BtlInfoId, 'PANELDELTAZ', sPanelDeltaZ) bModif = true end return bModif end -- Imposto direttorio libreria specializzata per Travi EgtAddToPackagePath( WALL.BASEDIR .. '\\LuaLibs\\?.lua') -- Impostazione della macchina corrente EgtResetCurrMachGroup() local sMachine = 'Essetre-' .. WALL.MACHINE if not EgtSetCurrMachine( sMachine) then WALL.ERR = 11 WALL.MSG = 'Error selecting machine : ' .. sMachine WriteErrToLogFile( WALL.ERR, WALL.MSG) PostErrView( WALL.ERR, WALL.MSG) return end -- Verifico che la macchina corrente sia abilitata per la lavorazione delle Travi local sMachDir = EgtGetCurrMachineDir() if not EgtExistsFile( sMachDir .. '\\Wall\\WallData.lua') then WALL.ERR = 12 WALL.MSG = 'Error not configured for walls machine : ' .. sMachine WriteErrToLogFile( WALL.ERR, WALL.MSG) PostErrView( WALL.ERR, WALL.MSG) return end -- Elimino direttori altre macchine e imposto direttorio macchina corrente per ricerca librerie EgtRemoveBaseMachineDirFromPackagePath() EgtAddToPackagePath( sMachDir .. '\\Wall\\?.lua') -- Se modalità visualizzazione finestre per DB esco if WALL.FLAG > 10 then WALL.ERR = 0 return end -- Carico le librerie _G.package.loaded.WallExec = nil local WE = require( 'WallExec') -- Carico i dati globali local WD = require( 'WallData') -- Dati del file local sDir, sTitle, sExt = EgtSplitPath( WALL.FILE) local bBtl = ( string.upper( sExt or '') ~= '.NGE') local sNgeFile = sDir..sTitle..'.nge' local sBtmFile = sDir..sTitle..'.btm' local sPntFile = sDir..sTitle..'.pnt' -- 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( WALL.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 .. '\\Wall\\TS3Data.lua') == -1 or EgtCompareFilesLastWriteTime( sOriFile, sMachDir .. '\\Tools\\Tools.data') == -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) -- flag di importazione local nFlag = EIB_FL.TS3_POS + EIB_FL.USEUATTR + EgtIf( WD.CUT_WITH_OUTLINE, EIB_FL.TRIM_WITH_OUTLINE or 128, EIB_FL.NONE) -- eseguo import EgtNewFile() if not EgtImportBtl( WALL.FILE, nFlag) then WALL.ERR = 13 WALL.MSG = 'Error importing BTL file : ' .. WALL.FILE WriteErrToLogFile( WALL.ERR, WALL.MSG) PostErrView( WALL.ERR, WALL.MSG) return end -- altrimenti Nge, lo apro else if not EgtOpenFile( WALL.FILE) then WALL.ERR = 13 WALL.MSG = 'Error opening NGE file : ' .. WALL.FILE WriteErrToLogFile( WALL.ERR, WALL.MSG) PostErrView( WALL.ERR, WALL.MSG) return end end -- Aggiorno eventuali dati ausiliari UpdateAuxData( sBtmFile) -- Recupero informazione se progetto o produzione local bProj = ( EgtGetInfo( EgtGetFirstNameInGroup( GDB_ID.ROOT, 'BtlInfo') or GDB_ID.NULL, 'PROJECT', 'i') == 1) -- Dimensioni del pannello local dRawL = ( EgtGetInfo( EgtGetFirstNameInGroup( GDB_ID.ROOT, 'BtlInfo') or GDB_ID.NULL, 'PANELLEN', 'd') or 100) local dRawW = ( EgtGetInfo( EgtGetFirstNameInGroup( GDB_ID.ROOT, 'BtlInfo') or GDB_ID.NULL, 'PANELWIDTH', 'd') or 50) local dExtraL = 0 local dExtraW = 0 if bProj then if WD.BEAM_MACHINE then if dRawL < WD.MIN_LENGTH then dExtraL = WD.MIN_LENGTH - dRawL dRawL = WD.MIN_LENGTH elseif dRawL < WD.MAX_LENGTH then dExtraL = min( WD.MAX_LENGTH - dRawL, 3000) dRawL = dRawL + dExtraL end if dRawW + 10 < WD.MIN_WIDTH then dExtraW = WD.MIN_WIDTH - dRawW dRawW = WD.MIN_WIDTH elseif dRawW < WD.MAX_WIDTH then dExtraW = min( WD.MAX_WIDTH - dRawW, 10) dRawW = dRawW + dExtraW end else dExtraW = 10 if WD.DEFAULT_RAW_NO_EXTRA_WIDTH then dExtraW = 0 end dRawW = dRawW + dExtraW end end -- Recupero l'elenco ordinato delle pareti local vWall = {} local nPartId = EgtGetFirstPart() while nPartId do table.insert( vWall, { Id = nPartId, Name = ( EgtGetName( nPartId) or ( 'Id=' .. tonumber( nPartId)))}) nPartId = EgtGetNextPart( nPartId) end if #vWall == 0 then WALL.ERR = 14 WALL.MSG = 'Error no walls in the file : ' .. WALL.FILE WriteErrToLogFile( WALL.ERR, WALL.MSG) PostErrView( WALL.ERR, WALL.MSG) return else local sOut = '' for i = 1, #vWall do sOut = sOut .. vWall[i].Name .. ', ' end sOut = sOut:sub( 1, -3) EgtOutLog( 'Travi trovate : ' .. sOut, 1) end -- Ne recupero le dimensioni for i = 1, #vWall do local Ls = EgtGetFirstNameInGroup( vWall[i].Id, 'Box') local b3Solid = EgtGetBBoxGlob( Ls or GDB_ID.NULL, GDB_BB.STANDARD) if not b3Solid then WALL.ERR = 15 WALL.MSG = 'Box undefined for beam ' .. vWall[i].Name WriteErrToLogFile( WALL.ERR, WALL.MSG) PostErrView( WALL.ERR, WALL.MSG) return else vWall[i].Box = b3Solid end end -- Ne recupero la posizione for i = 1, #vWall do local PosX = EgtGetInfo( vWall[i].Id, 'POSX', 'd') local PosZ = EgtGetInfo( vWall[i].Id, 'POSZ', 'd') if bProj and WD.DEFAULT_RAW_NO_EXTRA_WIDTH and #vWall == 1 then PosX = 0 PosZ = 0 end vWall[i].PosX = PosX + min( dExtraL, 1200) if WD.USE_POSY then local PosY = EgtGetInfo( vWall[i].Id, 'POSY', 'd') vWall[i].PosY = max( PosY, 0) else vWall[i].PosY = 0 end vWall[i].PosZ = PosZ + dExtraW / 2 end -- Eseguo eventuali rotazioni e inversioni testa-coda for i = 1, #vWall do local b3Solid = vWall[i].Box -- rotazione local dRotAng = EgtGetInfo( vWall[i].Id, 'ROTATED', 'd') if dRotAng then if abs( dRotAng) > GEO.EPS_ANG_SMALL then local ptRotCen = b3Solid:getCenter() EgtRotate( vWall[i].Id, ptRotCen, X_AX(), dRotAng, GDB_RT.GLOB) b3Solid:rotate( ptRotCen, X_AX(), dRotAng) end EgtSetInfo( vWall[i].Id, 'ROTATED_DONE', dRotAng) end -- inversione local dInvAng = EgtGetInfo( vWall[i].Id, 'INVERTED', 'd') if dInvAng then if abs( dInvAng - 180) > GEO.EPS_ANG_SMALL and abs( dInvAng + 180) > GEO.EPS_ANG_SMALL then local ptInvCen = b3Solid:getCenter() EgtRotate( vWall[i].Id, ptInvCen, Z_AX(), dInvAng - 180, GDB_RT.GLOB) b3Solid:rotate( ptInvCen, Z_AX(), dInvAng - 180) end EgtSetInfo( vWall[i].Id, 'INVERTED_DONE', dInvAng) end -- correzioni per rotazioni non centrate di produzioni TS3 (quasi sempre multipli di 90 deg) local sType = EgtGetInfo( vWall[i].Id, 'TYPE', 's') if not bProj and dRotAng and dInvAng and sType ~= 'LAYER' then if abs( dInvAng - 0) < GEO.EPS_ANG_SMALL then if abs( dRotAng - 180) < GEO.EPS_ANG_SMALL then vWall[i].PosZ = vWall[i].PosZ - vWall[i].Box:getDimY() elseif abs( dRotAng - 270) < GEO.EPS_ANG_SMALL then vWall[i].PosZ = vWall[i].PosZ - vWall[i].Box:getDimY() end elseif abs( dInvAng - 90) < GEO.EPS_ANG_SMALL or abs( dInvAng + 270) < GEO.EPS_ANG_SMALL then vWall[i].PosZ = vWall[i].PosZ - vWall[i].Box:getDimY() if abs( dRotAng - 180) < GEO.EPS_ANG_SMALL or abs( dRotAng + 180) < GEO.EPS_ANG_SMALL then vWall[i].PosX = vWall[i].PosX - vWall[i].Box:getDimX() elseif abs( dRotAng - 270) < GEO.EPS_ANG_SMALL or abs( dRotAng + 90) < GEO.EPS_ANG_SMALL then vWall[i].PosX = vWall[i].PosX - vWall[i].Box:getDimX() end elseif abs( dInvAng - 180) < GEO.EPS_ANG_SMALL or abs( dInvAng + 180) < GEO.EPS_ANG_SMALL then vWall[i].PosX = vWall[i].PosX - vWall[i].Box:getDimX() if abs( dRotAng - 0) < GEO.EPS_ANG_SMALL then vWall[i].PosZ = vWall[i].PosZ - vWall[i].Box:getDimY() elseif abs( dRotAng - 270) < GEO.EPS_ANG_SMALL or abs( dRotAng + 90) < GEO.EPS_ANG_SMALL then vWall[i].PosZ = vWall[i].PosZ - vWall[i].Box:getDimY() elseif abs( dRotAng - 90) < GEO.EPS_ANG_SMALL or abs( dRotAng + 270) < GEO.EPS_ANG_SMALL then vWall[i].PosZ = vWall[i].PosZ - vWall[i].Box:getDimY() end elseif abs( dInvAng - 270) < GEO.EPS_ANG_SMALL or abs( dInvAng + 90) < GEO.EPS_ANG_SMALL then if abs( dRotAng - 0) < GEO.EPS_ANG_SMALL then vWall[i].PosX = vWall[i].PosX - vWall[i].Box:getDimX() end end end end -- Ne verifico le dimensioni local dRawH = vWall[1].Box:getDimZ() + vWall[1].PosY local vWallErr = {} for i = 2, #vWall do local dDimH = vWall[i].Box:getDimZ() + vWall[i].PosY if abs( dDimH - dRawH) > 100 * GEO.EPS_SMALL then table.insert( vWallErr, i) end end if #vWallErr > 0 then local sOut = 'Rimosse pareti con spessore diverso dalla prima :\n' for i = #vWallErr, 1, -1 do sOut = sOut .. vWall[vWallErr[i]].Name .. '\n' table.remove( vWall, vWallErr[i]) end WALL.ERR = 16 WALL.MSG = sOut WriteErrToLogFile( WALL.ERR, WALL.MSG) PostErrView( WALL.ERR, WALL.MSG) return end -- se impostato flag apposito, in vista il grezzo è uguale al pezzo if bProj and WD.DEFAULT_RAW_NO_EXTRA_WIDTH and #vWall == 1 then dRawL = vWall[1].Box:getDimX() dRawW = vWall[1].Box:getDimY() end -- Verifico dimensioni massime grezzo if dRawL > WD.MAX_LENGTH + 10 * GEO.EPS_SMALL or dRawW > WD.MAX_WIDTH + 10 * GEO.EPS_SMALL or dRawH > WD.MAX_HEIGHT + 10 * GEO.EPS_SMALL then local sOut = 'Grezzo (' .. EgtNumToString( dRawL, 2) .. ' x ' .. EgtNumToString( dRawW, 2) .. ' x ' .. EgtNumToString( dRawH, 2) .. ') ' .. 'oltre il limite della macchina ('..EgtNumToString( WD.MAX_LENGTH, 2)..' x '..EgtNumToString( WD.MAX_WIDTH, 2)..' x '..EgtNumToString( WD.MAX_HEIGHT, 2)..') ' WALL.ERR = 17 WALL.MSG = sOut WriteErrToLogFile( WALL.ERR, WALL.MSG) PostErrView( WALL.ERR, WALL.MSG) return end -- Verifico dimensioni minime del grezzo if dRawL < WD.MIN_LENGTH - 10 * GEO.EPS_SMALL or dRawW < WD.MIN_WIDTH - 10 * GEO.EPS_SMALL or dRawH < WD.MIN_HEIGHT - 10 * GEO.EPS_SMALL then local sOut = 'Grezzo (' .. EgtNumToString( dRawL, 2) .. ' x ' .. EgtNumToString( dRawW, 2) .. ' x ' .. EgtNumToString( dRawH, 2) .. ') ' .. 'sotto il limite della macchina ('..EgtNumToString( WD.MIN_LENGTH, 2)..' x '..EgtNumToString( WD.MIN_WIDTH, 2)..' x '..EgtNumToString( WD.MIN_HEIGHT, 2)..')' WALL.ERR = 17 WALL.MSG = sOut WriteErrToLogFile( WALL.ERR, WALL.MSG) PostErrView( WALL.ERR, WALL.MSG) return end -- Sistemo le pareti nel grezzo local bPbOk, sPbErr = WE.ProcessWalls( dRawL, dRawW, dRawH, vWall) if not bPbOk then WALL.ERR = 18 WALL.MSG = sPbErr WriteErrToLogFile( WALL.ERR, WALL.MSG) PostErrView( WALL.ERR, WALL.MSG) return end -- Se richiesto per la macchina, ruoto il grezzo di 180 gradi attorno a Z if WD.RAWPART_ROT and abs( WD.RAWPART_ROT - 180) < 1 then EgtRotateRawPart( EgtGetFirstRawPart() or GDB_ID.NULL, Z_AX(), 180) end -- Imposto Nome file CN local _, sName, _ = EgtSplitPath( WALL.FILE) EgtSetInfo( EgtGetCurrMachGroup(), 'NcName', sName .. '.cnc') -- Abilito Vmill EgtSetInfo( EgtGetCurrMachGroup(), 'Vm', '1') -- Lavoro le features local bPfOk, Stats = WE.ProcessFeatures() 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 WALL.ERR = 0 WALL.MSG = '---' WALL.ROT = Stats[i].Rot or 0 WALL.CUTID = Stats[i].CutId WALL.TASKID = Stats[i].TaskId WriteErrToLogFile( WALL.ERR, WALL.MSG, WALL.ROT, WALL.CUTID, WALL.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) WALL.ERR = 19 WALL.MSG = sMsg WALL.ROT = Stats[i].Rot or 0 WALL.CUTID = Stats[i].CutId WALL.TASKID = Stats[i].TaskId WriteErrToLogFile( WALL.ERR, WALL.MSG, WALL.ROT, WALL.CUTID, WALL.TASKID) elseif Stats[i].Err < 0 then nWarnCnt = nWarnCnt + 1 sOutput = sOutput .. string.format( '[%d,%d] %s\n', Stats[i].CutId, Stats[i].TaskId, sMsg) WALL.ERR = -19 WALL.MSG = sMsg WALL.ROT = Stats[i].Rot or 0 WALL.CUTID = Stats[i].CutId WALL.TASKID = Stats[i].TaskId WriteErrToLogFile( WALL.ERR, WALL.MSG, WALL.ROT, WALL.CUTID, WALL.TASKID) end end -- Salvo il progetto EgtSaveFile( sNgeFile) -- Se non ci sono errori o modalità modifica, salvo il file originale if nErrCnt == 0 or WALL.FLAG == 1 then EgtCopyFile( WALL.FILE, sDir..sTitle..'.ori'..sExt) end -- 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) -- Dichiaro nessun errore local nPartId = EgtGetFirstPart() while nPartId do local nCutId = EgtGetInfo( nPartId, 'CUTID') if nCutId then local LayerId = {} LayerId[1] = EgtGetFirstNameInGroup( nPartId, 'Outline') LayerId[2] = EgtGetFirstNameInGroup( nPartId, 'Processings') for nInd = 1, #LayerId do local nProcId = EgtGetFirstInGroup( LayerId[nInd] or GDB_ID.NULL) while nProcId do local bIsFea = EgtExistsInfo( nProcId, 'GRP') and EgtExistsInfo( nProcId, 'PRC') local nTaskId = EgtGetInfo( nProcId, 'TASKID') if bIsFea and nTaskId then WALL.ERR = 0 WALL.MSG = '---' WALL.ROT = 0 WALL.CUTID = nCutId WALL.TASKID = nTaskId WriteErrToLogFile( WALL.ERR, WALL.MSG, WALL.ROT, WALL.CUTID, WALL.TASKID) end nProcId = EgtGetNext( nProcId) end 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, 'WALL.FILE' è cambiato da un PC all'altro. Di conseguenza si deve aggiornare nome file che si andrà a generare. local _, sName, _ = EgtSplitPath( WALL.FILE) EgtSetInfo( EgtGetLastMachGroup(), 'NcName', sName .. '.cnc') -- Passo in modalità lavora EgtSetCurrMachGroup( EgtGetLastMachGroup()) -- Aggiorno posizione del grezzo if WE.MoveRaw() then bToRecalc = true end -- Se necessario eseguo aggiornamento con ricalcolo delle lavorazioni if bToRecalc or WALL.FLAG == 3 or WALL.FLAG == 4 then EgtOutLog( ' +++ Recalculating all dispositions and machinings >>>') EgtImportSetup() EgtApplyAllMachinings() -- copia del file btl originale (per dichiarare progetto ricalcolato) EgtCopyFile( WALL.FILE, sDir..sTitle..'.ori'..sExt) end -- Salvo il progetto EgtSaveFile( sNgeFile) end -- *** Eseguo simulazione con verifica collisione in cieco *** if ( WALL.FLAG == 0 and ( bToProcess or bToRecalc)) or WALL.FLAG == 3 or WALL.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 WALL.ERR = 19 WALL.MSG = 'Error starting simulation' elseif nErr == MCH_SHE.COLLISION then WALL.ERR = 22 WALL.MSG = 'Head-part collision' elseif nErr == MCH_SHE.OUTSTROKE then WALL.ERR = 23 WALL.MSG = 'Axis outstroke ' .. sErr elseif nErr == MCH_SHE.SPECIAL then WALL.ERR = 24 WALL.MSG = 'Special error ' .. sErr else WALL.ERR = 25 WALL.MSG = 'General failure (contact supplier)' end WALL.ROT = 0 WALL.CUTID = 0 WALL.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 WALL.CUTID = EgtGetVal( vItem[i], 'CUTID', 'i') or 0 elseif string.find( vItem[i], 'TASKID', 1, true) then WALL.TASKID = EgtGetVal( vItem[i], 'TASKID', 'i') or 0 end end WriteErrToLogFile( WALL.ERR, WALL.MSG, WALL.ROT, WALL.CUTID, WALL.TASKID) return end end -- *** Genero programma CN *** ( se richiesto) local bIsGenerationEnabled = ( EgtVerifyKeyOption( 110) == false) if bIsGenerationEnabled and ( WALL.FLAG == 0 or WALL.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 WALL.ERR = 20 local _, sName, _ = EgtSplitPath( WALL.FILE) WALL.MSG = 'Error generating NC part program : ' .. sName WriteErrToLogFile( WALL.ERR, WALL.MSG) PostErrView( WALL.ERR, WALL.MSG) return end end -- *** Eseguo stima tempi *** EgtOutLog( ' +++ Estimating T&L >>>') if not EgtEstimate( '', 'EgtCAM5 - ' .. sNgeFile) then WALL.ERR = 21 local _, sName, _ = EgtSplitPath( WALL.FILE) WALL.MSG = 'Error estimating production time : ' .. sName WriteErrToLogFile( WALL.ERR, WALL.MSG) PostErrView( WALL.ERR, WALL.MSG) return end local Ttot = EgtGetInfo( EgtGetCurrMachGroup(), 'Ttot') local sTime = 'Total Time = ' .. EgtNumToString( Ttot, 1) EgtOutLog( sTime) -- Se modalità Cloud, importo la nuvola di punti if WALL.FLAG == 5 then EgtOutLog( ' +++ Importing Point Cloud >>>') -- Creo gruppo Cloud nel gruppo di lavorazione local nMGrpId = EgtGetCurrMachGroup() local nCloudId = EgtGetFirstNameInGroup( nMGrpId or GDB_ID.NULL, 'Cloud') if nCloudId then EgtEmptyGroup( nCloudId) else nCloudId = EgtGroup( nMGrpId) EgtSetName( nCloudId, 'Cloud') end -- Recupero BBox della tavola local b3Tab = EgtGetTableArea() if not b3Tab or b3Tab:isEmpty() then WALL.ERR = 22 WALL.MSG = 'Machine table not found' return end -- Recupero i punti della nuvola local hFile = io.open( sPntFile, 'r') if not hFile then WALL.ERR = 23 WALL.MSG = 'Missing point cloud file' return end local vPoints = {} local sLine = hFile:read( '*l') while sLine do local vCoord = EgtSplitString( sLine, ' ') if vCoord and #vCoord >= 2 then local dX = tonumber( vCoord[1]) + b3Tab:getMax():getX() local dY = tonumber( vCoord[2]) + b3Tab:getMin():getY() local dZ = b3Tab:getMax():getZ() EgtOutLog( ' X='..EgtNumToString( dX, 3)..' Y='..EgtNumToString( dY, 3), 3) table.insert( vPoints, { dX, dY, dZ}) end sLine = hFile:read( '*l') end hFile:close() -- Inserisco la curva di contorno della nuvola local nClCrvId = EgtCurveCompoFromPoints( nCloudId, vPoints, GDB_RT.GLOB) if not nClCrvId then WALL.ERR = 24 WALL.MSG = 'Failed to create Point cloud Contour' return end EgtCloseCurveCompo( nClCrvId) EgtApproxCurve( nClCrvId, GDB_CA.LINES, 1.0) EgtSetColor( nClCrvId, 'RED') end -- Se modifica o simula, imposto la vista ISO 3d opportuna if WALL.FLAG == 1 or WALL.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( WD.SIMUL_VIEW_DIR or 2, 1), 4) EgtSetView( vView[nV], false) -- se cloud, imposto la vista TOP elseif WALL.FLAG == 5 then EgtSetView( SCE_VD.TOP, false) end -- Completamento senza errori e avvisi if nWarnCnt == 0 then WALL.ERR = 0 WALL.MSG = '---' WriteErrToLogFile( WALL.ERR, WALL.MSG) end -- Scrittura tempo totale stimato di lavorazione WriteTimeToLogFile( Ttot) EgtOutLog( ' +++ BatchProcess completed')