
! script name: 3dintersect.d/aslicepart
! 3dtopic: slices a part at an angle to the x_axis.

!A
!A NAME:
!A
!A      Angle Slice Part 
!A
!A DESCRIPTION:
!A
!A      This script generates a slice through a part at an angle
!A      through a reference point.
!A
!B INSTRUCTIONS:
!B
!B      PART OFFSET: Enter the offset to the part.
!B
!B      PICK REFERENCE POINT:  Select the reference point.
!B
!B      ANGLE: Input the angle the slice makes with the x axis.
!B
!B      PICK SURFACE GROUP, Name: Pick the surface group to be sliced.
!B
!B              N -  This allows the name of the surface group to be entered.
!B
!B      SURFACE GROUP NAME: Enter the name of the surface group.
!B
!C NOTE:
!C
!C      Slice curves are created as pointchains.
!C

Stat=ChangeLabelStr("ScriptNameStatus","Function: angle 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)
Layer_sw=NamedVarVal("3D Layer Switch",Ws3DSystemVars,1.0)

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

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_point:Stat=SetInputFormat("n4","")
Pc= XyzInput("INPUT",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Pc) THEN Pick_point
Stat=SetLastPoint(Pc,WsXyzInput)

Angle_ques:Angle=InputAngle("ANGLE")
IF (ExitScript(Destination$)) THEN Leave

Angle_slice:StdWorkplane

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

Stat=SetPickMask(WsPickGeometry)

Pt_group= CreateGroup("")
Stat= AddToGroup(Pt_group,Pc)
T1=AngleTransform(Pc,90,0,Angle)
path_group=SlicePart(Part,Pt_group,Tol,WsForward,WsFalse,WsFalse,0,0,T1)
Stat=DeleteGroup(Pt_group,WsTrue)

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

Stat=DeleteEntity(path_group)
GOTO Pick_point

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