
! script name: 3druled.d/closedruled
! 3dtopic: Makes a ruled translation bounded by a top and bottom plane

!A
!A NAME:
!A
!A 	Closed Ruled Translation
!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]

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



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 ValidGeometry(Contour)) THEN Contour_loop
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
	Closed=IsContClosed(Isle)
	IF NOT Closed THEN Pick_isle
	Stat=AddToGroup(Islands,Isle)
	Stat= SetSelectedFlag(Isle,WsTrue)
	Stat= PlotEntity(Isle)
	Stat=SetPickMask(WsPickGeometry)
NEXT I

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Xshift)
Xshift=GetValue("X SHIFT",Answer$)
IF ExitScript(Destination$) THEN Leave

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Yshift)
Yshift=GetValue("Y SHIFT",Answer$)
IF ExitScript(Destination$) THEN Leave

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Zshift)
Zshift=GetValue("Z SHIFT",Answer$)
IF ExitScript(Destination$) THEN Leave

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

G1=ClosedRuledTrans(Contour,Islands,Xshift,Yshift,Zshift,Tol,Firston,Secondon,Spliton)

IF ValidGeometry(G1) THEN
	ActivateUndo
	Stat= AdvanceUndoNumber("closed ruled trans")
	Stat= AddgroupToUndo(WsUBCreateMode,G1,WsFalse)
	Stat=DeleteEntity(G1)
END IF

Stat= PlotEntity(Contour)
Stat= PlotEntity(Islands)
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
