
! script name: vpkboolean.d/vpkunite
! var_solids: unite two solid bodies

!A
!A NAME:
!A
!A 	Unite Two Bodies VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script unites or adds two solid bodies together forming a
!A	single resultant body.
!A
!A~ image location - images/pkboolean.gif
!A
!B INSTRUCTIONS:
!B
!B	PICK FIRST BODY:  Pick the first of the two bodies.
!B
!B	PICK SECOND BODY: Pick the second of the two bodies.
!B
!B NOTES:
!B
!B	The resulting body will have the same parasolid tag as
!B	the first body. The resultant body will inherit the properties
!B	of the first body, for example layer and name.
!B	Faces which survive the addition will retain
!B	their colors and other properties. New Faces will have the 
!B	current color properties.
!B
!# see also - htdocs/help.d/parasolids.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: unite two bodies ")

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Body1$[256]
DIM Body2$[256]

ActivateUndo

Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave

Stat= GLPlotOn
Body_loop:!

E1=WPKPickEntity("PICK FIRST BODY")
IF (ExitScript(Destination$)) THEN Leave
IF NOT WPKIsEntity(E1) THEN Body_loop
Body1= WPKParentBody(E1)
Stat= EntityNameCheck(Body1,Body1$)

E2=WPKPickEntity("PICK SECOND BODY")
IF (ExitScript(Destination$)) THEN Leave
IF NOT WPKIsEntity(E2) THEN Body_loop
Body2= WPKParentBody(E2)
Stat= EntityNameCheck(Body2,Body2$)

WPKClearErrorFlag

RecordFunctionOn
Stat= RecordDescr("BOOLEAN: Unite")
G1= WPKUniteBodies(Body1$,Body2$)
Stat= WPKNameBodyGroup(G1,Body1$)
Stat= WPKSetBodyParent(G1,1)
Stat= DeleteEntity(G1)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

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

GOTO Body_loop

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