-- RunPartPositioning.lua by Egaltech s.r.l. 2022/04/11 -- 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() -- 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 -- 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) --EgtSetLevel( nTabPart, GDB_LV.SYSTEM) 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, 'ORANGE') EgtSetAlpha( nTabSurfId, 70) end -- Posiziono il pezzo EgtMove( nPartId, Point3d( dPosX, dPosY, 0) - b3Part:getMin()) local nMchGrpId = EgtGetMachGroupId( '3dPrint') EgtRemoveMachGroup( nMchGrpId or GDB_ID.NULL) 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() EgtSetView( SCE_VD.ISO_SW, false) EgtZoom( SCE_ZM.ALL) EgtOutLog( ' +++ PlacePart completed') end --------------------------------------------------------------------- return RunPartPositioning