
! script name: parasolids.d/chamfersharpfaceedges
! solids: chamfer sharp edges on a face

!A
!A NAME:
!A
!A 	Chamfer Face Sharp Edges
!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 face sharp corners ")

OPTION BASE 1
DIM Destination$[256]
DIM Answer$[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
Start:!
Stat= SetEqualsValue(Chamfer_len)
Stat=SetInputFormat("n4=","")
Chamfer_len=GetValue("CHAMFER LENGTH")
IF ExitScript(Destination$) THEN Leave
V1=CreateVariable("solid chamfer length",WsPKSolidsVars,Chamfer_len)

Pick_loop:!
E1=WPKPickEntity("PICK FACE",WsPkPickFace)
IF (ExitScript(Destination$)) THEN Leave
IF NOT WPKIsEntity(E1) THEN Pick_loop

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

Propagate= WsTrue
Stat= WPKEdgeChamfer(Pkgroup,Chamfer_len,Chamfer_len,Propagate)
Stat= WPKUnSetBadBlends(Pkbody)
Stat= WPKFixBlends(Pkbody,Propagate,Angle_tol)
Stat= WPKRemoveGroup(Pkgroup)
ActivateUndo
Stat= AdvanceUndoNumber("face edge blend")
Stat= AddItemToUndo(WsUBPKSessionMark)
WPKErrorCheck
GOTO Start



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
