
! script name: fouraxisturn.d/movesyncpts
! topic: move sync points

!A
!A NAME:
!A	
!A	Move sync points
!A
!A DESCRIPTION:
!A
!A	This script moves sync points on a four axis lathe machining path.
!A	Sync points are used to syncronize the motion of the two independent
!A	turrets on the lathe.
!A
!B INSTRUCTIONS:
!B
!B	PICK PATH FOR SYNC POINTS: Pick the path that the 
!B				sync points are on.
!B
!B	PICK SYNC POINT,  Show, New, Exit: Pick the Sync point to be
!B				moved. If an Undo/Redo is performed
!B				then Show will update the graphics.
!B				New selects a new lathe path.
!B				Exit will leave the script.
!B
!B	PICK THE PATH ENTITY THE SYNC POINT WILL BE ON: Pick the entity on the
!B			path on which the sync point will be placed. This
!B			entity must be on the same path as the rest of the
!B			sync points.
!B			
!B	SYNC POINT LOCATION: Input or pick the location of the sync point.
!B
!C NOTE:
!C
!C	Sync points are properties attached to the path entities. It is
!C	possible to have two Sync points on different entities but at
!C	the same physical location. This might occur if the sync point
!C	were located at a return point for some roughing cycle.
!C
!C	The sync points are always processed in the order that they
!C	appear along the contour. The number associated with the
!C	sync point does not change the processing order but is for
!C	reference only.
!C
!# see also - htdocs/help.d/fouraxisturn.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: Move sync points ")

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

stat= SetInputFormat("n4","")

Pen_color= 3

ActivateUndo
Pick_contour: !
Stat=SetInputFormat("n4","")
Contour=PickGroupEnt("PICK PATH FOR SYNC POINTS")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Contour) THEN Pick_contour

Stat= DeleteGroup(Syncpts,WsTrue)
Syncpts= ContourSyncPoints(Contour)
Stat= SetForceVisible(Syncpts,WsTrue)
Stat= SetColor(Syncpts,Pen_color)
IF NOT ValidGeometry(Syncpts) THEN Pick_contour

Pick_loop: !
ActivateUndo
Stat=SetInputFormat("a1",",S,E,N,")
Element1=PickEntity("PICK SYNC POINT TO BE MOVED, Show, New, Exit ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
SELECT Answer$
CASE "A" 
	Stat= DeleteGroup(Syncpts,WsTrue)
	ActivateUndo
	Stat= AdvanceUndoNumber("remove contour sync pts")
	Stat= AddGroupToUndo(WsUBModifyMode,Contour,1,WsTrue)

	Stat= RemoveSyncPoints(Contour)

	Syncpts= ContourSyncPoints(Contour)
	Stat= SetForceVisible(Syncpts,WsTrue)
	Stat= SetColor(Syncpts,Pen_color)
	GOTO Pick_contour
CASE "N"
	Stat= DeleteGroup(Syncpts,WsTrue)
	GOTO Pick_contour
CASE "E"
	GOTO Leave
CASE "S"
	Stat= DeleteGroup(Syncpts,WsTrue)
	Syncpts= ContourSyncPoints(Contour)
	Stat= SetForceVisible(Syncpts,WsTrue)
	Stat= SetColor(Syncpts,Pen_color)
	GOTO Pick_loop
END SELECT

PlotOff
T1= LastPickPara
P1= ParameterPt(Element1,T1)
N= ClosestSyncPtNum(Contour,P1,1)
Stat= DeleteEntity(P1)
PlotOn
IF N=0 THEN Pick_loop

Pick_entity:!
Stat=SetInputFormat("n4","")
Element2=PickEntity("PICK THE PATH ENTITY THE SYNC POINT WILL BE ON")
IF (ExitScript(Destination$)) THEN Leave

N1= ElementGrpNum(Contour,Element2)
IF NOT N1 THEN
        Stat= MessageStringBox("Entity must be on path","Error")
        GOTO Pick_entity
END IF


Pick_point:!
Stat=SetInputFormat("n4","")
Pt=XyzInput("SYNC POINT LOCATION",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Pt) THEN Pick_point


Element1= SyncPointEntity(Contour,N)
Sync_num= SyncPointNumber(Contour,N)
Stat= DeleteGroup(Syncpts,WsTrue)
ActivateUndo
Stat= AdvanceUndoNumber("Move sync pt")
Stat= AddItemToUndo(WsUBModifyMode,Element1)
Stat= AddItemToUndo(WsUBModifyMode,Element2)

Stat= DeleteSyncPoint(Contour,N)
Stat= SetSyncPoint(Element2,Pt,Sync_num)
Stat= DeleteEntity(Pt)

Stat= DeleteGroup(Syncpts,WsTrue)
Syncpts= ContourSyncPoints(Contour)
Stat= SetForceVisible(Syncpts,WsTrue)
IF NOT ValidGeometry(Syncpts) THEN Pick_contour
Stat= SetColor(Syncpts,Pen_color)
GOTO Pick_loop

Leave:!
PlotOn
Stat= DeleteEntity(Pt)
Stat= DeleteGroup(Syncpts,WsTrue)
stat= SetInputFormat("n4","")
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END


