
! script name: points.d/ptsinbdy
! topic: delete points exterior to a boundary

!A
!A NAME:
!A
!A 	Points in Boundary
!A
!A DESCRIPTION:
!A
!A 	This script will eliminate all points within a specified box that
!A 	are inside the exterior contour and outside the islands delected.
!A
!A~ image location - images/pointsinboundary.jpg
!B INSTRUCTIONS:
!B
!B 	SELECT VIEW FOR SELECTION BOX: Pick the view to be used.
!B
!B 	PICK FIRST CORNER OF PICK ZONE: Pick a corner of the box to be used.
!B
!B 	PICK SECOND CORNER OF PICK ZONE: Pick the other corner of the box.
!B
!B 	PICK EXTERIOR CONTOUR: Pick the contour to be used as the
!B 		exterior boundary, it may be partially outside the view box.
!B
!B 	NUMBER OF ISLANDS: Enter the number of islands to be used as a
!B 		reference for the point deletion.
!B
!B 	   NOTE: The following question will only be asked if the number of
!B 		 islands is not zero.
!B
!B 	   PICK ISLAND # : Pick the islands to be used.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: delete points exterior to a boundary ")

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

DeActivateUndo
Group_loop:!
Group=CreateGroup("TEMPGROUP")

Vnum=PickView("SELECT VIEW FOR SELECTION BOX")
IF (ExitScript(Destination$)) THEN Leave

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

Pick_loop:!
Offset_sign=1
Contour=PickEntity("PICK EXTERIOR CONTOUR")
IF (ExitScript(Destination$)) THEN Leave
IF (NOT ValidGeometry(Contour)) THEN Pick_loop
Closed=IsContClosed(Contour)
IF NOT Closed THEN Pick_loop

Stat=SetInputFormat("n0","")
Nisles=GetValue("NUMBER OF ISLANDS",Answer$)
IF (ExitScript(Destination$)) THEN Leave

Islands=CreateGroup("ISLANDS")
FOR I=1 TO Nisles

	Isle=PickEntity("PICK ISLAND #"&VAL$(I))
	IF (ExitScript(Destination$)) THEN Leave

	Stat=AddToGroup(Islands,Isle)

NEXT I

Group1=PtsInGroup(Group,WsPickPoints)
Stat=DeleteEntity(Group)

Outgroup=GrpInBoundary(Contour,Islands,Group1,WsInside)

Group2=SubtractGrps(Group1,Outgroup)

Stat=UnLink(Group2)

Stat=DeleteGroup(Group2)
TransformCleanUp

Stat=DeleteEntity(Outgroup)
Stat=DeleteEntity(Group1)
Stat=DeleteEntity(islands)

GOTO Group_loop

Leave:!
Stat=DeleteEntity(Group)
Stat=DeleteEntity(Group1)
Stat=DeleteEntity(Outgroup)
Stat=DeleteEntity(islands)

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