
! script name: vlines.d/bvchntwopts
! var_topic: construct a bivector chain between two points

!A
!A NAME:
!A
!A 	BiVectorChain Two Points --- VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script constructs a bivector chain between two points.
!A	A bivector chain is a special entity that is used to create
!A	cutterpaths for five axis motion. Each point also has two
!A	vectors associated with in, usually a tangent vector and a
!A	vector which will represent the tool axis line.
!A
!B INSTRUCTIONS:
!B
!B 	FIRST POINT: Pick the starting point for the bivector chain.
!B
!B 	FIRST VECTOR HEAD: Pick the head of the first vector.
!B
!B 	SECOND POINT: Pick the second point.
!B
!B 	SECOND VECTOR HEAD: Pick the head of the second vector.
!B
!B NOTES:
!B
!B	Bivector chains created by this function may be linked into
!B	a contour and then used as leadin moves for five axis cuts.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: bivector chain two points ")

DIM Answer$[256]
DIM Point1$[256]
DIM Point2$[256]
DIM Point11$[256]
DIM Point21$[256]
DIM Name$[256]
DIM Destination$[256]
DEG

Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave

Tol=NamedVarVal("3D Cutting Tol",Ws3DSystemVars,0.005)

ActivateUndo
stat= SetInputFormat("n4","")
Line_loop:E1=PickEntity("FIRST POINT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E1) THEN Line_loop
Stat= EntityNameCheck(E1,Point1$)
T1= LastPickPara
Pick_return1= CurrPickReturn
Ps= ParameterReturnPt(E1,T1,Pick_return1)

Pick_head1:Stat=SetLastPoint(Ps)
E11=PickEntity("FIRST VECTOR HEAD")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E11) THEN Pick_head1
Stat= EntityNameCheck(E11,Point11$)
T11= LastPickPara
Pick_return11= CurrPickReturn

Pick_line2:Stat=SetLastPoint(Ps)
E2=PickEntity("SECOND POINT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E2) THEN Pick_line2
Stat= EntityNameCheck(E2,Point2$)
T2= LastPickPara
Pick_return2= CurrPickReturn
Pe= ParameterReturnPt(E2,T2,Pick_return2)

Pick_head2:Stat=SetLastPoint(Pe)
E21=PickEntity("SECOND VECTOR HEAD")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E21) THEN Pick_head2
Stat= EntityNameCheck(E21,Point21$)
T21= LastPickPara
Pick_return21= CurrPickReturn

Stat= DeleteEntity(Ps)
Stat= DeleteEntity(Pe)


Stat= GenerateVarName(WsBiVectorChainEnt,Name$)

RecordFunctionOn
Stat= RecordDescr("BVCHAIN: Two points")
Stat= SetRecDelLastExec
SELECT Pick_return1
CASE WsGeometryEnd
        Ps= ParameterReturnPt(Point1$,T1,WsGeometryEnd)
CASE WsGeometryMid
        Ps= ParameterReturnPt(Point1$,T1,WsGeometryMid)
CASE WsGeomCenter
        Ps= ParameterReturnPt(Point1$,T1,WsGeomCenter)
END SELECT
SELECT Pick_return11
CASE WsGeometryEnd
        Ps1= ParameterReturnPt(Point11$,T11,WsGeometryEnd)
CASE WsGeometryMid
        Ps1= ParameterReturnPt(Point11$,T11,WsGeometryMid)
CASE WsGeomCenter
        Ps1= ParameterReturnPt(Point11$,T11,WsGeomCenter)
END SELECT
SELECT Pick_return2
CASE WsGeometryEnd
        Pe= ParameterReturnPt(Point2$,T2,WsGeometryEnd)
CASE WsGeometryMid
        Pe= ParameterReturnPt(Point2$,T2,WsGeometryMid)
CASE WsGeomCenter
        Pe= ParameterReturnPt(Point2$,T2,WsGeomCenter)
END SELECT
SELECT Pick_return21
CASE WsGeometryEnd
        Pe1= ParameterReturnPt(Point21$,T21,WsGeometryEnd)
CASE WsGeometryMid
        Pe1= ParameterReturnPt(Point21$,T21,WsGeometryMid)
CASE WsGeomCenter
        Pe1= ParameterReturnPt(Point21$,T21,WsGeomCenter)
END SELECT
V1= FreeParameter("Interpolate", 1)
V2= FreeParameter("Tolerance", Tol)
Bv1=BiVectorChTwoPts(Ps,Ps1,Pe,Pe1,V1,V2)
Stat= NameEntity(Bv1,Name$)
Stat= DeleteEntityList(Ps,Pe,Ps1,Pe1)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= PlotEntity(Point1$)
Stat= PlotEntity(Point2$)
Stat= PlotEntity(Bv1)

ActivateUndo
Stat= AdvanceUndoNumber("bivector chain")
Stat= AddItemToUndo(WsUBCreateMode,Bv1)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
GOTO Line_loop

Leave:!
Stat= DeleteEntityList(Ps,Pe,Ps1,Pe1)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END

