
! script name: vnormals.d/mansurfgrp
! var_topic: manual group surfaces 

!A
!A NAME:
!A
!A 	Manual Group
!A
!A DESCRIPTION:
!A	
!A 	Makes a surface group by picking the individual surfaces.
!A 	Normal directions are automatically set.
!A
!B INSTRUCTIONS:
!B
!B 	SURFACE GROUP NAME: Enter the surface group name.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: manual group ")

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


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

DeActivateUndo
Nlength=NamedVarVal("3D Normal Length",Ws3DSystemVars,1.0)
Ncolor= 3
Nlinetype= 10

Start:!
Group_name:!
Stat=SetInputFormat("a99","")
Stat= SetEqualsValue(0,"A")
Stat=GetValue("SURFACE GROUP NAME, Autoname ",Name$)
IF (ExitScript(Destination$)) THEN Leave
IF Name$= "A" OR Name$="a" OR POS(Name$,"Autoname") OR POS(Name$,"autoname") THEN
        Stat=GenerateVarName(WsGroupEnt,Name$)
END IF
Group= FindNamedGrp(Name$)
IF ValidGeometry(Group) THEN
        Stat= SetInputFormat("a1",",N,")
        Stat= GetValue("GROUP EXISTS: New name",Answer$)
        IF (ExitScript(Destination$)) THEN Leave
        GOTO Group_name
END IF

Make_group:!
Part_group= CreateGroup("TEMPGROUP",WsSurfaceGroup)

Pick_loop:!
Stat=SetPickMask(WsPickSurfOnly)
Stat=SetInputFormat("a1",",P,U,C,")
E1=PickEntity("PICK ELEMENT, Unpick, Clear, Proceed",Answer$)
IF ExitScript(Destination$) THEN Leave
Choice$=UPC$(Answer$)
SELECT Choice$
   CASE "P"
      Stat= SetSelectedFlag(Part_group,WsFalse)
      Stat= PlotEntity(Part_group)
      GOTO Make_record
   CASE "U"
      Element_num=GroupCount(Part_group)
      Temp_e1=GroupElement(Part_group,Element_num)
      IF NOT ValidGeometry(Temp_e1) THEN Pick_loop
      Stat= SetSelectedFlag(Temp_e1,WsFalse)
      Stat=PlotEntity(Temp_e1)
      Stat=RemoveFromGrp(Part_group,Element_num)
   CASE "C"
      Stat= SetSelectedFlag(Part_group,WsFalse)
      Stat= PlotEntity(Part_group)
      Stat=DeleteEntity(Part_group)
      GOTO Make_group
   CASE ELSE
      IF NOT ValidGeometry(E1) THEN Pick_loop
      Stat= SetSelectedFlag(E1,WsTrue)
      N1= ElementGrpNum(Part_group,E1)
      IF N1 = 0 THEN
              Stat=AppendToGroup(Part_group,E1)
      END IF
      Stat=PlotEntity(E1)
END SELECT
GOTO Pick_loop


Make_record:!
Stat= SetPickMask(WsPickAll)
IF Name$= "" THEN
	Stat= GenerateVarName(WsGroupEnt,Name$)
END IF
RecordFunctionOn
Stat= RecordDescr("GROUP: Surfaces")
G1= CreateGroup(Name$,WsSurfaceGroup)
RecordFunctionOff
Num_surfs= GroupCount(Part_group)
FOR I= 1 TO Num_surfs
	surf1= GroupElement(Part_group,I)
	IF ValidGeometry(Surf1) THEN
		Stat= EntityNameCheck(Surf1,Surface$)
		
		RecordFunctionOn
		Stat= AlignSurfNormal(Surface$)
		Stat= SetEdgeExt(Surface$,0)
		Stat= AddToGroup(G1,Surface$)
		RecordFunctionOff

		Stat= ShowSurfNormal(Surf1,0.51,0.52,Nlength,Ncolor,Nlinetype)

	END IF
NEXT I
RecordFunctionOn
Stat= NameEntity(G1,Name$)
RecordFunctionOff
CloseVarRecord
IF NOT ValidGeometry(G1) THEN
        DelLastVarRecord
END IF
Stat= DeleteEntity(Part_group)

GOTO Leave

Leave:!
Stat= SetPickMask(WsPickAll)
Stat= DeleteEntity(Nline)
Stat= DeleteEntity(Part_group)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
