
! script name: v4axisturn.d/setsyncpoint
! var_topic: set a sync point on an element.

!A
!A NAME:
!A
!A	Set Sync Point VARIATIONAL
!A
!A DESCRIPTION:
!A
!A	Set a sync point on a entity.
!A
!B INSTRUCTIONS:
!B
!B	PICK PATH FOR SYNC POINTS: Pick the path that the 
!B				sync points are on.
!B
!B	PICK THE 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
!B	SYNC NUMBER:  Number assigned to sync point. For reference only.
!B		      The order of the sync points is determined by their
!B		      occurance along the contour.
!B
!C NOTE:
!C
!C	Sync points are locations on a contour which are used in
!C	four axis dual turret turning. The sync points are places 
!C	where the tool motion for each of the turrets are coordinated. 
!C	The contours for the two turrets must 
!C	have the same number of sync points. 
!C	Some sync points may be multiple at the same location when
!C	one of the turrets is to be stationary.
!C	The Sync numbers are for reference only. The actual numbers
!C	(if required) for the machine tool are generated by the turbo post.
!C
!C      This script is not set up to allow the Sync Number to be
!C      a variable. This may be done after the record is created by
!C      changing the free parameter into a variable.
!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: set sync point ")

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

Var_object=CheckVarObject
IF ExitScript(Destination$) THEN Leave

stat= SetInputFormat("n4","")
Stat=SetXyzInput(WsLatheInput)

Sync_number=1
Pen_color= 3


Pick_contour: !
ActivateUndo
Stat=SetInputFormat("n4","")
Contour=PickGroupEnt("PICK PATH FOR SYNC POINTS")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Contour) THEN Pick_contour
IF IsEntVariational(Contour)= WsFalse THEN
        Stat= MessageStringBox("Path must be variational","Error")
        GOTO Pick_contour
END IF

Stat= DeleteGroup(Syncpts,WsTrue)
Syncpts= ContourSyncPoints(Contour)
Stat= SetForceVisible(Syncpts,WsTrue)
Stat= SetColor(Syncpts,Pen_color)

Pick_entity: !
ActivateUndo
Stat=SetInputFormat("n4a1",",N,")
Element=PickEntity("PICK THE ENTITY THE SYNC POINT WILL BE ON   New contour",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$= "N" THEN 
	Stat= DeleteGroup(Syncpts,WsTrue)
	GOTO Pick_contour
END IF
IF NOT ValidDependency(Element) THEN Pick_entity
N1= ElementGrpNum(Contour,Element)
IF NOT N1 THEN
        Stat= MessageStringBox("Entity must be on path","Error")
        GOTO Pick_entity
END IF
Stat=EntityNameCheck(Element,Element$)

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(Element,Pt)
Stat= DeleteEntity(Pt)

Stat=SetEqualsValue(Sync_number)
Stat=SetInputFormat("n4=","")
Sync_number=GetValue("SYNC NUMBER",Answer$)
IF (ExitScript(Destination$)) THEN Leave

ActivateUndo
Stat= AdvanceUndoNumber("set sync pt")
Stat= AddItemToUndo(WsUBModifyMode,Element$)

RecordFunctionOn
Stat=RecordDescr("FOUR AXIS TURN: Set Sync Point")
V1=FreeParameter("Sync number",Sync_number)
V2=FreeParameter("Sync parameter",Sync_param)
Pt= ParameterPt(Element$,V2)
Stat= SetSyncPoint(Element$,Pt,V1)
Stat= DeleteEntity(Pt)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= AddItemToUndo(WsUBCreateMode,Curr_record)

Stat= DeleteGroup(Syncpts,WsTrue)
Syncpts= ContourSyncPoints(Contour)
Stat= SetForceVisible(Syncpts,WsTrue)
Stat= SetColor(Syncpts,Pen_color)

GOTO Pick_entity

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


