
! script name: vgroups.d/ptsincont
! var_topic: group all points of a group inside closed contour

!A
!A NAME:
!A
!A 	Group Points in a Group Inside a Contour   (VARIATIONAL)
!A
!A DESCRIPTION:
!A
!A 	This script will sub-group a group of points that are inside
!A	a  closed contour and inside.
!A
!B INSTRUCTIONS:
!B
!B 	SELECT GROUP OF POINTS: Select the group of points to sub-divide.
!B
!B 	PICK BOUNDING CONTOUR: Pick the contour to be used as the boundary.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: group points of a group inside a contour ")

DIM Answer$[256]
DIM Destination$[256]
DIM Group$[256],Contour$[256]
DIM Name$[256]
DEG

Group_loop:!
Var_object=CheckVarObject
IF ExitScript(Destination$) THEN Leave
Highlight_color=2

ActivateUndo
Start:Stat=SetInputFormat("a99=","",WsFalse)
Stat= SetEqualsValue(0,"A")
Stat=GetValue("GROUP NAME, Autoname ",Name$)
IF ExitScript(Destination$) THEN Leave
IF Name$= "A" OR Name$="a" OR Name$= "Autoname" OR Name$="autoname" THEN
        Auto_name=1
ELSE
        Auto_name=0
END IF
E1= FindNamedGrp(Name$)
IF ValidGeometry(E1) THEN
        Stat=SetInputFormat("a1",",P,")
        Stat=GetValue("NAME IN USE,  Proceed",Answer$)
        IF ExitScript(Destination$) THEN Leave
        IF Answer$="P" THEN Start
END IF
Pick_group:G1=PickGroupEnt("SELECT GROUP OF POINTS")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(G1) THEN Pick_group
Stat= EntityNameCheck(G1,Group$)

Pick_cont:Contour=PickGroupEnt("PICK BOUNDING CONTOUR")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(Contour) THEN Pick_cont
Stat= EntityNameCheck(Contour,Contour$)

IF Auto_name THEN
        Stat=GenerateVarName(WsGroupEnt,Name$)
END IF
RecordFunctionOn
Stat=RecordDescr("GROUP: Group points of a group inside a closed contour")
G1=GrpInsideCont(Contour$,Group$,WsInside)
Stat= NameEntity(G1,Name$)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF ValidGeometry(G1) THEN
	ActivateUndo
	Stat= AdvanceUndoNumber("pts inside contour")
	Stat= AddItemToUndo(WsUBCreateMode,G1)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
        Stat=Highlight(G1,Highlight_color,WsDirArrowsOff)
ELSE
	Stat= SetInputFormat("a1=",",Y,N,")
	Stat= GetValue("NO GROUP CREATED. FORCE RECORD  Yes or No ",Answer$)
	IF Answer$="N" THEN DelLastVarRecord
END IF
GOTO Group_loop

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


