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

!A
!A NAME:
!A
!A 	Surface Parting Line Tangent Extension Surface
!A
!A DESCRIPTION:
!A
!A 	This script creates a surface tangent 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 	Z CONSTANT: Lower extent of extension surface.
!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 curve will approach vertical.
!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 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: tangent 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

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(Z_const)
Z_const= GetValue("Z CONSTANT ",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=PartingTaperExt(Surf_type,Surface,Pc,Angle,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
