
! script name: pkswept.d/pkceswept
! solids: construct body by sweeping a contour along an entity

!A
!A NAME:
!A
!A 	Sweep Contour along Entity
!A
!A DESCRIPTION:
!A
!A	This script sweeps a contour along an entity. The resulting
!A	body is a sheet body if the contour is open, a solid body if
!A	the contour is closed.
!A
!B INSTRUCTIONS:
!B
!B	ALIGNMENT:  Normal, Parallel 	Alignment of cross sections.
!B				
!B			N    Normal Alignment
!B			NT   Normal Alignment with twist and scale
!B			NS   Normal Alignment scale
!B			P    Parallel Alignment
!B			PT   Parallel Alignment with twist and scale
!B			PS   Parallel Alignment scale
!B
!B
!B
!B	PICK CONTOUR TO BE SWEPT: Pick the contour to be swept. The contour
!B 		should be a synergy contour and should be defined in a plane
!B 		which is normal to the contour. It should be placed at a
!B 		vertex of the sweep path.
!B
!B	PICK ENTITY TO SWEEP ALONG: Pick the entity defining the sweep.  This
!B 		entity can be either a regular synergy geometry entity or an
!B 		edge of a parasolid body.
!B
!C NOTES:
!C
!C	The resulting body cannot not be self-intersecting. Attempting to
!C	sweep a shape around a radius to small to except it will generate
!C	a self-intersecting body. A sharp corner on the sweep path will
!C	generate a mitered corner.
!C
!C	The variable swept body form can be changed the default is 2
!C			
!C		swept body form   0:   minimal topology
!C		swept body form   1:   columns
!C		swept body form   2:   grid
!C
!# see also - htdocs/help.d/parasolids.htm

Stat=ChangeLabelStr("ScriptNameStatus","Function: sweep contour along entity ")

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

ActivateUndo

Swept_form=NamedVarVal("swept body form",WsPKSolidsVars,2.0)
Simplify=NamedVarVal("simplify swept body",WsPKSolidsVars,1.0)
Stat= GLPlotOn
Start:!
Ask_twist= 0
Ask_scale= 0
Twist_on= 0
Stat=SetInputFormat("a2=",",N,NS,NT,P,PS,PT,")
Stat=SetEqualsValue(0,"N")
Stat=GetValue("ALIGNMENT: Normal, Parallel NS NT PS PT  ",Answer$)
IF ExitScript(Destination$) THEN Leave
SELECT Answer$
CASE "N"
	Alignment= 0
	Ask_twist= 0
	Ask_scale= 0
CASE "P"
	Alignment= 1
	Ask_twist= 0
	Ask_scale= 0
CASE "NT"
	Alignment= 0
	Ask_twist= 1
	Ask_scale= 1
	Twist_on= 1
CASE "NS"
	Alignment= 0
	Ask_twist= 0
	Ask_scale= 1
	Twist_on= 1
CASE "PT"
	Alignment= 1
	Ask_twist= 1
	Ask_scale= 1
	Twist_on= 1
CASE "PS"
	Alignment= 1
	Ask_twist= 0
	Ask_scale= 1
	Twist_on= 1
END SELECT


IF Ask_twist THEN
	Stat=SetInputFormat("n4=","")
	Stat= SetEqualsValue(Twist)
	Twist=GetValue("TWIST ANGLE  ",Answer$)
	IF ExitScript(Destination$) THEN Leave
END IF
IF Ask_scale THEN
        Stat=SetInputFormat("n4=","")
        Stat= SetEqualsValue(1.0)
        Sfactor=GetValue("SCALE FACTOR  ",Answer$)
        IF ExitScript(Destination$) THEN Leave
END IF

Pick_contour:!
Stat=SetInputFormat("a1",",E,")
Contour=PickGroupEnt("PICK CONTOUR TO BE SWEPT  Edge group",0,Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$= "E" THEN
        Solid_body= WsFalse

        E1=WPKPickEntity("PICK EDGE GROUP",WsPKPickEdges)
        IF (ExitScript(Destination$)) THEN Leave
        IF NOT WPKIsEntity(E1) THEN Pick_contour

        Pkgroup= WPKContainingGroup(E1,1)
        IF NOT WPKIsEntity(Pkgroup) THEN Pick_contour

        Contour= Pkgroup
        Closed= WsFalse
ELSE
        Closed= IsContClosed(Contour)
END IF


Pick_path:!
Path=PickEntity("PICK ENTITY TO SWEEP ALONG")
IF (ExitScript(Destination$)) THEN Leave


Solid_body= WsFalse
IF Closed THEN
        Stat=SetInputFormat("a1=",",1,2,")
        Stat=SetEqualsValue(0,"Solid")
        Stat=GetValue("BODY TYPE:  ( 1 ) solid  ( 2 ) sheet ",Answer$)
        IF ExitScript(Destination$) THEN Leave
        IF Answer$= "1" THEN Solid_body= WsTrue
END IF

WPKClearErrorFlag
IF Twist_on THEN
    Pkbody=WPKTwistSweptBody(Contour,Path,Twist,Sfactor,Solid_body,Alignment,Swept_form,Simplify)
ELSE
    Pkbody=WPKMakeSweptBody(Contour,Path,Solid_body,Alignment,Swept_form,Simplify)
END IF

ActivateUndo
Stat= AdvanceUndoNumber("sweep contour along entity")
Stat= AddItemToUndo(WsUBPKSessionMark)
WPKErrorCheck
GOTO Pick_contour

Leave:!
V2=CreateVariable("swept body form",WsPKSolidsVars,Swept_form)
V2=CreateVariable("simplify swept body",WsPKSolidsVars,Simplify)
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END
