
! script name: surfaces.d/ppartingext
! 3dtopic: generates a parting line extension on a part

!A
!A NAME:
!A
!A 	Part Parting Line 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 GROUP: Pick the surface group.
!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 	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: 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

Pick_loop: StdWorkplane
Stat=SetPickMask(WsPickSurfOnly)
Stat=SetInputFormat("n4","")
Part_group=PickGroupEnt("PICK SURFACE GROUP",WsSurfaceGroup)
IF ExitScript(Destination$) THEN Leave
IF NOT ValidGeometry(Part_group) THEN Pick_loop

Stat=Highlight(Part_group,WsPickPen,WsDirArrowOff)

Pc= PointXYZ(0,0,Z_const)
Stat=SetPickMask(WsPickGeometry)
Surf_group=PartingTaperExt(Surf_type,Part_group,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 Pick_loop

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