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

!A
!A NAME:
!A
!A 	Group Points 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 	PICK BOUNDING CONTOUR: Pick the contour to be used as the boundary.
!B

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

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

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

Start:Stat=SetInputFormat("a99=","",WsFalse)
ActivateUndo
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_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 inside contour")
G1= GrpByEntType(WsPointEnt)
G2=GrpInsideCont(Contour$,G1,WsInside)
Stat= NameEntity(G2,Name$)
Stat= DeleteEntity(G1)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF ValidGeometry(G2) THEN
	ActivateUndo
	Stat= AdvanceUndoNumber("pts inside contour")
	Stat= AddItemToUndo(WsUBCreateMode,G2)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
        Stat=Highlight(G2,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


