
! script name: vsurfaces.d/offsurfgrp
! var_topic: make offset surfaces from a group of surfaces

!A
!A NAME:
!A
!A 	Offset: Box	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will make offset surfaces from a group of surfaces in a box.
!A
!B INSTRUCTIONS:
!B
!B 	SELECT VIEW FOR SELECTION BOX: Pick the view that surfaces are to be
!B 		selected in.
!B
!B 	OFFSET: Enter the offset amount to be used for the group of surfaces.
!B
!C NOTES:
!C
!C 	An offset surface is one of the standard surfaces offset in the normal
!C 	direction by the offset amount.
!C

Stat=ChangeLabelStr("ScriptNameStatus","Function: offset surface group ")

DIM Answer$[256]
DIM Destination$[256]
DIM Name$[256]
DIM Surface$[256]
DIM Offset_var$[256]

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

DEG

ActivateUndo
Stat=SetInputFormat("n4","")

Group=CreateGroup("TEMP")


Vnum= LastPickView
Stat=PickBox(Group,Vnum,WsPickPen)
IF ExitScript(Destination$) THEN Leave

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Offset)
Offset=GetValue("OFFSET",Answer$)
IF ExitScript(Destination$) THEN Leave
No_offset_var= LastVariableInput(Offset_var$)

Num_surfs= GroupCount(Group)
IF NOT Num_surfs THEN Leave

Stat= GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("OFFSET: Surfaces")
Stat= SetRecDelLastExec
Pgroup= CreateGroup("TEMPGROUP",WsSurfaceGroup)
RecordFunctionOff
Num_surfs= GroupCount(Group)
FOR I= 1 TO Num_surfs
        surf1= GroupElement(Group,I)
	IF ValidGeometry(Surf1) THEN
                Stat= EntityNameCheck(Surf1,Surface$)
		RecordFunctionOn
		Stat= AddToGroup(G1,Surface$)
		RecordFunctionOff
	END IF
NEXT I
RecordFunctionOn
IF No_offset_var THEN
        V1= FreeParameter("Offset",Offset)
ELSE
        V1= FreeParameter("Offset",Offset_var$)
END IF
G1=OffsetSurfGrp(Pgroup,V1)
Stat= AutoNameGroup(G1,Name$)
  RecordFunctionOff
    ActivateUndo
    Stat= AdvanceUndoNumber("offset surfaces")
    Stat= AddGroupToUndo(WsUBCreateMode,G1,0,WsFalse)
  RecordFunctionOn
Stat= DeleteEntityList(G1,Pgroup)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat=DeleteEntity(Group)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)

Leave:!
Stat=SetInputFormat("n4","")
Stat=DeleteEntity(Group)
Stat=DeleteEntity(G1)

IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END

