
! script name: surfaces.d/plnormplineext
! 3dtopic: plane normal parting line extension to a surface.

!A
!A NAME:
!A
!A 	Surface Plane Normal Parting Line Extension Surface
!A
!A DESCRIPTION:
!A
!A 	This script creates a surface normal to the given surface at the
!A 	parting line determined by the taper angle.  The extension surface
!A 	is the the direction of the projection of the normal vector in a z
!A 	constant plane.
!A
!B INSTRUCTIONS:
!B
!B 	TAPER ANGLE: Taper angle which determines the Parting Line.
!B
!B 	EXTEND DISTANCE: Enter the amount the surface extends.
!B
!B 	PATCH WIDTH ALONG EDGES: Enter the width of the patch to be used along
!B 		the edge.
!B
!B 	PICK SURFACE: Pick the surface.
!B
!C NOTES:
!C
!C 	The surface must have its normal vector oriented properly.
!C
!C 	Avoid situations in which the extension surface crosses over 
!C 	itself or degenerates to a point. This will occur in situations
!C 	where the extension has to fit into a tight radius.
!C
!C 	Avoid situations where the parting line taper angle matches the angle
!C 	of a wall of the surface. Try to get at least a 0.5 deg to 1 deg
!C 	difference.
!C
!C 	This function is real sensitive to the smoothness of the surfaces. 
!C 	Even surfaces which may appear smooth may not have smooth parting lines.
!C
!C 	A Nurb surface is more stable than a bicubic if the surfaces
!C 	are not real smooth.
!C


Stat=ChangeLabelStr("ScriptNameStatus","Function: normal parting line extension ")

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

IF ARGC<2 THEN
        Surf_type= WsCubicSurfEnt
ELSE
        Surf_type= WsNurbSurfEnt
END IF
Ext_type= WsPlaneNormalExt


Trim_curves_on= WsTrue

ActivateUndo
Patch_width=NamedVarVal("3D Default Patch",Ws3DSystemVars,0.25)
Tol=NamedVarVal("3D Fillet Tol",Ws3DSystemVars,0.005)

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

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

stat= SetInputFormat("n4=","")
stat= SetEqualsValue(Extend_dist)
Extend_dist= GetValue("EXTEND DISTANCE ",Answer$)
IF (ExitScript(Destination$)) THEN Leave

stat= SetInputFormat("n4=","")
stat= SetEqualsValue(Patch_width)
Pwidth= GetValue("PATCH WIDTH ALONG EDGES",Answer$)
IF (ExitScript(Destination$)) THEN Leave

Intersect2: StdWorkplane
Stat=SetPickMask(WsPickSurfOnly)
Stat=SetInputFormat("n0","")
Surface=PickEntity("PICK SURFACE ",Answer$)
IF ExitScript(Destination$) THEN Leave
IF NOT ValidGeometry(Surface) THEN Intersect2

Pc= PointXYZ(0,0,Z_const)
Stat=SetPickMask(WsPickGeometry)
Surf_group=PartingNormalExt(Ext_type,Surf_type,Surface,Angle,Extend_dist,Pwidth,Tol,Trim_curves_on)
Stat= DeleteEntity(Pc)

ActivateUndo
Stat= AdvanceUndoNumber("surface")
Stat= AddGroupToUndo(WsUBCreateMode,Surf_group,0,WsFalse)

Stat= DeleteEntity(Surf_group)
GOTO Intersect2

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