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

!A
!A NAME:
!A
!A 	Extend: Parting Line: Plane Normal	VARIATIONAL
!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 the extend distance.
!A
!B INSTRUCTIONS:
!B
!B 	TAPER ANGLE: Taper angle which determines
!B 		the Parting Line.
!B
!B 	EXTEND DISTANCE: Enter the amount of extension.
!B
!B 	PATCH WIDTH ALONG EDGES: Enter the width of
!B 		the patch to be used along 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 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 plane normal extension ")

DIM Destination$[256]
DIM Answer$[256]
DIM Surface$[256]
DIM Dist_var$[256]
DIM Angle_var$[256]
DIM Patch_var$[256]
DIM Name$[256]

Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave

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

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
No_angle_var= LastVariableInput(Angle_var$)

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

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

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

Stat= GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("SURFACE: Plane Normal Parting line extension")
Stat= SetRecDelLastExec
Stat= Set3dInterOffset(0.0)
IF No_angle_var THEN
        V1= FreeParameter("Taper",Angle)
ELSE
        V1= FreeParameter("Taper",Angle_var$)
END IF
IF No_dist_var THEN
        V2= FreeParameter("Extend_dist",Extend_dist)
ELSE
        V2= FreeParameter("Extend_dist",Dist_var$)
END IF
IF No_patch_var THEN
        V3= FreeParameter("Patch_width",Pwidth)
ELSE
        V3= FreeParameter("Patch_width",Patch_var$)
END IF
V4= FreeParameter("Tolerance",Tol)
V5= FreeParameter("Trim_curves_on",Trim_curves_on)
Surf_group=PartingNormalExt(WsPlaneNormalExt,Surf_type,Surface$,V1,V2,V3,V4,V5)
RecordFunctionOff
IF ValidGeometry(Surf_group) THEN
        RecordFunctionOn
        Stat= AutoNameGroup(Surf_group,Name$)

	RecordFunctionOff
	ActivateUndo
	Stat= AdvanceUndoNumber("parting line ext")
	Stat= AddGroupToUndo(WsUBCreateMode,Surf_group,0,WsFalse)
        RecordFunctionOn

        stat= DeleteEntity(Surf_group)
        RecordFunctionOff
        No_surface=0
ELSE
        No_surface=1
END IF
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF No_surface THEN
        DelLastVarRecord
ELSE
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
GOTO Pick_loop

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