
! script name: vruled.d/closedruled
! var_topic: Makes a ruled translation bounded by a top and bottom plane

!A
!A NAME:
!A
!A 	Closed Ruled Translation  VARIATIONAL 
!A
!A DESCRIPTION:
!A
!A	This script makes a ruled surface translation bounded by 
!A	top and bottom planes.  
!A
!B INSTRUCTIONS:
!B
!B 	PICK EXTERIOR CONTOUR: Pick the exterior boundary of the boundary.
!B 		The contour had to be created by types or by auto link.
!B
!B 	# OF INTERIOR CONTOURS: Enter the number of interior islands.
!B
!B 	PICK INTERIOR # : Pick the interior contours.  The interior contour(s)
!B 		had to be created by types or by auto link.
!B
!C NOTE:
!C
!C	The exterior and interior contours must be closed.
!C	The construction must take place in the workplane of the contours.
!C	The contours must be flat relative to the plane created.
!C

stat=ChangeLabelStr("ScriptNameStatus","Function: closed ruled translation ")

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Contour$[256]
DIM Islands$[256]
DIM Isle_name$[256]
DIM X_var$[256]
DIM Y_var$[256]
DIM Z_var$[256]

Firston=1
Secondon= 1
Spliton= 0
IF ARGC > 1 THEN
	A$= ARGV(1)
	Firston= VAL(A$)
	IF ARGC > 2 THEN
		A$= ARGV(2)
		Secondon= VAL(A$)
		IF ARGC > 3 THEN
			A$= ARGV(3)
			Spliton= VAL(A$)
		END IF
	END IF
END IF

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


Highlight_color= 3
Stat= SetDefaults(WsSelectedEntPen,Highlight_color)
Tol=NamedVarVal("3D Trimming Tol",Ws3DSystemVars,0.005)


Contour_loop:!
ActivateUndo
Stat=SetPickMask(WsPickNoSurf)
Contour=PickGroupEnt("PICK EXTERIOR CONTOUR")
IF (ExitScript(Destination$)) THEN Leave
IF (NOT ValidDependency(Contour)) THEN Boundary_loop
Stat= EntityNameCheck(Contour,Contour$)
Stat=SetPickMask(WsPickGeometry)

Closed=IsContClosed(Contour)
IF NOT Closed THEN Contour_loop
Stat= SetSelectedFlag(Contour,WsTrue)
Stat= PlotEntity(Contour)

Stat=SetInputFormat("n0=","")
Stat= SetEqualsValue(0)
Nisles=GetValue("# OF INTERIOR CONTOURS  1 2 3 4 5 ",Answer$)
IF (ExitScript(Destination$)) THEN Leave

Islands=CreateGroup("ISLANDS")
FOR I=1 TO Nisles
Pick_isle: Stat=SetPickMask(WsPickNoSurf)
        Isle=PickGroupEnt("PICK INTERIOR CONTOUR #"&VAL$(I))
        IF (ExitScript(Destination$)) THEN Leave
        IF (NOT ValidDependency(Isle)) THEN Pick_isle
	Closed=IsContClosed(Isle)
	IF NOT Closed THEN Pick_isle
        Stat=AppendToGroup(Islands,Isle)
        Stat= SetSelectedFlag(Isle,WsTrue)
        Stat= PlotEntity(Isle)
        Stat=SetPickMask(WsPickGeometry)
NEXT I
Stat= SetSelectedFlag(Contour,WsTrue)
Stat= SetSelectedFlag(Islands,WsTrue)

Xyz_shift:!
stat= SetInputFormat("n4=","")
Stat=SetEqualsValue(Xmove)
Xmove=GetValue("X SHIFT ")
IF ExitScript(Destination$) THEN Leave
No_x_var= LastVariableInput(X_var$)

Stat=SetEqualsValue(Ymove)
Ymove=GetValue("Y SHIFT ")
IF ExitScript(Destination$) THEN Leave
No_y_var= LastVariableInput(Y_var$)

Stat=SetEqualsValue(Zmove)
Zmove=GetValue("Z SHIFT ")
IF ExitScript(Destination$) THEN Leave
No_z_var= LastVariableInput(Z_var$)

Stat= SetSelectedFlag(Contour,WsFalse)
Stat= SetSelectedFlag(Islands,WsFalse)

tat= GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat= SetRecDelLastExec
Stat= RecordDescr("RULED: Closed ruled surfaces")
Stat= NullReference(Contour$)
Isles=CreateGroup("")
RecordFunctionOff
FOR I= 1 TO Nisles
        Isle= GroupElement(Islands,I)
        Stat= EntityNameCheck(Isle,Isle_name$)
        RecordFunctionOn
        Stat= AppendToGroup(Isles,Isle_name$)
        RecordFunctionOff
NEXT I
RecordFunctionOn
IF No_x_var THEN
        V1= FreeParameter("Xmove",Xmove)
ELSE
        V1= FreeParameter("Xmove",X_var$)
END IF
IF No_y_var THEN
        V2= FreeParameter("Ymove",Ymove)
ELSE
        V2= FreeParameter("Ymove",Y_var$)
END IF
IF No_z_var THEN
        V3= FreeParameter("Zmove",Zmove)
ELSE
        V3= FreeParameter("Zmove",Z_var$)
END IF
V4= FreeParameter("Tolerance",Tol)
V5= FreeParameter("First plane on",Firston)
V6= FreeParameter("Second plane on",Secondon)
V7= FreeParameter("Split ruled surface",Spliton)
G1=ClosedRuledTrans(Contour$,Isles,V1,V2,V3,V4,V5,V6,V7)
RecordFunctionOff
IF ValidGeometry(G1) THEN
        RecordFunctionOn
        Stat= AutoNameGroup(G1,Name$)
        ActivateUndo
        Stat= AdvanceUndoNumber("closed ruled surfs")
        Stat= AddGroupToUndo(WsUBCreateMode,G1,0,WsFalse)
        stat= DeleteEntity(G1)
        RecordFunctionOff
        No_surfs=0
ELSE
        No_surfs=1
END IF
Stat= PlotEntity(Contour)
Stat= PlotEntity(Islands)
RecordFunctionOn
Stat=DeleteEntity(Isles)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF No_surfs THEN
        DelLastVarRecord
ELSE
        ActivateUndo
        Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
Stat=DeleteEntity(Islands)


GOTO Contour_loop

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