
! script name: pksurfaces.d/sewbodies
! solids: sew two sheet bodies

!A
!A NAME:
!A
!A 	Sew Sheet Bodies
!A
!A DESCRIPTION:
!A
!A 	This script sews two sheet bodies together along common
!A	edges to form a single sheet body.
!A
!A~ image location - images/pksewbodies.gif
!A
!B INSTRUCTIONS:
!B
!B	GAP DISTANCE: Enter the maximum gap to be closed.
!B
!B	PICK FIRST SHEET BODY: Pick the first sheet body.
!B
!B	PICK SECOND SHEET BODY: Pick the second sheet body.
!B
!B NOTE:
!B
!B	The user must check that the bodies have been joined along
!B	the common edges. Carefully examine the wire frame of the sheet
!B	looking for double edges. The sheets may join in some areas and
!B	not in others. If the join is imperfect, undo and use a larger
!B	gap distance.
!B
!B	Using too large a gap distance may result in undesired merging.
!B
!B	Too small a gap distance will result in an imperfect join.
!B	
!B	If a series of sheet bodies is sewn together to form a closed
!B	volume a solid body will result if possible.
!B
!# see also - htdocs/help.d/parasolids.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: sew sheet bodies ")

DIM Destination$[256]
DIM Answer$[256]

ActivateUndo
Units= CurrentUnits
IF Units= WsMetric THEN
        Gap_dist= 1.25
ELSE
        Gap_dist= .050
END IF
Stat= GLPlotOn

Gap_dist:!
Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Gap_dist)
Gap_dist=GetValue("GAP DISTANCE ")
IF ExitScript(Destination$) THEN Leave

Body_loop:!

E1=WPKPickEntity("PICK FIRST BODY")
IF (ExitScript(Destination$)) THEN Leave
IF NOT WPKIsEntity(E1) THEN Body_loop

Body= WPKParentBody(E1)
Body_type= WPKBodyType(Body)
IF Body_type<> WsPKSheetBody THEN Body_loop

E2=WPKPickEntity("PICK SECOND BODY")
IF (ExitScript(Destination$)) THEN Leave
IF NOT WPKIsEntity(E2) THEN Body_loop

Body= WPKParentBody(E2)
Body_type= WPKBodyType(Body)
IF Body_type<> WsPKSheetBody THEN Body_loop

WPKClearErrorFlag
E3= WPKSewBodies(E1,E2,Gap_dist)

ActivateUndo
Stat= AdvanceUndoNumber("sew bodies")
Stat= AddItemToUndo(WsUBPKSessionMark)
WPKErrorCheck

GOTO Body_loop

Leave:!
LowerColorBox
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
