
! script name: vcontours.d/addcornerchmfr
! var_topic: add chamfer to contour corner

!A
!A NAME:
!A
!A 	Add Corner Chamfer	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script allows a corner chamfer on a contour to be changed.
!A
!B INSTRUCTIONS:
!B
!B 	PICK POINT TO DETERMINE CORNER: Pick a point
!B 		near the corner.
!B
!B 	CORNER CHAMFER: Input the chamfer to be
!B 		used on the corner.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: add corner chamfer")

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Contour$[256]
DIM Point$[256]
DIM Chamfer_var$[256]

Var_object=CheckVarObject
IF ExitScript(Destination$) THEN Leave

ActivateUndo
Chamfer_ques:!
Stat= SetInputFormat("n4=","")
Stat= SetEqualsValue(Chamfer)
Chamfer=GetValue("CORNER CHAMFER")
IF ExitScript(Destination$) THEN Leave
No_chamfer_var=LastVariableInput(Chamfer_var$)

Pick_loop:!

Pick_contour: !
Contour=PickGroupEnt("PICK CONTOUR ")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(Contour) THEN Pick_contour
Stat=EntityNameCheck(Contour,Contour$)
IF NOT IsEntVariational(Contour) THEN
   Stat=SetInputFormat("a99","")
   Stat= GetValue("NON-VDM ENTITY. CANNOT USE ON NON VDM ENTITY ",Answer$)
   Stat=SetInputFormat("n4","")
   GOTO Leave
END IF

Pick_loop:!
E1=PickEntity("PICK POINT TO DETERMINE CORNER")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidGeometry(E1) THEN Pick_loop
IF NOT ValidDependency(E1) THEN Pick_start
Pick_para=LastPickPara
Pick_return=CurrPickReturn
Stat=EntityNameCheck(E1,Point$)

ActivateUndo
Stat= AdvanceUndoNumber("add chamfer")
Stat= AddGroupToUndo(WsUBModifyMode,Contour$,1,WsTrue)


Stat=GenerateVarName(WsLineEnt,Name$)
RecordFunctionOn
Stat=RecordDescr("CONTOUR: Add corner chamfer ")
SELECT Pick_return
    CASE WsGeometryEnd
        Pt=ParameterReturnPt(Point$,Pick_para,WsGeometryEnd)
    CASE WsGeometryMid
        Pt=ParameterReturnPt(Point$,Pick_para,WsGeometryMid)
    CASE WsGeomCenter
        Pt=ParameterReturnPt(Point$,Pick_para,WsGeomCenter)
END SELECT
IF No_chamfer_var THEN
        V1=FreeParameter("Corner Chamfer",Chamfer)
ELSE
        V1=FreeParameter("Corner Chamfer",Chamfer_var$)
END IF
L1= AddCornerChamfer(Contour$,V1,Pt)
Stat=NameEntity(L1,Name$)
Stat=DeleteEntity(Pt)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= AddItemToUndo(WsUBCreateMode,L1)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
Stat= PlotEntity(Contour$)
GOTO Pick_loop

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