-- 2019/09/23 18:30:00 -- Creazione di una punta a forare per legno -- Intestazioni require( 'EgtBase') _ENV = EgtProtectGlobal() EgtEnableDebug( false) require( "EgtDimension") -- Dati utensile : dichiarazione e valori standard local TOOL = {} TOOL.TOOLHOLDER = '' TOOL.TOTLEN = 110 TOOL.LEN = 80 TOOL.DIAM = 20 TOOL.MAXMAT = 40 TOOL.ERR = 0 _G.TOOL = TOOL function CreateTool() TOOL.ERR = 999 -- Parametri utensile local sFilePath = TOOL.TOOLHOLDER local dWDHeight = TOOL.TOTLEN local dWDCylHeight = TOOL.LEN local dWDDiameter = TOOL.DIAM local dMaxMat = TOOL.MAXMAT local dCutterHeight = dMaxMat local bWDType = true -- Parametri portautensile local dThHeight = 0 local dThDiam = 0 -- Progetto vuoto EgtNewFile() local Pz = GDB_ID.NULL -- Se richiesto inserisco porta utensile if sFilePath and sFilePath ~= "" then -- eseguo inserimento if not EgtInsertFile(sFilePath) then TOOL.ERR = 1 return end -- recupero altezza portautensile Pz = EgtGetFirstInGroup(GDB_ID.ROOT) dThHeight = EgtGetInfo( Pz, "H", "d") or 0 dThDiam = EgtGetInfo( Pz, "D", "d") or 0 -- Altrimenti creo pezzo e layer opportuni else -- Creo pezzo e layer Pz = EgtGroup(GDB_ID.ROOT) EgtGroup( Pz) -- altezza portautensile rimane nulla end -- Layer Pz = EgtGetFirstGroupInGroup(GDB_ID.ROOT) local WDLayer = EgtGetFirstInGroup( Pz) EgtSetName( WDLayer, 'SOLID') local QuoteLayer = EgtGroup( Pz) EgtSetName( QuoteLayer, 'AUX') EgtSetColor( QuoteLayer, BLACK()) if EgtGetBackground then local colTop, colBot = EgtGetBackground() if colTop and colBot then local nInt = colTop:getRed() + colTop:getGreen() + colTop:getBlue() + colBot:getRed() + colBot:getGreen() + colBot:getBlue() if nInt < 769 then EgtSetColor( QuoteLayer, WHITE()) end end end local dWDTipHeight = dWDHeight - dWDCylHeight if dWDTipHeight < 0 then TOOL.ERR = 2 return end local dNoCutHeight = dWDCylHeight - dMaxMat if dNoCutHeight < dThHeight then TOOL.ERR = 12 return end local ptP1 = Point3d( 0.5 * dWDDiameter, 0, 0) local ptP2 = Point3d( 0.5 * dWDDiameter, - dWDCylHeight, 0) local ptP3 = Point3d( 0, - dWDHeight, 0) local ptP4 = Point3d( - 0.5 * dWDDiameter, - dWDCylHeight, 0) if dNoCutHeight > 0.1 then local ptPM = Point3d( 0.5 * dWDDiameter, - dNoCutHeight, 0) local NoCutLine = EgtLine( WDLayer, ptP1, ptPM, GDB_RT.GRID) local NoCutSurf = EgtSurfTmByRevolve( WDLayer, NoCutLine, ORIG(), -Y_AX(), false, 0.05, GDB_RT.GRID) EgtSetColor( NoCutSurf, LGRAY()) EgtErase( NoCutLine) ptP1 = ptPM end local CutStemLine = EgtLine( WDLayer, ptP1, ptP2, GDB_RT.GRID) or GDB_ID.NULL local TipLine = EgtLine( WDLayer, ptP2, ptP3, GDB_RT.GRID) or GDB_ID.NULL local CutLine = EgtCurveCompo( WDLayer, { CutStemLine, TipLine}) or GDB_ID.NULL local CutSurf = EgtSurfTmByRevolve( WDLayer, CutLine, ORIG(), -Y_AX(), false, 0.05, GDB_RT.GRID) or GDB_ID.NULL EgtSetColor( CutSurf, Color3d( 224, 0, 0)) EgtErase( CutLine) local dLenVertArrow = 0.05 * dWDHeight local dLenHorArrow = 0.4 * dWDDiameter local dDistQuoteX = dWDTipHeight + dLenHorArrow + 10 local dDistQuoteY = max( dThDiam, dWDDiameter) / 2 + 10 local dTextSize = min( 15, max( 0.1 * dWDDiameter, 0.1 * dWDHeight)) local dTextDist = 5 local sLenTxt = EgtNumToString( EgtToUiUnits( dWDCylHeight),3) CreateLinearDimensionOnY( QuoteLayer, ORIG(), ptP4, sLenTxt, dTextSize, dDistQuoteY, dLenVertArrow, dTextDist, false, 'LEN', GDB_RT.GRID) local sLenTotTxt = EgtNumToString( EgtToUiUnits( dWDHeight),3) CreateLinearDimensionOnY( QuoteLayer, ORIG(), ptP3, sLenTotTxt, dTextSize, dDistQuoteY, dLenVertArrow, dTextDist, true, 'TOTLEN', GDB_RT.GRID) local sDiamTxt = EgtNumToString( EgtToUiUnits( dWDDiameter),3) CreateLinearDimensionOnX( QuoteLayer, ptP2, ptP4, sDiamTxt, dTextSize, dDistQuoteX, dLenHorArrow, dTextDist, false, 'DIAM', GDB_RT.GRID) TOOL.ERR = 0 end _G.CreateTool = CreateTool