
! script name: 3dintersect.d/entintsurf
! 3dtopic: entity intersect surface

!A
!A NAME:
!A
!A 	Entity Intersect Surface
!A
!A DESCRIPTION:
!A
!A 	This script will generate a point at the intersection of an entity and
!A 	a surface. The pick location will determine which intersection is to be
!A 	generated.
!A
!B INSTRUCTIONS:
!B
!B 	PICK ENTITY: Pick the entity.  Note: The pick location is important.
!B
!B 	PICK SURFACE : Pick the the surface.  Note: The pick location is
!B 		important.
!B
!C NOTES:
!C
!C 	The pick location should be near the desired intersection, failure
!C 	to do this may result in no point generated.
!C

Stat=ChangeLabelStr("ScriptNameStatus","Function: entity intersect surface ")

DIM Destination$[256]
DIM Answer$[256]

ActivateUndo
Tol=NamedVarVal("3D Intersect Tol",Ws3DSystemVars,0.005)
Start:!
StdWorkplane
Stat=Setup3dCutter(WsNullTool,0.0,0.0,0.0,0.0,0.0)

Intersect2: StdWorkplane

Pick_entity:!
Stat=SetPickMask(WsPickNoSurf)
Stat=SetInputFormat("n0","")
Ent=PickEntity("PICK ENTITY ",Answer$)
IF ExitScript(Destination$) THEN Leave
IF NOT ValidGeometry(Ent) THEN Pick_entity
T=LastPickPara

Pick_surf:!
Stat=SetPickMask(WsPickSurfOnly)
Surface=PickEntity("PICK SURFACE",Answer$)
IF ExitScript(Destination$) THEN Leave
IF NOT ValidGeometry(Surface) THEN Pick_surf
UVpoint=LastUVSurfPick(Surface)
IF NOT ValidGeometry(UVpoint) THEN Pick_surf
U=XPointValue(UVpoint)
V=YPointValue(UVpoint)

Stat=SetPickMask(WsPickGeometry)

p1=EntityIntSurf(Ent,T,Surface,U,V,Tol)

Stat=DeleteEntity(UVpoint)

ActivateUndo
Stat= AdvanceUndoNumber("point")
Stat= AddItemToUndo(WsUBCreateMode,P1)

GOTO Intersect2

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