
! script name: macros.d/groove
! EXAMPLE: create groove of specified length and width

!A
!A NAME:
!A
!A 	Groove
!A
!A DESCRIPTION:
!A
!A 	This script is a macro that creates a groove with specified
!A 	length and width referenced to a line.
!A
!B INSTRUCTIONS:
!B
!B 	GROOVE LENGTH: Enter the length of the groove to be created.
!B
!B 	GROOVE WIDTH: Enter the width of the groove to be created.
!B
!B 	PICK LINE: Pick the line that will be used for reference for
!B 		the groove.
!B
!B 	PICK LEFT/RIGHT OF LINE: Pick which side of the line the groove
!B 		should be created on.
!B
!B 	GROOVE START POINT ABS X,Y: Enter the X,Y coordinates for the
!B 		start point of the groove.  NOTE: See XYZ INPUT OPTIONS.
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: groove ")

DIM Destination$[256]
DIM Answer$[256]

DEG

DeActivateUndo
Chamfer_corners=1
Top_corner_rad=0.03
Bottom_rad=0.05
Chamfer_length=0.05

Groove_len=NamedVarVal("groove length",WsLatheVars,1.0)
Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Groove_len)
Groove_len=GetValue("GROOVE LENGTH ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
Vlength=CreateVariable("groove length",WsLatheVars,Groove_len)


Groove_width=NamedVarVal("groove width",WsLatheVars,0.5)
Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Groove_width)
Groove_width=GetValue("GROOVE WIDTH ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
Vwidth=CreateVariable("groove width",WsLatheVars,Groove_width)

Groove_loop:!
Stat=SetInputFormat("n4=","")

Start_line=PickSpecificEnt("PICK LINE",WsPickLines)
IF (ExitScript(Destination$)) THEN Leave
T1=LastPickPara
IF T1<0.5 THEN
	P1=ParameterPt(Start_line,0.0)
	P2=ParameterPt(Start_line,1.0)
ELSE
	P1=ParameterPt(Start_line,1.0)
	P2=ParameterPt(Start_line,0.0)
END IF
Base_line=LineTwoPoints(P1,P2,WsTRIMMED)

Pt=InputFreePoint("PICK LEFT/RIGHT OF LINE")
IF (ExitScript(Destination$)) THEN Leave

S1=PtLeftRight(Base_line,Pt)

Ps=XyzInput("GROOVE START POINT",WsXyOnly)
IF (ExitScript(Destination$)) THEN Leave

Groove_start=Intersect(Base_line,Ps,1)
Dist=Groove_width*S1

Norm_line1=NormalLine(Base_line,Groove_start,WsUNTRIMMED)
Bottom_line=Parallel(Base_line,Dist,WsUNTRIMMED)
Norm_line2=Parallel(Norm_line1,-Groove_len,WsUNTRIMMED)

Groove_end=Intersect(Base_line,Norm_line2,1)
Bottom_start=Intersect(Norm_line1,Bottom_line,1)
Bottom_end=Intersect(Norm_line2,Bottom_line,1)

IF Chamfer_corners THEN
	First=Type10(11,P1,Groove_start,Chamfer_length)
ELSE
	First=Type10(10,P1,Groove_start,Top_corner_rad)
END IF
Second=Type10(10,Groove_start,Bottom_start,Bottom_rad)
Stat=JoinTypes(First,Second)
Third=Type10(10,Bottom_start,Bottom_end,Bottom_rad)
Stat=JoinTypes(Second,Third)
IF Chamfer_corners THEN
	Fourth=Type10(11,Bottom_end,Groove_end,Chamfer_length)
ELSE
	Fourth=Type10(10,Bottom_end,Groove_end,Top_corner_rad)
END IF
Stat=JoinTypes(Third,Fourth)
Fifth=Type1(1,Groove_end,P2)
Stat=JoinTypes(Fourth,Fifth)
Stat=CloseType(First)


Stat=DeleteEntity(Base_line)
Stat=DeleteEntity(Norm_line1)
Stat=DeleteEntity(Norm_line2)
Stat=DeleteEntity(Bottom_line)
Stat=DeleteEntity(P1)
Stat=DeleteEntity(P2)
Stat=DeleteEntity(Pt)
Stat=DeleteEntity(Ps)
Stat=DeleteEntity(Groove_start)
Stat=DeleteEntity(Groove_end)
Stat=DeleteEntity(Bottom_start)
Stat=DeleteEntity(Bottom_end)
Stat=DeleteEntity(Start_line)

Stat=HighlightTypes(First,195)
Stat=UnLinkTypes(First)

GOTO Groove_loop

Leave:!

Stat=DeleteEntity(Base_line)
Stat=DeleteEntity(Norm_line1)
Stat=DeleteEntity(Norm_line2)
Stat=DeleteEntity(Bottom_line)
Stat=DeleteEntity(P1)
Stat=DeleteEntity(P2)
Stat=DeleteEntity(Pt)
Stat=DeleteEntity(Ps)
Stat=DeleteEntity(Groove_start)
Stat=DeleteEntity(Groove_end)
Stat=DeleteEntity(Bottom_start)
Stat=DeleteEntity(Bottom_end)
Stat=DeleteEntity(Start_line)

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