
! script name: offsets.d/animatetool
! topic: animate tool along cutter path

!A
!A NAME:
!A
!A 	Animate Tool
!A
!A DESCRIPTION:
!A
!A 	This script animates a tool
!A 	tool along a defined cutter path.
!A
!B INSTRUCTIONS:
!B
!B 	PICK PATH: Pick the path that will have
!B 		the area of the tool animated.
!B
!C NOTE:
!C
!C	For lathe tool images it is assumed that the image is based off
!C	the theoretical tool tip.
!C

stat=ChangeLabelStr("ScriptNameStatus","Function: Animate tool ")

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

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

Current_pen=CurrentColor
StdWorkplane

Pick_loop: !
ActivateUndo
Stat=SetPickMask(WsPickAll)
Stat=SetInputFormat("n4","")
Element=PickEntity("PICK ENTITY IN PATH")
IF (ExitScript(Destination$)) THEN Leave
Path=ParentGroup(Element,0)
IF NOT ValidGeometry(Path) THEN 
	Etype= EntityType(Element)
	IF Etype<> WsCPathFileEnt AND Etype<> WsHoleEnt THEN Pick_loop
	Path_group= Element
	Path= Element
	GOTO Get_tool
END IF

Path_group=ParentGroup(Path,WsPathGroup)
IF NOT ValidGeometry(Path_group) THEN 
	Tool= GetAssocTool(Path)
	IF NOT ValidGeometry(Tool) THEN 
		Tool= GetAssocTool(Element)
		IF NOT ValidGeometry(Tool) THEN Pick_loop
	END IF
	Path_group= Path
	GOTO Animate_cutter
END IF

Get_tool:!
Tool= GetAssocTool(Path)
IF NOT ValidGeometry(Tool) THEN Pick_loop

Animate_cutter:!
Work_trans= CurrentWorkplane
Stat= AnimateTool(Tool,Path_group,Work_trans)
GOTO Pick_loop

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


