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

!A
!A NAME:
!A
!A 	Add Corner Chamfer
!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
Start:!
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:!
Stat=SetInputFormat("n4b","")
E1=PickEntity("PICK CORNER ON PROFILE")
IF (ExitScript(Destination$)) THEN
        IF Destination$= "BACKUP" THEN Start
        GOTO Leave
END IF
IF NOT ValidGeometry(E1) THEN Pick_loop
IF NOT ValidDependency(E1) THEN Pick_loop
Pick_para=LastPickPara
Pick_return=CurrPickReturn
Stat=EntityNameCheck(E1,Point$)

Contour= ParentGroup(E1)
IF NOT ValidDependency(Contour) THEN Pick_loop
Stat=EntityNameCheck(Contour,Contour$)

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
	 IF Destination$= "SCRIPTSTART" THEN Start
         IF Destination$= "BACKUP" THEN Start
	 LOAD Destination$
END IF
END
