Files
3dprinting/LuaLibs/RunPartPositioning.lua
T
SaraP b9f1922969 3dPrinting :
- aggiunti setti.
2022-06-24 17:22:19 +02:00

146 lines
5.2 KiB
Lua

-- RunPartPositioning.lua by Egaltech s.r.l. 2022/05/28
-- Gestione calcolo disposizione e lavorazioni per stampa 3d
-- 2022/03/21 Creazione file
-- Tabella per definizione modulo
local RunPartPositioning = {}
-- Intestazioni
require( 'EgtBase')
EgtOutLog( ' RunPartPositioning started', 1)
-- Costanti generali
local AMD = require( 'AddManData')
function RunPartPositioning.Exec()
-- Verifico che la macchina corrente sia adatta alla stampa 3d
local sMachIni = EgtGetCurrMachineDir() .. '\\' .. EgtGetCurrMachineName() .. '.ini'
local sMachMaterial = EgtGetStringFromIni( 'General', 'Material', '', sMachIni)
if sMachMaterial ~= 'Additive' then
EgtOutBox( 'Current machine unsuitable for additive manufacturing', 'Warning', 'WARNING')
return
end
-- Recupero ultimo oggetto selezionato
local nPartId = EgtGetParent(EgtGetParent( EgtGetLastSelectedObj()))
-- verifico sia un pezzo valido
if nPartId then
local nParentId = EgtGetParent( nPartId)
while nParentId ~= GDB_ID.ROOT do
nPartId = nParentId
nParentId = EgtGetParent( nPartId)
end
if EgtIsPart( nPartId) then
local sName = EgtGetName( nPartId)
if sName == TABLE then
EgtOutBox( 'No selected part. Please select a part before moving it on the table.', 'Warning', 'WARNING')
return
end
else
EgtOutBox( 'No selected part. Please select a part before moving it on the table.', 'Warning', 'WARNING')
return
end
else
EgtOutBox( 'No selected part. Please select a part before moving it on the table.', 'Warning', 'WARNING')
return
end
-- gli assegno nome pezzo e layer
if not EgtGetName( nPartId) then
local nPartIndex = 1
while EgtGetFirstNameInGroup( GDB_ID.ROOT, PART .. nPartIndex) do
nPartIndex = nPartIndex + 1
end
EgtSetName( nPartId, PART .. nPartIndex)
local nLayerId = EgtGetFirstInGroup( nPartId)
EgtSetName( nLayerId, ORIGINAL_SOLID)
end
local nMchGrpId = EgtGetMachGroupId( '3dPrint')
EgtRemoveMachGroup( nMchGrpId or GDB_ID.NULL)
-- Rimuovo eventuale frame
local nFrameId = EgtGetFirstNameInGroup( nPartId, FRAME_PART)
if nFrameId then EgtErase( nFrameId) end
-- rimuovo eventuale start point
local nPtStartId = EgtGetFirstNameInGroup( nPartId, KEY_START_POINT)
if nPtStartId then EgtErase( nPtStartId) end
-- Recupero dati tavola (creando gruppo di lavoro temporaneo)
local nQqqId = EgtAddMachGroup( 'qqq')
EgtSetTable( 'Tab')
local b3Tab = EgtGetTableArea()
dTabX = b3Tab:getDimX()
dTabY = b3Tab:getDimY()
EgtRemoveMachGroup( nQqqId or GDB_ID.NULL)
-- Richiedo coordinata posizionamento pezzo
local b3Part = EgtGetBBoxGlob( nPartId, GDB_BB.EXACT)
local dPosX = b3Tab:getDimX() / 2
local dPosY = b3Tab:getDimY() / 2
local Positions = EgtDialogBox( 'Part position on table:', { 'X', EgtNumToString( EgtToUiUnits(dPosX), 1)}, { 'Y', EgtNumToString( EgtToUiUnits(dPosY), 1)})
if not Positions then return end
dPosX = EgtFromUiUnits( tonumber( Positions[1])) - b3Part:getDimX() / 2
dPosY = EgtFromUiUnits( tonumber( Positions[2])) - b3Part:getDimY() / 2
-- Creo disegno tavola
local nTabPart = EgtGetFirstNameInGroup( GDB_ID.ROOT, TABLE)
if not nTabPart then
-- Disegno tavola
nTabPart = EgtGroup( GDB_ID.ROOT)
EgtSetMode( nTabPart, GDB_MD.LOCKED)
EgtSetName( nTabPart, TABLE)
local nTabLayer = EgtGroup( nTabPart)
EgtSetName( nTabLayer, TABLE)
local nTabOutlineId = EgtRectangle2P( nTabLayer, Point3d( 0, 0, 0), Point3d( dTabX, dTabY, 0))
EgtSetName( nTabOutlineId, TABLE_OUTLINE)
local nTabSurfId = EgtSurfFlatRegion( nTabLayer, nTabOutlineId)
EgtSetName( nTabSurfId, TABLE_SURFACE)
EgtSetColor( nTabSurfId, 'GRAY')
EgtSetAlpha( nTabSurfId, 70)
end
-- Posiziono il pezzo e aggiorno il suo box
local vtMove = Point3d( dPosX, dPosY, 0) - b3Part:getMin()
EgtMove( nPartId, vtMove)
b3Part:move( vtMove)
-- Posiziono eventuali setti
local nSettiPart = EgtGetFirstNameInGroup( GDB_ID.ROOT, SETTI_GRP)
if nSettiPart then
EgtMove( nSettiPart, vtMove)
end
-- Creo il frame del pezzo
local frPart = Frame3d( b3Part:getCenter() - 0.5 * b3Part:getDimZ() * Z_AX(), Z_AX())
nFrameId = EgtFrame( nPartId, frPart, GDB_RT.GLOB)
if nFrameId then
EgtSetName( nFrameId, FRAME_PART)
EgtSetMode( nFrameId, GDB_MD.LOCKED)
end
EgtAddMachGroup( '3dPrint')
EgtSetTable( 'Tab')
local nRawId = EgtAddRawPartWithPart( nPartId, GDB_ID.NULL, 0, Color3d( 128, 128, 128, 30))
EgtMoveToCornerRawPart( nRawId, Point3d( dPosX, dPosY, 0), MCH_CR.BL)
EgtResetCurrMachGroup()
-- creo lo start point
local ptStart = b3Part:getCenter() - 0.6 * b3Part:getDimY() * Y_AX() - 0.5 * b3Part:getDimZ() * Z_AX()
nPtStartId = EgtPoint( nPartId, ptStart, GDB_RT.GLOB)
if nPtStartId then
EgtSetName( nPtStartId, KEY_START_POINT)
EgtSetColor( nPtStartId, EgtStdColor( "RED"))
end
EgtSetView( SCE_VD.ISO_SW, false)
EgtZoom( SCE_ZM.ALL)
EgtOutLog( ' +++ RunPartPositioning completed')
end
---------------------------------------------------------------------
return RunPartPositioning