
! script name: 3dwrap.d/wrapgroup
! 3dtopic: wraps a group around axis line

!A
!A NAME:
!A
!A 	Wrap Group
!A
!A DESCRIPTION:
!A
!A 	This script wraps a group about a cylinder.
!A
!B INSTRUCTIONS:
!B
!B 	RADIUS OF CYLINDER: Enter the Radius of
!B 		the cylinder to be wrapped around.
!B
!B 	STARTING ANGLE: Starting angular coordinate
!B 		of the wrapped entity.
!B
!B 	TAPER ANGLE: Enter the Taper to be applied
!B 		along the axis of wrapping cylinder.
!B
!B 	PICK GROUP TO BE WRAPPED: Pick the group
!B 		to be wrapped.
!B
!B 	U PATCH WIDTH: Enter the U patch width
!B 		for wrapped surfaces only.
!B
!B 	V PATCH WIDTH: Enter the V patch width
!B 		for wrapped surfaces only.
!B
!C NOTES:
!C
!C 	The wrapping algorithm is as follows:
!C 	A point on the entity 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 entity becomes the Y coordinate
!C 	on the wrapped entity.
!C
!C 	The Z coordinate on the wrapping entity 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 	The Taper modifies the Radius for increasing Y values.
!C
!C 	The wrapping entity is not a true development of the wrapped entity.
!C

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

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

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

Radius=InputRadius("RADIUS OF CYLINDER")
IF ExitScript(Destination$) THEN Leave

Astart=InputAngle("STARTING ANGLE")
IF ExitScript(Destination$) THEN Leave

Stat=SetAngleEquals(Taper)
Taper=InputAngle("TAPER ANGLE")
IF ExitScript(Destination$) THEN Leave

Ploop:!

Stat=SetInputFormat("n4","")
Group=PickGroupEnt("PICK GROUP TO BE WRAPPED",0)
IF ExitScript(Destination$) THEN Leave

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

New_group=WrapEntity(Group,Radius,Astart,Taper,Tol,Upatch,Vpatch)

ActivateUndo
Stat= AdvanceUndoNumber("wrap group")
Stat= AddGroupToUndo(WsUBCreateMode,New_group,1,WsTrue)
GOTO Ploop

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