
! script name: vpksolids.d/vpktaperbodyup
! var_solids: apply taper to a body up to the parting body.

!A
!A NAME:
!A
!A 	Taper Body Up to Parting Body. VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script applies taper to a body up to the parting body.
!A
!A~ image location - images/pktaperbodyup.gif
!A
!B INSTRUCTIONS:
!B
!B	TAPER ANGLE: Specify the taper angle.
!B
!B	PICK REFERENCE EDGE GROUP: Select the group of reference edges.
!B 		Reference edges should be grouped as a parasolid
!B 		group.  The edge group must form single connected curve
!B 		which lies below the parting body. The curve cannot
!B 		cross the parting body.
!B
!B	SELECT PARTING BODY: Select the parting body (usually a sheet).
!B
!B NOTES:
!B
!B      The taper direction is determined by the positive z axis of
!B      the current workplane.
!B
!B	The parting body and the main body should intersect in a clean
!B	fashion. If the intersection between the body and the parting body
!B	is too complex this function will fail.
!B
!B      The following methods are available:
!B
!B              0,1) PK_taper_method_isocline_c (default)
!B              2)   PK_taper_method_curve_c    uses reference curves tangent.
!B              3)   PK_taper_method_surface_c  uses tapered face normal.
!B
!B	The default method will fail if the reference curves become steeper
!B	than the taper angle. In this case try another method. The method
!B	becomes a system variable once the script has been used.
!B
!B      The corner type specifies how geometry is to be constructed to
!B      fill the gaps between to adjacent tapered faces.
!B      The possible values for corner_type are
!B              0,1) PK_taper_corner_extend_c adjacent faces extended(default).
!B              2)   PK_taper_corner_plane_c plane face created filling gap
!B
!B	Corner type becomes a system variable once the script has been used.
!B
!# see also - htdocs/help.d/parasolids.htm


stat=ChangeLabelStr("ScriptNameStatus","Function: taper body ")

OPTION BASE 1
DIM Destination$[256]
DIM Answer$[256]
DIM Body$[256]
DIM Edge_group$[256]
DIM Parting_body$[256]
DIM Angle_var$[256]

ActivateUndo

Stat= GLPlotOn
Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave
Start:!
Method=NamedVarVal("solid taper face method",WsPKSolidsVars,1.0)
Corner_type=NamedVarVal("solid taper corner type",WsPKSolidsVars,1.0)
Merge_faces=NamedVarVal("solid taper merge faces",WsPKSolidsVars,1.0)


Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Angle)
Angle=GetValue("TAPER ANGLE",Answer$)
IF ExitScript(Destination$) THEN Leave
No_angle_var= LastVariableInput(Angle_var$)

Reference_loop:!
E1=WPKPickEntity("PICK REFERENCE EDGE GROUP",WsPKPickEdge)
IF (ExitScript(Destination$)) THEN Leave
IF NOT WPKIsEntity(E1) THEN Start
Stat= EntityNameCheck(Pkbody,Body$)
Stat= EntityNameCheck(Pkgroup,Edge_group$)

Pkbody= WPKParentBody(E1)
Pkgroup= WPKContainingGroup(E1,1)
IF NOT WPKIsEntity(Pkgroup) THEN Start

Stat=SetInputFormat("n4","")
E1=WPKPickEntity("SELECT PARTING BODY")
IF (ExitScript(Destination$)) THEN Leave
IF NOT WPKIsEntity(E1) THEN Start
Pkparting= WPKParentBody(E1)
Stat= EntityNameCheck(Pkparting,Parting_body$)

WPKClearErrorFlag
RecordFunctionOn
Stat= RecordDescr("BODY: taper body")
IF No_angle_var THEN
         V1= FreeParameter("Angle",Angle)
ELSE
         V1= FreeParameter("Angle",Angle_var$)
END IF
V2= FreeParameter("Method",Method)
V3= FreeParameter("Merge faces",Merge_faces)
V4= FreeParameter("Corner type",Corner_type)
Stat= WPKTaperBody(Body$,Parting_body$,0,Edge_group$,0.0,V1,V2,WsFalse,V3,V4)
Stat= WPKNameBody(Body$,Body$)
Stat= WPKSetBodyParent(Body$,1)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= WPKSolidRecordOn(Curr_record)
ActivateUndo
Stat= AdvanceUndoNumber("taper body")
Stat= AddItemToUndo(WsUBPKSessionMark)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
WPKErrorCheck

Leave:!
V1=CreateVariable("solid taper face method",WsPKSolidsVars,Method)
V2=CreateVariable("solid taper merge faces",WsPKSolidsVars,Merge_faces)
V3=CreateVariable("solid taper corner type",WsPKSolidsVars,Corner_type)
PlotOn
V1=CreateVariable("solid taper face method",WsPKSolidsVars,Method)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
