
! script name: parasolids.d/pkdeleteblends
! solids: deletes a face which came from a blend

!A
!A NAME:
!A
!A	Delete Blends
!A
!A DESCRIPTION:
!A
!A 	This script attempts to remove a list of faces based on the 
!A	assumption that the faces were created by a radius blend.
!A	All the faces must come from the same body.
!A
!B INSTRUCTIONS:
!B
!B	PICK FACES: Apply, Unpick ,Clear
!B
!B NOTES:
!B
!B	This script can be very useful for removing faces which resulted
!B	from a radius blend. Do not try to use it on an arbitrary face.
!B
!B	It may not be possible to remove some blends if the geometric
!B	configuration is too complex.
!B
!B	If the opposing faces on the edges of the blend face can be
!B	easily extended to meet in a sharp corner then this function
!B	will succeed, if not the geometry may be too complicated.
!B	Often times a complicated situation may be handled by 
!B	dealing with the problem in pieces. Try to determine a section
!B	of a few faces which could be removed to form a sharp corner.
!B
!# see also - htdocs/help.d/parasolids.htm


stat=ChangeLabelStr("ScriptNameStatus","Function: delete blends ")

OPTION BASE 1
DIM Destination$[256]
DIM Answer$[256]
REAL Face_array(100)

ActivateUndo

Pick_color=2

Stat= GLPlotOn
Start:!
Num_faces= 0
Mark_group=CreateGroup("TEMPGROUP")

Face_loop:!
Stat=SetInputFormat("a1",",A,U,C,")
E1=WPKPickEntity("PICK FACES: Apply, Unpick ,Clear ",WsPKPickFace,Answer$)
IF (ExitScript(Destination$)) THEN Leave

SELECT Answer$
CASE "A"
	GOSUB Delete_faces
	GOTO Start
CASE "U"
	Num_faces= Num_faces-1
	IF Num_faces<0 THEN Num_faces=0
	N1= GroupCount(Mark_group)
	E1= GroupElement(Mark_group,N1)
	Stat=RemoveFromGrp(Mark_group,N1)
	Stat= DeleteEntity(E1)
	N1= GroupCount(Mark_group)
	IF N1= 0 THEN 
		Stat= DeleteEntity(Ps)
	END IF
	PlotAll
	GOTO Face_loop
CASE "C"
	Stat= DeleteGroup(Mark_group,WsTrue)
	Stat= DeleteEntity(Ps)
	PlotAll
	GOTO Start
END SELECT

IF Num_faces= 99 THEN Start
IF NOT WPKIsEntity(E1) THEN Face_loop

UVpoint=LastUVSurfPick(E1)
IF NOT ValidGeometry(UVpoint) THEN Face_loop
U=XPointValue(UVpoint)
V=YPointValue(UVpoint)
Stat= DeleteEntity(UVPoint)

Face1= WPKEntityTag(E1)
FOR I= 1 TO Num_faces
	IF Face1= Face_array(I) THEN Face_loop
NEXT I
Num_faces= Num_faces+1
Face_array(Num_faces)= Face1
Pt= SurfParameterPt(E1,U,V)
Stat= SetColor(Pt,Pick_color,WsTrue)
Stat= AddToGroup(Mark_group,Pt)
GOTO Face_loop

Delete_faces:!
WPKClearErrorFlag
Stat= DeleteGroup(Mark_group,WsTrue)

WPKClearErrorFlag
E2= WPKDeleteBlends(Num_faces,Face_array)

ActivateUndo
Stat= AdvanceUndoNumber("delete blends")
Stat= AddItemToUndo(WsUBPKSessionMark)
WPKErrorCheck
RETURN


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