Files
egwwindowlua/ManCreateWindow.lua
Dario Sassi c8ec5c73ad Window 3.1h1 :
- aggiunta gestione flip pezzi per lavorare in prima fase interno invece di esterno
- aggiunta cancellazione di tutti i vecchi file risultato in modalità manuale.
2026-08-07 11:55:06 +02:00

99 lines
3.2 KiB
Lua

-- ManCreateWindow.lua by Egalware s.r.l. 2026/08/07
-- Creazione serramento 3d da descrizione JWD
require( 'EgtBase')
_ENV = EgtProtectGlobal()
EgtEnableDebug( false)
-- Imposto direttorio per librerie
local sBaseDir = EgtGetSourceDir() .. 'Designing\\'
EgtAddToPackagePath( sBaseDir .. '?.lua')
EgtAddToPackagePath( sBaseDir .. 'WinLib\\' .. '?.lua')
_G.package.loaded.WinConst = nil
_G.package.loaded.WinJWDConst = nil
_G.package.loaded.WinCreate = nil
_G.package.loaded.WinCalculate = nil
_G.package.loaded.WinManageProject = nil
_G.package.loaded.JSON = nil
_G.package.loaded.xml2lua = nil
_G.package.loaded.xml2lua_tree = nil
require( 'WinConst')
local WinManageProject = require( 'WinManageProject')
local WinCalculate = require( 'WinCalculate')
local sOpenFilePath = ''
-- verifico se lanciato file in batch per test
if WINDOW and WINDOW.FILE then
sOpenFilePath = WINDOW.FILE
-- oppure in interattivo
else
-- se voglio aprire ultima finestra generata
if EgtGetKeyPressed( GEN_VK.SHIFT) then
local sLastWinPath = EgtGetStringFromIni( 'Window', 'LastWin', '', EgtGetIniFile())
if not EgtExistsFile( sLastWinPath) then
EgtOutBox( 'Non esiste Finestra corrente', 'Crea Serramento - Window', 'INFO', 'OK')
return
end
EgtOpenFile( sLastWinPath)
EgtZoom( SCE_ZM.ALL)
return
-- altrimenti apro dialogo di scelta file JWD
else
local sOpenDirPath = 'C:\\EgtData\\EgtWindowMaker\\Projects\\*.jwd'
sOpenFilePath = EgtFileDialog( true, sOpenDirPath, "Window Project Files (*.jwd)|*.jwd||")
if not sOpenFilePath then
return
end
-- backup
local sDir, sName, sExt = EgtSplitPath( sOpenFilePath)
local sBackDir = sDir .. 'bak\\'
if EgtExistsDirectory( sBackDir) then
EgtEmptyDirectory( sBackDir)
else
EgtCreateDirectory( sBackDir)
end
local vFiles = EgtFindAllFiles( sDir .. '*.*') or {}
for i = 1, #vFiles do
local sFileToMove = sDir .. vFiles[i]
EgtRenameFile( sDir .. vFiles[i], sBackDir .. vFiles[i])
end
-- copio il file selezionato
EgtCopyFile( sBackDir .. sName .. sExt, sOpenFilePath)
end
end
EgtNewFile()
local sProfileDir = EgtGetStringFromIni( 'Window', 'ProfileDir', 'C:\\EgtData\\EgtWindowMaker\\Profiles', EgtGetIniFile())
if not WinManageProject.ReadFromFile( sOpenFilePath, sProfileDir) then
return
end
local sFilePath = EgtChangePathExtension( sOpenFilePath, 'nge')
EgtSetCurrFilePath( sFilePath)
-- imposto se calcolare i solidi o meno
WinCalculate.SetCalcSolid( true)
--WinCalculate.SetCalcPreview( true)
-- creo i pezzi
local nFrameId = EgtGetFirstNameInGroup( GDB_ID.ROOT, WIN_AREA .. '*')
WinCalculate.CreatePartFromArea( nFrameId)
WinCalculate.AddHardware( nFrameId, true, false, false, false)
WinCalculate.AddAccessories( nFrameId, true)
-- elimino profilo se in batch per test
if WINDOW and WINDOW.TEST == 1 then
local nProfileGroupId = EgtGetFirstNameInGroup( GDB_ID.ROOT, WIN_PROFILE)
if nProfileGroupId and nProfileGroupId ~= GDB_ID.NULL then
EgtErase( nProfileGroupId)
end
else
EgtSaveFile()
EgtZoom( SCE_ZM.ALL)
EgtWriteStringToIni( 'Window', 'LastWin', sFilePath, EgtGetIniFile())
end