
! script name: v4axisturn.d/movesyncpts
! var_topic: move sync points

!A
!A NAME:
!A	
!A	Move sync points VARIATIONAL
!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
!C      This script is variational is should only be used on paths
!C      created variationally. Failure to do this will result in
!C      multiple occurances of the sync points.
!C
!# see also - htdocs/help.d/fouraxisturn.htm

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

DIM Answer$[256]
DIM Destination$[256]
DIM Contour$[256]
DIM Element1$[256]
DIM Element2$[256]
DEG

Var_object=CheckVarObject
IF ExitScript(Destination$) THEN Leave
stat= SetInputFormat("n4","")
Stat=SetXyzInput(WsLatheInput)

Pen_color= 3

ActivateUndo
Pick_contour: !
Stat=SetInputFormat("n4","")
Contour=PickGroupEnt("PICK PATH FOR SYNC POINTS")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(Contour) THEN Pick_contour
IF IsEntVariational(Contour)= WsFalse THEN
	Stat= MessageStringBox("Path must be variational","Error")
	GOTO Pick_contour
END IF
Stat=EntityNameCheck(Contour,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$
	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 NOT N 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
Stat=EntityNameCheck(Element2,Element2$)


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

Sync_param= IntParameter(Element2,Pt)
Stat= DeleteEntity(Pt)

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)

RecordFunctionOn
Stat=RecordDescr("FOUR AXIS TURN: move sync point")
V1= FreeParameter("Sync point #",N)
V2= FreeParameter("Sync parameter #",Sync_param)
V3= FreeParameter("Sync #",SyncPointNumber(Contour$,V1))
Stat= DeleteSyncPoint(Contour$,V1)
Pt= ParameterPt(Element2$,V2)
Stat= SetSyncPoint(Element2$,Pt,V3)
Stat= DeleteEntity(Pt)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= AddItemToUndo(WsUBCreateMode,Curr_record)

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


