
! script name: v3dwrap.d/odwrapgroup
! var_topic: wraps a group around axis line for mill-turn.

!A
!A NAME:
!A
!A 	Wrap Group for Mill-Turn  VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script wraps a group about a cylinder for mill-turn.
!A
!B INSTRUCTIONS:
!B
!B 	RADIUS OF CYLINDER: Enter the Diameter of the cylinder to be wrapped
!B 		around.
!B
!B 	PICK GROUP TO BE WRAPPED: Pick the group to be wrapped.
!B
!C NOTES:
!C
!C 	The wrapping algorithm is as follows:
!C 	A point on the group 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 group becomes the Y coordinate
!C 	on the wrapped group.
!C
!C 	The Z coordinate on the wrapping group 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 group is not a true development of the wrapped group.
!C

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

DIM Destination$[256]
DIM Answer$[256]
DIM Group$[256]
DIM Radius_var$[256]

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

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

Ask_radius:Stat=SetInputFormat("n4=","")
Radius=InputRadius("RADIUS OF CYLINDER")
IF (ExitScript(Destination$)) THEN Leave
No_radius_var= LastVariableInput(Radius_var$)
C1= LastPickEnt
IF ValidGeometry(C1) THEN
        IF NOT ValidDependency(C1) THEN Ask_radius
        No_radius_var=0
        Stat= EntityNameCheck(C1,Radius_var$)
END IF


Ploop:!

Stat=SetInputFormat("n4","")
Group=PickGroupEnt("PICK GROUP TO BE WRAPPED",0)
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(Group) THEN Ploop
Stat= EntityNameCheck(Group,Group$)
Stat=SetPickMask(WsPickAll)

E1=GroupElement(Group,1)
Ask_patches=IsSurfaceEntity(E1)
IF Ask_patches THEN
        Stat=SetInputFormat("n4=","")
        Stat=SetEqualsValue(Uwidth)
        Upatch=GetValue("U PATCH WIDTH",Answer$)
        IF ExitScript(Destination$) THEN Leave

        Stat=SetInputFormat("n4=","")
        Stat=SetEqualsValue(Vwidth)
        Vpatch=GetValue("V PATCH WIDTH",Answer$)
        IF ExitScript(Destination$) THEN Leave
END IF


Stat= GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("WRAP: Od wrap group")
Stat= SetRecDelLastExec
Work= CurrentWorkplane
Stat= SetWorkplane
P1=PointXYZ(0,0,0)
P2=PointXYZ(0,1,0)
P3=PointXYZ(-1,0,0)
Trans1=ThreePtTrans(P1,P2,P3)
Stat=SetWorkplane(Trans1)
V1= FreeParameter("Astart",90)
V2= FreeParameter("Tolerance",Tol)
V3= FreeParameter("U patch width",Uwidth)
V4= FreeParameter("V patch width",Vwidth)
IF No_radius_var THEN
        V12= FreeParameter("Radius",Radius)
	G1=WrapEntity(Group$,V12,V1,0.0,V2,V3,V4)
ELSE
	G1=WrapEntity(Group$,Radius_var$,V1,0.0,V2,V3,V4)
END IF
Stat= AutoNameGroup(G1,Name$)
Stat= SetNoPathFlag(G1,WsTrue)
Stat= DeleteEntityList(P1,P2,P3)
Stat= SetWorkplane(Work)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(G1) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("od wrap group")
	Stat= AddGroupToUndo(WsUBCreateMode,G1,1,WsTrue)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
GOTO Ploop

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