
! script name: vconics.d/helixent
! var_topic: make a helix entity

!A
!A NAME:
!A
!A 	Helix		VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script defines a helix entity.
!A
!B INSTRUCTIONS:
!B
!B 	RADIUS OF HELIX: Enter the radius of
!B 		the helix to be constructed.
!B
!B 	CENTER POINT ABS X,Y: Enter the X,Y
!B 		coordinates of the center point of the helix.
!B 		NOTE: See XYZ INPUT OPTIONS.
!B
!B 	STARTING ANGLE: Enter the starting angle of the helix.
!B
!B 	ANGULAR EXTENT: Enter the total number of
!B 		degrees for the helix construction.
!B
!B 	Z START: Enter the Z coordinate of the
!B 		start point of the helix.
!B
!B 	Z END: Enter the Z coordinate of the
!B 		end point of the helix.
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: helix ")

DIM Answer$[256]
DIM Destination$[256]
DIM Name$[256]
DIM Center$[256]
DIM Destination$[256]
DIM Radius_var$[256]
DIM Start_angle$[256]
DIM Angle_var$[256]
DIM Zstart_var$[256]
DIM Zend_var$[256]
DEG

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

ActivateUndo
Start:!
Stat=SetInputFormat("n4","")

Radius=InputRadius("RADIUS OF HELIX")
IF (ExitScript(Destination$)) THEN Leave
No_radius_var= LastVariableInput(Radius_var$)
C1= LastPickEnt
IF ValidGeometry(C1) THEN
        IF NOT ValidDependency(C1) THEN Start
        No_radius_var=0
        Stat= EntityNameCheck(C1,Radius_var$)
END IF
Stat=SetEqualsValue(Radius)

Pick_point:Stat=SetInputFormat("n4=","")
E1=PickEntity("CENTER POINT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(E1) THEN Pick_point
IF NOT ValidDependency(E1) THEN Pick_point
Pick_para= LastPickPara
Pick_return= CurrPickReturn
Stat= EntityNameCheck(E1,Center$)
Pc= ParameterReturnPt(E1,Pick_para,Pick_return)
Stat=SetLastPoint(Pc)
Stat= DeleteEntity(Pc)

Astart=InputAngle("STARTING ANGLE")
IF (ExitScript(Destination$)) THEN Leave
No_astart_var= LastVariableInput(Start_angle$)
L1= LastPickEnt
IF ValidGeometry(L1) THEN
        IF NOT ValidDependency(L1) THEN Angle_ques
        Stat= EntityNameCheck(L1,Start_angle$)
        No_astart_var=0
END IF

Angle=InputAngle("ANGULAR EXTENT")
IF (ExitScript(Destination$)) THEN Leave
No_angle_var= LastVariableInput(Angle_var$)

Stat=SetPickReturn(WsGeometryZ)
Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Zstart)
Zstart=GetValue("Z START",Answer$)
IF (ExitScript(Destination$)) THEN Leave
Stat=SetPickReturn(WsGeometryEnd)
No_zstart_var= LastVariableInput(Zstart_var$)

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Zend)
Zend=GetValue("Z END",Answer$)
IF (ExitScript(Destination$)) THEN Leave
Stat=SetPickReturn(WsGeometryEnd)
No_zend_var= LastVariableInput(Zend_var$)



Stat= GenerateVarName(WsHelixEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("HELIX: Radius center")
Stat= SetRecDelLastExec
SELECT Pick_return
CASE WsGeometryEnd
        Pc= ParameterReturnPt(Center$,Pick_para,WsGeometryEnd)
CASE WsGeometryMid
        Pc= ParameterReturnPt(Center$,Pick_para,WsGeometryMid)
CASE WsGeomCenter
        Pc= ParameterReturnPt(Center$,Pick_para,WsGeomCenter)
END SELECT
IF No_radius_var THEN
        V1= FreeParameter("Radius",Radius)
ELSE
        V1= FreeParameter("Radius",Radius_var$)
END IF
IF No_astart_var THEN
        V2= FreeParameter("Astart",Astart)
ELSE
        V2= FreeParameter("Astart",Start_angle$)
END IF
IF No_angle_var THEN
        V3= FreeParameter("Angle",Angle)
ELSE
        V3= FreeParameter("Angle",Angle_var$)
END IF
IF No_zstart_var THEN
        V4= FreeParameter("Zstart",Zstart)
ELSE
        V4= FreeParameter("Zstart",Zstart_var$)
END IF
IF No_zend_var THEN
        V5= FreeParameter("Zend",Zend)
ELSE
        V5= FreeParameter("Zend",Zend_var$)
END IF
H1=Helix(Pc,V1,V1,V4,V5,V2,V3)
Stat= NameEntity(H1,Name$)
Stat= DeleteEntity(Pc)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

ActivateUndo
Stat= AdvanceUndoNumber("helix")
Stat= AddItemToUndo(WsUBCreateMode,H1)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)

GOTO Start


Leave:!
Stat=SetPickReturn(WsGeometryEnd)
Stat=SetInputFormat("n4","")
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END

