
! script name: pksolids.d/makexyzhole
! solids: make a hole in a solid body at an xyz point

!A
!A NAME:
!A
!A 	Make XYZ Hole
!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]

DEG

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

Stat= GLPlot
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

Dia=InputRadius("HOLE DIAMETER",WsDiaInput)
IF (ExitScript(Destination$)) THEN Leave
Diar=Dia

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

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

Ploop:Pt=XyzInput("INPUT",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave

PlotOff
Add_on= ToolTipLength(Dia,Tip_angle)
H1=Hole(Pt,Dia,Depth,Tip_angle,Add_on)
Stat=SetLastPoint(Pt,WsXyzInput)
Stat=DeleteEntity(Pt)
Stat= WPKSubtractHoleGrp(Pkbody,H1)
Stat=DeleteEntity(H1)
PlotOn
Stat= WPKUpdateBody(Pkbody)


ActivateUndo
Stat= AdvanceUndoNumber("make hole")
Stat= AddItemToUndo(WsUBPKSessionMark)
WPKErrorCheck
GOTO Ploop

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

Stat=DeleteEntity(Pt)
Stat=DeleteEntity(H1)
Stat=DeleteEntity(G1)

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