
! script name: v3dinter.d/surfintpart
! var_topic: generate a group of paths of intersection of a surface and a part

!A
!A NAME:
!A
!A 	Intersect: Surface Intersect part. VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will generate a group of paths of intersection of a surface
!A 	with a part  in 3d space.  There is a path generated for
!B 	each pair of intersecting surfaces.
!A
!B INSTRUCTIONS:
!B
!B 	PICK SURFACE : Pick  the surface  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: surf intersect part ")

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

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

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

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

Stat=SetPickMask(WsPickSurfOnly)
Stat=SetInputFormat("n4","")
Surface=PickEntity("PICK SURFACE ")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(Surface) THEN Pick_loop
Stat= EntityNameCheck(Surface,Element$)


Pick_part:!
Stat=SetPickMask(WsPickSurfOnly)
Stat=SetInputFormat("n4","")
Part_group=PickGroupEnt("PICK SURFACE GROUP ",WsSurfaceGroup)
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(Part_group) THEN Pick_part
Stat= EntityNameCheck(Part_group,Part_name$)

Stat=Highlight(Part_group,WsPickPen,WsDirArrowOff)
Stat=SetPickMask(WsPickGeometry)

Stat= GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("CURVE: Surface int Part")
Stat= SetRecDelLastExec
stat= Set3dInterOffset(0.0)
V1= FreeParameter("Tolerance",Tol)
G1= CreateGroup("")
Stat= AddToGroup(G1,Element$)
G2=IntersectParts(Part_name$,S1,G1,S2,V1)
Stat= AutoNameGroup(G2,Name$)
Stat= SetNoPathFlag(G2,WsTrue)
Stat= DeleteEntity(G1)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(G2) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("intersect curves")
	Stat= AddGroupToUndo(WsUBCreateMode,G2,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
