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

!A
!A NAME:
!A
!A 	Surface Normal Parting Line Extension Surface
!A
!A DESCRIPTION:
!A
!A 	This script creates a surface normal to the given surface
!A 	at the parting line determined by the taper angle. The surface
!A 	extends until it reaches the Z constant value.
!A
!B INSTRUCTIONS:
!B
!B 	TAPER ANGLE: Taper angle which determines the Parting Line.
!B
!B 	EXTEND DISTANCE: Enter the amount the surface will extend.
!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
!C 	the angle of a wall of the surface. Try to get at least a 0.5 deg
!C 	to 1 deg 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
!C 	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= WsNormal


ActivateUndo
Trim_curves_on= WsTrue

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

Stat=SetPickMask(WsPickGeometry)
Surf_group=PartingNormalExt(Ext_type,Surf_type,Surface,Angle,Extend_dist,Pwidth,Tol,Trim_curves_on)

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
