
! script name: vpkintersect.d/vbodyentintersect
! var_solids: find the intersection between a body and a contour

!A
!A NAME:
!A
!A 	Body with Entity  VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script finds the intersect points between an entity and a body.
!A
!B INSTRUCTIONS:
!B
!B 	PICK BODY: Pick the target body.
!B
!B 	PICK ENTITY: Pick a synergy entity.
!B
!# see also - htdocs/help.d/parasolids.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: body curve intersect ")

DIM Destination$[256]
DIM Answer$[256]
DIM Element$[256]
DIM Body$[256]
DIM Name$[256]

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


Stat= GLPlotOn
Start:!
Body_loop:!
Pkbody= WPKCurrentBody
IF NOT WPKIsEntity(Pkbody) THEN
        Stat=SetInputFormat("n4","")
        E1=WPKPickEntity("PICK BODY")
        IF (ExitScript(Destination$)) THEN Leave
        IF NOT WPKIsEntity(E1) THEN Start
        Pkbody= WPKParentBody(E1)
END IF
Stat= EntityNameCheck(Pkbody,Body$)


Pick_entity:!
E2=PickEntity("PICK ENTITY ")
IF (ExitScript(Destination$)) THEN Leave
Stat= EntityNameCheck(E2,Element$)

WPKClearErrorFlag
Stat= GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("POINTS: body intersect entity")
G1= WPKBodyCurveInter(Body$,Element$)
Stat= AutoNameGroup(G1,Name$)
RecordFunctionOff
IF ValidGeometry(G1) THEN
        ActivateUndo
        Stat= AdvanceUndoNumber("body intersect entity")
        Stat= AddGroupToUndo(WsUBCreateMode,G1,0,WsTrue)
        Make_record=1
ELSE
        Make_record=0
END IF
RecordFunctionOn
Stat= DeleteEntity(G1)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

IF Make_record THEN
        Stat= WPKSolidRecordOn(Curr_record)
        ActivateUndo
        Stat= AddItemToUndo(WsUBPKSessionMark)
        Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
ELSE
        DelLastVarRecord
END IF
WPKErrorCheck
GOTO Body_loop

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