
! script name: vpksolids.d/vpkchamfersharpfaceedges
! var_solids: chamfer sharp edges on a face

!A
!A NAME:
!A
!A 	Chamfer Sharp Edges On a Face   VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script chamfers sharp edges on a face.
!A
!B INSTRUCTIONS:
!B
!B	PICK FACE: Pick the face.
!B
!B
!C NOTE:
!C
!C      It may be possible that some chamfers which do not work properly
!C      when in propagate mode will work if each individual edge is
!C      selected and then are collectively fixed.
!C
!# see also - htdocs/help.d/parasolids.htm


stat=ChangeLabelStr("ScriptNameStatus","Function: chamfer sharp face edges ")

OPTION BASE 1
DIM Destination$[256]
DIM Answer$[256]
DIM Body$[256]
DIM Face$[256]
DIM Chamfer_var$[256]


Start_color= 3
End_color= 4
Pick_color= 2

Chamfer_len=NamedVarVal("solid chamfer length",WsPKSolidsVars,0.0)
Angle_tol=NamedVarVal("solid blend propagate angle",WsPKSolidsVars,1.0)


Stat= GLPlotOn
Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave
Start:!
Propagate= WsTrue
Stat= SetEqualsValue(Chamfer_len)
Stat=SetInputFormat("n4=","")
Chamfer_len=GetValue("CHAMFER LENGTH")
IF ExitScript(Destination$) THEN Leave
No_chamfer_var= LastVariableInput(Chamfer_var$)
V1=CreateVariable("solid chamfer length",WsPKSolidsVars,Chamfer_len)


Ploop:!
Stat=SetInputFormat("n4","")
E1=WPKPickEntity("PICK FACE",WsPKPickFace)
IF (ExitScript(Destination$)) THEN Leave
IF NOT WPKIsEntity(E1) THEN Face_loop
Stat= EntityNameCheck(E1,Face$)

Pkbody= WPKParentBody(E1)
Stat= EntityNameCheck(Pkbody,Body$)

Pkgroup= WPKSharpEdgeGroup(E1,2)
IF NOT WPKIsEntity(Pkgroup) THEN Pick_loop

GOSUB Fix_blends
Stat= WPKRemoveGroup(Pkgroup)
GOTO Leave

Fix_blends:!
	WPKClearErrorFlag
	RecordFunctionOn
	Stat= RecordDescr("BLEND: chamfer sharp face edges")
	V1= FreeParameter("Propagate on",Propagate)
        V4= FreeParameter("Propagate angle",Angle_tol)
	IF No_chamfer_var THEN
       		V5= FreeParameter("Chamfer",Chamfer_len)
	ELSE
       		V5= FreeParameter("Chamfer",Chamfer_var$)
	END IF
	Pkgroup= WPKSharpEdgeGroup(Face$,2)
	Stat= WPKEdgeChamfer(Pkgroup,V5,V5,V1)
	Stat= WPKUnSetBadBlends(Body$)
	Stat= WPKFixBlends(Body$,V1,V4,V2,V3)
	Stat= WPKRemoveGroup(Pkgroup)
	Stat= WPKNameBody(Body$,Body$)
        Stat= WPKSetBodyParent(Body$,1)
        RecordFunctionOff
        Curr_record= CurrentVarRecord
        CloseVarRecord

	Stat= WPKSolidRecordOn(Curr_record)
        ActivateUndo
        Stat= AdvanceUndoNumber("chamfer sharp face edges")
        Stat= AddItemToUndo(WsUBPKSessionMark)
        Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
        WPKErrorCheck

RETURN


Leave:!
V3=CreateVariable("solid blend propagate angle",WsPKSolidsVars,Angle_tol)
Stat= DeleteGroup(Group,WsTrue)
Stat=SetPickReturn(WsGeometryEnd)
Stat=SetInputFormat("n4","")
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
