
! script name: vpksolids.d/vpksewbodies
! var_solids: sew two sheet bodies

!A
!A NAME:
!A
!A 	Sew Sheet Bodies  VARIATIONAL
!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]
DIM Name$[256]
DIM Body1$[256]
DIM Body2$[256]
DIM Gap_var$[256]

ActivateUndo
Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave
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
No_gap_var= LastVariableInput(Gap_var$)

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
Stat= EntityNameCheck(Body,Body1$)

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
Stat= EntityNameCheck(Body,Body2$)


WPKClearErrorFlag
RecordFunctionOn
Stat= RecordDescr("SOLIDS: Sew sheets")
IF No_gap_var THEN
        V1= FreeParameter("Gap distance",Gap_dist)
ELSE
        V1= FreeParameter("Gap distance",Gap_var$)
END IF
E3= WPKSewBodies(Body1$,Body2$,Gap_dist)
Stat= WPKNameBody(Body1$,Body1$)
Stat= WPKSetBodyParent(Body1$,1)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= WPKSolidRecordOn(Curr_record)
ActivateUndo
Stat= AdvanceUndoNumber("sew bodies")
Stat= AddItemToUndo(WsUBPKSessionMark)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
WPKErrorCheck

GOTO Body_loop

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