
! script name: 3dintersect.d/planeslice
! 3dtopic: slices a part by a plane

!A
!A NAME:
!A
!A 	Plane Slice Part
!A
!A DESCRIPTION:
!A
!A 	This script generates a slice through a part by a plane.
!A
!B INSTRUCTIONS:
!B
!B 	PART OFFSET: Enter the offset to the part.
!B
!B 	PICK SLICE PLANE: Pick the plane that will be used to slice
!B 		the part.
!B
!B 	PICK SURFACE GROUP: Pick the group of surfaces to be sliced by
!B 		the plane.
!B
!C NOTE:
!C
!C 	Slice curves are created as pointchains.
!C

Stat=ChangeLabelStr("ScriptNameStatus","Function: x slice part")

DIM Destination$[256]
DIM Answer$[256]
DIM Surface_dir$[80]

ActivateUndo
Tol=NamedVarVal("3D Intersect Tol",Ws3DSystemVars,0.005)
Ystep=NamedVarVal("3D Default Zstep",Ws3DSystemVars,0.125)

Start:!
Make_cpaths=0
Ask_offset=1
StdWorkplane
Stat=Setup3dCutter(WsNullTool,0.0,0.0,0.0,0.0,0.0)

Part_offset: !

IF ask_offset THEN
Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Offset)
Offset=GetValue("PART OFFSET",Answer$)
IF ExitScript(Destination$) THEN Leave
Stat=Setup3dCutter(WsNullTool,0.0,0.0,Offset,0.0,0.0)
END IF

Pick_plane: Stat=SetPickMask(WsPickSurfOnly)
Stat=SetInputFormat("n0","")
Slice_plane=PickEntity("PICK SLICE PLANE")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidGeometry(Slice_plane) THEN Pick_plane

Pick_group: StdWorkplane

Stat=SetPickMask(WsPickSurfOnly)
Stat=SetInputFormat("n0","")
Part=PickGroupEnt("PICK SURFACE GROUP",WsSurfaceGroup)
IF ExitScript(Destination$) THEN Leave
IF NOT ValidGeometry(Part) THEN Pick_group

Stat=SetPickMask(WsPickGeometry)

Group=CreateGroup("temp")
Pt=SurfParameterPt(Slice_plane,0.0,0.0)
Stat=AddToGroup(Group,Pt)

T1=GetTransform(Slice_plane)
direction=1

IF ValidGeometry(Slice_plane) THEN 
	path_group=SlicePart(Part,Group,Tol,direction,Make_cpaths,WsFalse,0,0,T1)
ELSE
	path_group=SlicePart(Part,Group,Tol,direction,Make_cpaths)
END IF

ActivateUndo
Stat= AdvanceUndoNumber("slice curve")
Stat= AddGroupToUndo(WsUBCreateMode,Path_group,0,WsTrue)

Stat=DeleteGroup(Group,1)
Stat=DeleteEntity(Pt)
Stat=DeleteEntity(path_group)
GOTO Part_offset

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