
! script name: surfaces.d/constcross
! 3dtopic: construct constant cross section surface

!A
!A NAME:
!A
!A 	Constant Cross Section
!A
!A DESCRIPTION:
!A
!A 	This script will make a constant cross section surface.  This surface
!A 	is created by sweeping a cross section contour along the drive contour,
!A 	maintaining the cross section normal to the drive contour.  The cross
!A 	section contour must be described at the start point of the drive
!A 	contour in 3D position.
!A
!B INSTRUCTIONS:
!B
!B 	U PATCH WIDTH: Enter the width of the patch to be
!B 		used along the cross section contour.
!B
!B 	V PATCH WIDTH: Enter the width of the patch to be
!B 		used along the drive contour.
!B
!B 	PICK DRIVE CONTOUR: Pick the generating contour.
!B
!B 	PICK CROSS SECTION: Pick the constant cross section.
!B
!C NOTES:
!C
!C	The drive contour and the cross contour must be smooth. 
!C	Adjacent elements must be tangent.
!C
!C 	The patch widths need not match small radii. The surface will
!C 	automatically be created width a minimum number of patches on small
!C 	radii. Small splines however will require consideration in patch size.
!C
!C 	The optimum workplane for a constant cross section is the workplane of
!C 	the drive contour. Most other workplanes will give an equivalent
!C 	surface, but in some workplanes the surface may not be generated, or it
!C 	may give undesirable results.
!C
!C 	The drive contour must not ever become perpendicular to the workplane.
!C 	If this occurs the orientation of the cross section becomes confused.
!C
!C 	The U contours of the constant cross section surface are the cross
!C 	sections.  The V contours are the contours generated along the drive
!C 	contour.
!C

Stat=ChangeLabelStr("ScriptNameStatus","Function: constant cross section ")

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

ActivateUndo
Patch_width=NamedVarVal("3D Default Patch",Ws3DSystemVars,0.5)

Uwidth=Patch_width
Vwidth=Patch_width

Blend_loop:!

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Uwidth)
Uwidth=GetValue("U PATCH WIDTH",Answer$)
IF ExitScript(Destination$) THEN Leave

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

Cont_count=1
Pick_loop: !
Stat=SetPickMask(WsPickNoSurf)
Contour=PickGroupEnt("PICK DRIVE CONTOUR ",0)
IF ExitScript(Destination$) THEN Leave
IF NOT ValidGeometry(Contour) THEN Pick_loop
Stat=Highlight(Contour,WsPickPen,WsDirArrowOff)

Pick_cross: Stat=SetPickMask(WsPickNoSurf)
Cross_section=PickGroupEnt("PICK CROSS SECTION ",0)
IF ExitScript(Destination$) THEN Leave
IF NOT ValidGeometry(Cross_section) THEN Pick_cross
Stat=Highlight(Cross_section,WsPickPen,WsDirArrowOff)

Surf=ConstCrossSurface(Contour,Cross_section,Uwidth,Vwidth)

ActivateUndo
Stat= AdvanceUndoNumber("const cross section")
Stat= AddItemToUndo(WsUBCreateMode,Surf)

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