
! script name: vpksolids.d/vpkmakexyzhole
! var_solids: make a hole in a solid body at an xyz point

!A
!A NAME:
!A
!A 	Make XYZ Hole VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script makes a hole in a solid
!A
!B INSTRUCTIONS:
!B
!B 	HOLE DIAMETER: Enter the diameter of the hole to be constructed.
!B
!B 	FINISH DEPTH: Enter the depth of the hole to be constructed.
!B
!B 	INPUT ABS X,Y,Z: Enter the X,Y,Z coordinates of the hole.
!B 		NOTE: See XYZ INPUT OPTIONS.
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: xyz hole ")

DIM Answer$[256]
DIM Destination$[256]
DIM Body$[256]
DIM Center$[256]
DIM Dia_var$[256]
DIM Depth_var$[256]
DIM Angle_var$[256]

DEG

ActivateUndo
Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave
Stat= GLPlotOn

Stat=SetInputFormat("n4=","")
Diar=NamedVarVal("hole diameter",WsPointVars,0.0)
Stat=SetRadiusEquals(Diar/2)

Pick_body:!
Pkbody= WPKCurrentBody
IF NOT WPKIsEntity(Pkbody) THEN
        Stat=SetInputFormat("n4","")
        E1=WPKPickEntity("PICK BODY")
        IF (ExitScript(Destination$)) THEN Leave
        IF NOT WPKIsEntity(E1) THEN Pick_body
        Pkbody= WPKParentBody(E1)
END IF
Stat= EntityNameCheck(Pkbody,Body$)

Dia_ques:Dia=InputRadius("HOLE DIAMETER",WsDiaInput)
IF (ExitScript(Destination$)) THEN Leave
No_dia_var= LastVariableInput(Dia_var$)
C1= LastPickEnt
IF ValidGeometry(C1) THEN
        IF NOT ValidDependency(C1) THEN Dia_ques
        No_dia_var=0
        Stat= EntityNameCheck(C1,Dia_var$)
END IF
Diar=Dia

Depthr=NamedVarVal("hole depth",WsPointVars,0.0)
Stat=SetDepthEquals(Depthr)
Depth=InputDepth("FINISH DEPTH")
IF (ExitScript(Destination$)) THEN Leave
No_depth_var= LastVariableInput(Depth_var$)
Depthr=Depth

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Tip_angle)
Tip_angle=GetValue("TIP ANGLE",Answer$)
IF ExitScript(Destination$) THEN Leave
No_angle_var= LastVariableInput(Angle_var$)

Pick_point:Stat=SetInputFormat("n4=","")
Pc=XyzInput("LOCATION POINT",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Pc) THEN Pick_point
E1= LastPickEnt
Pick_para= LastPickPara
Pick_return= CurrPickReturn
IF NOT ValidDependency(E1) THEN
        E1= CopyEntity(Pc)
        Stat= EntityNameCheck(E1,Center$)
        Pc_created= WsTrue
ELSE
        Stat= EntityNameCheck(E1,Center$)
        Pc_created= WsFalse
END IF
Stat=SetLastPoint(Pc)
Stat= DeleteEntity(Pc)



WPKClearErrorFlag
RecordFunctionOn
Stat= RecordDescr("BODY: make hole")
SELECT Pick_return
CASE WsGeometryEnd
        Pc= ParameterReturnPt(Center$,Pick_para,WsGeometryEnd)
CASE WsGeometryMid
        Pc= ParameterReturnPt(Center$,Pick_para,WsGeometryMid)
CASE WsGeomCenter
        Pc= ParameterReturnPt(Center$,Pick_para,WsGeomCenter)
END SELECT
IF No_depth_var THEN
        V1= FreeParameter("Finish Depth",Depth)
ELSE
        V1= FreeParameter("Finish Depth",Depth_var$)
END IF
IF No_angle_var THEN
        V2= FreeParameter("Tip angle",Tip_angle)
ELSE
        V2= FreeParameter("Tip angle",Angle_var$)
END IF
PlotOff
IF No_dia_var THEN
        V3= FreeParameter("Hole diameter",Dia)
	V4= FreeParameter("Tip angle addon",ToolTipLength(V3,V2))
	H1=Hole(Pc,V3,V1,V2,V4)
ELSE
	V4= FreeParameter("Tip angle addon",ToolTipLength(Dia_var$,V2))
	H1=Hole(Pc,Dia_var$,V1,V2,V4)
END IF
Stat= WPKSubtractHoleGrp(Body$,H1)
Stat= WPKNameBody(Body$,Body$)
Stat= WPKSetBodyParent(Body$,1)
Stat= DeleteEntityList(Pc,H1)
PlotOn
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= WPKUpdateBody(Pkbody)

Stat= WPKSolidRecordOn(Curr_record)
ActivateUndo
Stat= AdvanceUndoNumber("make hole")
IF Pc_created THEN Stat= AddItemToUndo(WsUBCreateMode,Center$)
Stat= AddItemToUndo(WsUBPKSessionMark)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
WPKErrorCheck

GOTO Pick_point

Leave:!
PlotOn
Vdia=CreateVariable("hole diameter",WsPointVars,Diar)
Vdepth=CreateVariable("hole depth",WsPointVars,Depthr)

IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
