
! script name: v3dinter.d/pintersect
! var_topic: generate a group of paths of intersection of two parts

!A
!A NAME:
!A
!A 	Intersect: Parts VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will generate a group of paths of intersection of two
!A 	parts ( surface groups ) in 3d space.  There is a path generated for
!B 	each pair of intersecting surfaces.
!A
!B INSTRUCTIONS:
!B
!B 	PICK SURFACE GROUP #1: Pick one of the surface groups to be used for
!B 		the intersection.
!B
!B 	PICK SURFACE GROUP #2: Pick the other surface group to be used for the
!B 		intersection.
!B

Stat=ChangeLabelStr("ScriptNameStatus","Function: intersect parts ")

DIM Destination$[256]
DIM Answer$[256]
DIM Part1$[256]
DIM Part2$[256]
DIM Name$[256]

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

ActivateUndo
Normal_len=NamedVarVal("3D Normal Length",Ws3DSystemVars,1.0)
Tol=NamedVarVal("3D Intersect Tol",Ws3DSystemVars,0.005)

Start:!
Stat=Setup3dCutter(WsNullTool,0.0,0.0,0.0,0.0,0.0)
Intersect2: StdWorkplane
Pick_loop:!

Pick_part1:!
Stat=SetPickMask(WsPickSurfOnly)
Stat=SetInputFormat("n4","")
Part_group1=PickGroupEnt("PICK SURFACE GROUP #1 ",WsSurfaceGroup)
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(Part_group1) THEN Pick_part1
Stat= EntityNameCheck(Part_group1,Part1$)
Stat=Highlight(Part_group1,WsPickPen,WsDirArrowOff)

Pick_part2:!
Stat=SetPickMask(WsPickSurfOnly)
Stat=SetInputFormat("n4","")
Part_group2=PickGroupEnt("PICK SURFACE GROUP #2 ",WsSurfaceGroup)
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(Part_group2) THEN Pick_part2
Stat= EntityNameCheck(Part_group2,Part2$)
Stat=Highlight(Part_group2,WsPickPen,WsDirArrowOff)
Stat=SetPickMask(WsPickGeometry)


Stat= GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("CURVES: Intersect Parts")
Stat= SetRecDelLastExec
stat= Set3dInterOffset(0.0)
V1= FreeParameter("Tolerance",Tol)
G1=IntersectParts(Part1$,S1,Part2$,S2,V1)
Stat= AutoNameGroup(G1,Name$)
Stat= SetNoPathFlag(G1,WsTrue)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(G1) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("intersect parts")
	Stat= AddGroupToUndo(WsUBCreateMode,G1,1,WsTrue)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
GOTO Intersect2

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