
! script name: lathe.d/lthtoolinterfere
! topic: highlight lathe tool interference

!A
!A NAME:
!A
!A 	View (Lathe) Tool Interference
!A
!A DESCRIPTION:
!A
!A 	This script will highlight lathe tool interference.
!A
!B INSTRUCTIONS:
!B
!B 	PICK LATHE TOOL PATH: Pick the lathe tool path.
!B
!B 	PICK PART OUTLINE CONTOUR: Pick the part outline contour.
!B
!B			
!C NOTE:
!C
!C	This script checks for interference between the tool 
!C	moving along a cutter path and a contour or geometry group defining 
!C	the area on the part to be checked. If an intersection between
!C	the tool image and the part outline occurs a message box will
!C	appear and a point is placed at the point on the cutter path
!C	where the interference is detected. The function will only
!C	show the first interference point.
!C
!C	To insure that every finish cut does not automatically
!C	interfere, we have chosen to ignore interference which may
!C	occur close to the tool tip, or along the cutting edge of
!C	the tool. For example, if a cut is made with a negative
!C	finish allowance, interference will only be found if some
!C	part of the tool away from the cutting edge interferes.
!C	
!C	A reasonably accurate tool image is required for this routine
!C	to function.
!C	

stat=ChangeLabelStr("ScriptNameStatus","Function: Lathe Tool Interfere  ")

DIM Answer$[256]
DIM Destination$[256]
DIM Image_name$[256]
DEG

ActivateUndo
stat= SetInputFormat("n4","")
Active_workplane=0
Work=CurrentWorkplane
IF (ValidGeometry(Work)) THEN Active_workplane=1

Current_pen=CurrentColor
StdWorkplane

Error_color= 7

Pick_loop: !
Stat=SetPickMask(WsPickNoSurf)
Stat=SetInputFormat("n4","")
Element=PickEntity("PICK LATHE TOOL PATH")
IF (ExitScript(Destination$)) THEN Leave

Path= ParentGroup(Element,0)
IF NOT ValidGeometry(Path) THEN Pick_loop
Tool= GetAssocTool(Path)
IF NOT ValidGeometry(Tool) THEN 
	Tool= GetAssocTool(Element)
	IF NOT ValidGeometry(Tool) THEN Pick_loop
END IF


Stat=SetInputFormat("n4","")
Contour=PickGroupEnt("PICK PART OUTLINE CONTOUR")
IF (ExitScript(Destination$)) THEN Leave

Tool=GetAssocTool(Path)
P1= LthToolInterfere(Tool,Path,Contour)
IF ValidGeometry(P1) THEN 
	Stat= SetColor(P1,Error_color)
	Stat= PlotEntity(Path)
	Stat= PlotEntity(P1)

	ActivateUndo
	Stat= AdvanceUndoNumber("tool interfere point")
	Stat= AddItemToUndo(WsUBCreateMode,P1)
END IF

GOTO Pick_loop

Leave:!
IF Active_workplane THEN
	Stat=SetWorkplane(Work)
ELSE
	StdWorkplane
END IF
stat= SetInputFormat("n4","")
Stat=SetCurrentColor(Current_pen)
Stat=SetPickMask(WsPickGeometry)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
