DataWall :
- correzione lav. tasche con pulitura angoli interni - modifiche per nuova interfaccia - aggiunta script per nesting.
This commit is contained in:
+277
@@ -0,0 +1,277 @@
|
||||
-- NestProcess.lua by Egaltech s.r.l. 2021/02/13
|
||||
-- Gestione nesting automatico pareti
|
||||
|
||||
-- Intestazioni
|
||||
require( 'EgtBase')
|
||||
_ENV = EgtProtectGlobal()
|
||||
EgtEnableDebug( true)
|
||||
|
||||
-- Per test
|
||||
--NEST = {}
|
||||
--NEST.FILE = 'c:\\TechnoEssetre7\\EgtData\\Prods\\0010\\Bar_10_1.btl'
|
||||
--NEST.MACHINE = 'Essetre-90480019_MW'
|
||||
--NEST.FLAG = 3
|
||||
|
||||
local sLog = 'BatchProcess : ' .. NEST.FILE .. ', ' .. NEST.MACHINE .. ', ' .. NEST.PANELLEN .. ', ' .. NEST.PANELWIDTH
|
||||
EgtOutLog( sLog)
|
||||
|
||||
-- Cancello file di log specifico
|
||||
local sLogFile = EgtChangePathExtension( NEST.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 ( NEST.FLAG == 1 or NEST.FLAG == 2 or NEST.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 ( NEST.FLAG == 1 or NEST.FLAG == 2 or NEST.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
|
||||
-- Se definito LOAD90, aggiorno
|
||||
local sLoad90 = EgtGetStringFromIni( 'AuxData', 'LOAD90', '', sAuxFile)
|
||||
if sLoad90 ~= '' then
|
||||
local BtlInfoId = EgtGetFirstNameInGroup( GDB_ID.ROOT, 'BtlInfo') or GDB_ID.NULL
|
||||
EgtSetInfo( BtlInfoId, 'LOAD90', sLoad90)
|
||||
bModif = true
|
||||
end
|
||||
return bModif
|
||||
end
|
||||
|
||||
-- Funzione per trovare nome MachGroup
|
||||
local function NewMachGroupName()
|
||||
local nMachGroupId = EgtGetFirstMachGroup()
|
||||
if not nMachGroupId then return 1 end
|
||||
local nMaxMachGroup = 0
|
||||
while nMachGroupId do
|
||||
sMachGroupName = EgtGetMachGroupName(nMachGroupId)
|
||||
local nMachGroupName = tonumber(sMachGroupName)
|
||||
if nMachGroupName > nMaxMachGroup then
|
||||
nMaxMachGroup = nMachGroupName
|
||||
end
|
||||
nMachGroupId = EgtGetNextMachGroup(nMachGroupId)
|
||||
end
|
||||
return nMaxMachGroup + 1
|
||||
end
|
||||
|
||||
-- Imposto direttorio libreria specializzata per Travi
|
||||
local sBaseDir = EgtGetSourceDir()
|
||||
EgtAddToPackagePath( sBaseDir .. 'LuaLibs\\?.lua')
|
||||
|
||||
-- Inizializzo contatori errori e avvisi
|
||||
local nErrCnt = 0
|
||||
local nWarnCnt = 0
|
||||
|
||||
-- inizio nesting automatico
|
||||
EgtAutoNestStart()
|
||||
|
||||
local OUTLINE = "Outline"
|
||||
-- creo pannello del materiale
|
||||
local SheetPartId = EgtGroup(GDB_ID.ROOT)
|
||||
EgtSetName(SheetPartId, "Sheet")
|
||||
local SheetLayerId = EgtGroup(SheetPartId)
|
||||
EgtSetName(SheetLayerId, OUTLINE)
|
||||
local SheetOutlineId = EgtRectangle2P(SheetLayerId, Point3d(0,0,0), Point3d(NEST.PANELLEN, NEST.PANELWIDTH, 0), GDB_RT.GLOB)
|
||||
-- EgtModifyCurveThickness(SheetOutlineId, -Material.T_mm)
|
||||
EgtSetName(SheetOutlineId, OUTLINE)
|
||||
|
||||
-- creo foglio per nesting
|
||||
EgtAutoNestAddSheet( SheetPartId, SheetOutlineId, 20, 0, 50) -- EgtAutoNestAddSheet( SheetId, OutlineId, dKerf, nPriority, nCount)
|
||||
|
||||
-- ciclo su pezzi per aggiungerli al nesting
|
||||
for nPartId, nCount in pairs( PART) do
|
||||
local nOutlineLayer = EgtGetFirstNameInGroup(nPartId, "Outline")
|
||||
local nOutline = GDB_ID.NULL
|
||||
local nTrimesh = GDB_ID.NULL
|
||||
local bFirst = true
|
||||
local bSecond = false
|
||||
local bUseBox = false
|
||||
nTrimesh = EgtGetFirstNameInGroup( nOutlineLayer, "1-Out")
|
||||
if not nTrimesh then
|
||||
nTrimesh = EgtGetFirstNameInGroup( nOutlineLayer, "2-Out")
|
||||
end
|
||||
if not nTrimesh then
|
||||
nTrimesh = EgtGetFirstNameInGroup( nOutlineLayer, "3-Out")
|
||||
end
|
||||
if not nTrimesh then
|
||||
nTrimesh = EgtGetFirstNameInGroup( nOutlineLayer, "4-Out")
|
||||
end
|
||||
local nAuxId = EgtGetInfo(nTrimesh, "AUXID", 'i')
|
||||
nOutline = nTrimesh + nAuxId
|
||||
|
||||
|
||||
-- local nIndex = EgtGetFirstInGroup(nOutlineLayer)
|
||||
-- while nIndex do
|
||||
-- local nType = EgtGetType(nIndex)
|
||||
-- if nType == GDB_TY.CRV_COMPO then
|
||||
-- nOutline = nIndex
|
||||
-- if bFirst then
|
||||
-- bFirst = false
|
||||
-- else
|
||||
-- bSecond = true
|
||||
-- end
|
||||
-- elseif nType == GDB_TY.SRF_MESH then
|
||||
-- nTrimesh = nIndex
|
||||
-- end
|
||||
-- nIndex = EgtGetNext(nIndex)
|
||||
-- end
|
||||
-- se c'è solo una compo verifico se ha lati inclinati
|
||||
-- if not bSecond then
|
||||
local nFacetCount = EgtSurfTmFacetCount(nTrimesh)
|
||||
for nIndex = 0, nFacetCount - 1 do
|
||||
local vtNorm = EgtSurfTmFacetNormVersor(nTrimesh, nIndex, GDB_ID.ROOT)
|
||||
if abs( vtNorm:getZ()) > 10 * GEO.EPS_SMALL then
|
||||
bUseBox = true
|
||||
break
|
||||
end
|
||||
end
|
||||
-- else
|
||||
-- bUseBox = true
|
||||
-- end
|
||||
-- se due compo o una e lati inclinati
|
||||
if bUseBox then
|
||||
-- calcolo box della trimesh
|
||||
local b3Outline = EgtGetBBoxGlob(nTrimesh, GDB_BB.IGNORE_TEXT)
|
||||
local ptP1 = Point3d( b3Outline:getMin():getX(), b3Outline:getMin():getY(), 0)
|
||||
local ptP2 = Point3d( b3Outline:getMax():getX(), b3Outline:getMax():getY(), 0)
|
||||
-- creo outline del box
|
||||
nOutline = EgtRectangle2P(nOutlineLayer, ptP1, ptP2, GDB_RT.GLOB)
|
||||
EgtSetStatus(nOutline, GDB_ST.OFF)
|
||||
end
|
||||
if nOutline then
|
||||
-- aggiungo pezzo al nesting
|
||||
EgtAutoNestAddPart( nPartId, nOutline, false, true, 90, 0, nCount)
|
||||
-- EgtAutoNestAddPart( PartId, OutlineId, bCanFlip, bCanRotate, dRotStep, nPriority, nCount)
|
||||
end
|
||||
end
|
||||
|
||||
-- aggiungo offset tra pezzi
|
||||
EgtAutoNestSetInterpartGap(50)
|
||||
|
||||
-- Impostazione corner di inizio del nesting (NST_CORNER.BL, TL, BR, TR)
|
||||
EgtAutoNestSetStartCorner( NST_CORNER.BR)
|
||||
|
||||
local nMaxTime = 5
|
||||
-- imposto tempo di nesting e lo avvio
|
||||
EgtAutoNestCompute(true, nMaxTime)
|
||||
|
||||
-- Variabili di calcolo
|
||||
local nNestedParts, nParts, nSheets, nNestings, dTotFillRatio
|
||||
-- Attesa fine calcolo
|
||||
local bOk = true
|
||||
local nTime = 0
|
||||
while bOk do
|
||||
bOk, nStat = EgtAutoNestGetComputationStatus()
|
||||
if nStat == 2 or nStat == 3 then
|
||||
nNestedParts, nParts, nSheets, nNestings, dTotFillRatio = EgtAutoNestGetResults()
|
||||
--EgtOutText( string.format( 'Parts : %d/%d Filling : %.2f%%', nNestedParts, nParts, 100 * dTotFillRatio))
|
||||
end
|
||||
if nStat == 3 then break end
|
||||
nTime = nTime + 1
|
||||
if EgtProcessEvents( nTime / nMaxTime * 100, 995) == 1 then
|
||||
bOk = EgtAutoNestCancelComputation()
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
-- se nesting andato bene
|
||||
if bOk then
|
||||
|
||||
-- disposizione sheet e parts
|
||||
local SheetId = GDB_ID.NULL
|
||||
local vtAdd = V_NULL()
|
||||
local nMachGroup = GDB_ID.NULL
|
||||
local nPartCount = 0
|
||||
local Sheet = {PartList = {}}
|
||||
local bFirstSheet = true
|
||||
for i = 0, 999 do
|
||||
local nType, nId, nFlag, dX, dY, dAngRot = EgtAutoNestGetOneResult( i)
|
||||
if not nType then break end
|
||||
-- se sheet
|
||||
if nType > 0 then
|
||||
-- creo gruppo di lavorazione
|
||||
local MachGroupName = NewMachGroupName()
|
||||
nMachGroup = EgtAddMachGroup(MachGroupName, sCurrMachName)
|
||||
EgtSetInfo(nMachGroup, "PANELLEN", NEST.PANELLEN)
|
||||
EgtSetInfo(nMachGroup, "PANELWIDTH", NEST.PANELWIDTH)
|
||||
EgtSetInfo(nMachGroup, "AUTONEST", 1)
|
||||
nPartCount = 0
|
||||
-- altrimenti pezzo
|
||||
else
|
||||
local PartId = nId
|
||||
nPartCount = nPartCount + 1
|
||||
-- if nFlag ~= 0 then
|
||||
-- EgtMirror( PartId, ORIG(), Y_AX(), GDB_RT.GLOB)
|
||||
-- end
|
||||
-- EgtRotate( PartId, ORIG(), Z_AX(), dAngRot, GDB_RT.GLOB)
|
||||
-- EgtMove( PartId, Vector3d( dX, dY, 0) + vtAdd, GDB_RT.GLOB)
|
||||
-- se c'e' un grezzo valido
|
||||
if nMachGroup and nMachGroup ~= GDB_ID.NULL then
|
||||
-- creo pezzo copia
|
||||
local nPartDuploId = EgtDuploNew(nId)
|
||||
EgtRotate( nPartDuploId, ORIG(), Z_AX(), dAngRot, GDB_RT.GLOB)
|
||||
EgtMove( nPartDuploId, Vector3d( dX, dY, 0), GDB_RT.GLOB)
|
||||
local PartBBox = EgtGetBBoxGlob(nPartDuploId, GDB_BB.STANDARD)
|
||||
-- local ptPos = Point3d(PartBBox:getMin():getX(), PartBBox:getMin():getY(), 0)
|
||||
EgtSetInfo(nMachGroup, "PART" .. nPartCount, nPartDuploId .. "," .. PartBBox:getMin():getX() .. "," .. PartBBox:getMin():getY().. "," .. 0 .. "," .. 0)
|
||||
-- EgtSetInfo(nMachGroup, "PART" .. nPartCount, nId .. "," .. 10 .. "," .. 10 .. "," .. 0 .. "," .. 0)
|
||||
|
||||
-- local PartBBox = EgtGetBBoxGlob(PartId, GDB_BB.STANDARD)
|
||||
-- local ptPos = Point3d(PartBBox:getMin():getX(), PartBBox:getMin():getY(), 0)
|
||||
-- local bOk = EgtAddPartToRawPart(PartId, ptPos, nRawId)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- creo grezzi per ogni gruppo di lavorazione
|
||||
_G.WALL = {}
|
||||
WALL.FILE = NEST.FILE
|
||||
WALL.MACHINE = NEST.MACHINE
|
||||
WALL.FLAG = 6 -- CREATE_PANEL
|
||||
nMachGroup = EgtGetFirstMachGroup()
|
||||
while nMachGroup do
|
||||
EgtSetCurrMachGroup(nMachGroup)
|
||||
if EgtGetInfo(nMachGroup, "AUTONEST",'i') == 1 then
|
||||
EgtSetInfo(nMachGroup, "AUTONEST", "")
|
||||
dofile(EgtGetSourceDir() .. "BatchProcessNew.lua")
|
||||
end
|
||||
nMachGroup = EgtGetNextMachGroup(nMachGroup)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
EgtResetCurrMachGroup()
|
||||
-- nascondo rettangolo
|
||||
EgtErase(SheetPartId)
|
||||
-- EgtSaveFile("c:\\Temp\\Prova1.nge")
|
||||
|
||||
EgtOutLog( ' +++ NestProcess completed')
|
||||
Reference in New Issue
Block a user