
! script name: 3dwrap.d/odwrapcontour
! 3dtopic: wraps a contour around axis line for mill-turn.

!A
!A NAME:
!A
!A 	Wrap Contour for Mill-Turn
!A
!A DESCRIPTION:
!A
!A 	This script wraps a contour about a cylinder for mill-turn.
!A
!B INSTRUCTIONS:
!B
!B 	DIAMETER OF CYLINDER: Enter the Diameter of the
!B 		cylinder to be wrapped around.
!B
!B 	PICK CONTOUR TO BE WRAPPED: Pick the contour
!B 		to be wrapped.
!B
!C NOTES:
!C
!C 	The wrapping algorithm is as follows:
!C 	A point on the contour to be wrapped has an X,Y,Z coordinate
!C 	relative to the current workplane. The X coordinate determines
!C 	the angular displacement around the wrapping cylinder.
!C 	X=0 will be mapped into the starting angle relative to the
!C 	wrapping cylinder. X= 2*PI*R will be mapped into one full
!C 	revolution around the wrapping cylinder from the starting angle.
!C 	X= 2*PI*R*A/360 will be mapped into a point at an angle A
!C 	relative to the starting angle.
!C
!C 	The Y coordinate on the wrapping contour becomes the Y coordinate
!C 	on the wrapped contour.
!C
!C 	The Z coordinate on the wrapping contour becomes a radial displacement
!C 	from the radius of the wrapping cylinder.
!C 	A positive Z adds to the radius. A negative Z subtracts from the radius.
!C
!C 	The wrapping contour is not a true development of the wrapped contour.
!C

Stat=ChangeLabelStr("ScriptNameStatus","Function: mill-turn wrap contour ")

DIM Destination$[256]
DIM Answer$[256]

ActivateUndo
Active_workplane=0
Work=CurrentWorkplane
IF (ValidGeometry(Work)) THEN Active_workplane=1

StdWorkplane

Tol=NamedVarVal("3D Intersect Tol",Ws3DSystemVars,0.005)
Patch_width=NamedVarVal("3D Default Patch",Ws3DSystemVars,0.5)
Uwidth=Patch_width
Vwidth=Patch_width

Diameter=InputRadius("DIAMETER OF CYLINDER",WsDiaInput)
IF ExitScript(Destination$) THEN Leave
Radius= Diameter/2

Ploop:!

Stat=SetPickMask(WsPickNoSurf)
Stat=SetInputFormat("n4","")
Contour=PickGroupEnt("PICK CONTOUR TO BE WRAPPED",0)
IF ExitScript(Destination$) THEN Leave
Stat=SetPickMask(WsPickAll)

Astart= 90
Taper= 0

StdWorkplane
P1= PointXYZ(0,0,0)
P2= PointXYZ(0,1,0)
P3= PointXYZ(-1,0,0)
T1=ThreePtTrans(P1,P2,P3)
Stat=SetWorkplane(T1)

New_contour=WrapEntity(Contour,Radius,Astart,Taper,Tol,Uwidth,Vwidth)
Stat=AutoNumberCont(New_contour)

Stat= DeleteEntity(P1)
Stat= DeleteEntity(P2)
Stat= DeleteEntity(P3)

ActivateUndo
Stat= AdvanceUndoNumber("wrap contour")
Stat= AddGroupToUndo(WsUBCreateMode,New_contour,1,WsTrue)
GOTO Ploop

Leave:!
IF Active_workplane THEN
        Stat=SetWorkplane(Work)
ELSE
        StdWorkplane
END IF
Stat=SetPickMask(WsPickAll)
Stat=SetInputFormat("n4","")
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END
