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

!A
!A NAME:
!A
!A 	Sweep Entity along Entity
!A
!A DESCRIPTION:
!A
!A	This script sweeps an entity along an entity. The resulting
!A	body is a sheet body. 
!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	PICK ENTITY TO BE SWEPT: Pick the entity to be swept. It should be
!B 		defined in a plane which is normal to the sweep. It should
!B 		be placed at a vertex of the sweep path.  The entity should
!B 		not be a full circle or an ellipse.
!B
!B	PICK ENTITY TO SWEEP ALONG: Pick the entity defining the sweep.
!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 entity 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_entity:!
E1=PickEntity("PICK ENTITY TO BE SWEPT")
IF (ExitScript(Destination$)) THEN Leave

Solid_body= WsFalse

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

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

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

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
