-- PanelSaw.lua by Egalware s.r.l. 2025/09/02 -- Creazione lista taglio e/o programmi di taglio per sezionatrici -- Intestazioni require( 'EgtBase') local PanelSaw = {} local function GetPanelList() local PanelList = {} local idMachGroup = EgtGetFirstMachGroup() local nMachGroupCount = EgtGetMachGroupCount() -- nessun MachGroup ossia nessun pannello: si esce subito if ( not idMachGroup) or ( nMachGroupCount == 0) then return nil end -- per ogni MachGroup si estraggono le informazioni del pannello for i = 1, nMachGroupCount do local vPartInfo = EgtSplitString( EgtGetInfo( idMachGroup, 'PART1', 's')) local idPart = vPartInfo[1] table.insert( PanelList, {}) PanelList[i].dLength = EgtGetInfo( idMachGroup, 'PANELLEN', 'd') PanelList[i].dWidth = EgtGetInfo( idMachGroup, 'PANELWIDTH', 'd') PanelList[i].dThickness = EgtGetInfo( idMachGroup, 'PANELHEIGHT', 'd') PanelList[i].sMaterialFullName = EgtGetInfo( idMachGroup, 'MATERIAL', 's') local vMaterialInfo = EgtSplitString( PanelList[i].sMaterialFullName, '-') PanelList[i].idMaterial = vMaterialInfo[1] PanelList[i].idProd = EgtGetInfo( idMachGroup, 'PRODID', 'i') PanelList[i].idPatt = EgtGetInfo( idMachGroup, 'PATTID', 'i') PanelList[i].nPdn = EgtGetInfo( idPart, 'PDN', 'i') PanelList[i].sName = EgtGetInfo( idPart, 'NAM', 's') -- in questa modalità ogni MachGroup è 1 pezzo, non esistono multipli -- TODO valutare se raggruppare i pannelli uguali per la cutting list PanelList[i].nQuantity = 1 idMachGroup = EgtGetNextMachGroup( idMachGroup) end return PanelList end local function GetSheetList() local SheetList = { { dLength = 2800, dWidth = 2070, dThickness = 8 }, { dLength = 2800, dWidth = 2070, dThickness = 18 } } return SheetList end local function GetProjectInfo() local ProjectInfo = {} local idBtlInfo = EgtGetFirstNameInGroup( GDB_ID.ROOT, 'BtlInfo') or GDB_ID.NULL ProjectInfo.sProjectName = EgtGetInfo( idBtlInfo, 'PROJECTNAME', 's') or '' return ProjectInfo end local function BuildCuttingList( PanelList, sOutputType) local LinesToWrite = {} local SheetList = GetSheetList() local ProjectInfo = GetProjectInfo() -- Casadei if sOutputType == 'Cutty' then -- Homag Optimat elseif sOutputType == 'Homag' then -- formato json generico else end return LinesToWrite end -- restituisce i pannelli raggruppati per coppia materiale-spessore univoca local function GroupByMaterial( PanelList) local PanelsGroupedByMaterial = {} for i = 1, #PanelList do local idMaterial = PanelList[i].idMaterial local dMaterialThickness = PanelList[i].dThickness -- si crea una chiave unica dalla coppia local key = idMaterial .. "_" .. tostring( dMaterialThickness) -- se la chiave non esiste già nella tabella, si crea if not PanelsGroupedByMaterial[key] then PanelsGroupedByMaterial[key] = {} end -- aggiunta del pezzo corrente al gruppo chiave corrispondente table.insert( PanelsGroupedByMaterial[key], PanelList[i]) end return PanelsGroupedByMaterial end function PanelSaw.GenerateCuttingList( sOutputType) local PanelList = GetPanelList() local PanelsGroupedByMaterial = GroupByMaterial( PanelList) for key, PanelListSingleMaterial in pairs( PanelsGroupedByMaterial) do if not sOutputType then sOutputType = 'json' end -- costruzione lista istruzioni local LinesToWrite = BuildCuttingList( PanelListSingleMaterial, sOutputType) -- scrittura file local sCurrentNgePath = EgtSplitPath( EgtGetCurrFilePath()) local sFilename = sCurrentNgePath .. 'CutList_' .. key .. '.' .. sOutputType local hFile, nFileErr = io.open( sFilename, 'w') if not hFile then EgtOutLog( 'Error creating cutting list : IO error ' .. tostring( nFileErr)) return false end hFile:write( table.concat( LinesToWrite, "\n")) hFile:close() end return end return PanelSaw