-- ManPrepMachGroups.lua by Egalware s.r.l. 2026/07/27 -- Creazione dei MachGroup del file già aperto in modalità manuale da EgtCAM5 -- Intestazioni require( 'EgtBase') _ENV = EgtProtectGlobal() EgtEnableDebug( false) -- Verifico che il progetto sia un serramento local nAreaId = EgtGetFirstNameInGroup( GDB_ID.ROOT, 'Area(Frame)') if not nAreaId then EgtOutBox( 'Caricare il progetto di una finestra', 'Prepara Macchinate - Window', 'INFO', 'OK') return end -- dati generali del progetto local sWinPath = EgtGetCurrFilePath() local sDir = EgtSplitPath( sWinPath) -- rimuovo eventuali macchinate già presenti local nMGrpId = EgtGetFirstMachGroup() while nMGrpId do local nCurrMGrpId = nMGrpId local sMGrpName = EgtGetMachGroupName( nMGrpId) nMGrpId = EgtGetNextMachGroup( nMGrpId) -- cancello eventuali file generati dalla macchinata local sMGrpFile = sDir .. sMGrpName .. '.bwe' if EgtExistsFile( sMGrpFile) then local nOrigCtx = EgtGetContext() local nCtx = EgtCreateContext() if nCtx and EgtOpenFile( sMGrpFile) then local nMgId = EgtGetFirstInGroup( EgtGetFirstNameInGroup( GDB_ID.ROOT, 'MachBase') or GDB_ID.NULL) if nMgId then local sNcName = EgtGetInfo( nMgId, 'NcName') if sNcName then local _, sSpecName, _ = EgtSplitPath( sNcName) local vFiles = EgtFindAllFiles( sDir .. sSpecName .. '*.*') or {} for i = 1, #vFiles do local sFileToErase = sDir .. vFiles[i] EgtEraseFile( sFileToErase) end end end end EgtDeleteContext( nCtx) EgtSetContext( nOrigCtx) end -- cancello tutti i file del direttorio con il nome della macchinata local vFiles = EgtFindAllFiles( sDir .. sMGrpName .. '.*') or {} for i = 1, #vFiles do local sFileToErase = sDir .. vFiles[i] EgtEraseFile( sFileToErase) end -- cancello la macchinata EgtRemoveMachGroup( nCurrMGrpId) end -- scrivo parametri di comando (OPT_TYPE = PIECE, WINDOW, FULL_LIST) _G.WIN = { MACHINELIST = { 'Saomad-Just3500'}, OPT_TYPE = 'WINDOW'} -- aggiungo le macchinate local bOk, sErr = pcall( dofile, EgtGetSourceDir() .. 'CAMAuto\\CreateMachGroups.lua') -- se errore, lo segnalo ed esco if not bOk then EgtOutBox( sErr, 'Prepara Macchinate - Window', 'OK', 'ERROR') return end -- salvo il file del serramento EgtSaveFile()