
! script name: trim.d/boundarysplit
! topic: split contour with boundary

!A
!A NAME:
!A
!A 	Boundary Split
!A
!A DESCRIPTION:
!A
!A 	This script splits a contour with a boundary.
!A
!B INSTRUCTIONS:
!B
!B 	PICK EXTERIOR CONTOUR: Pick the contour to be used as the boundary
!B 		of the contour to be trimmed.
!B
!B 	NUMBER OF ISLANDS: Enter the number of islands to be included for
!B 		trimming purposes.
!B
!B 	PICK ISLAND # : Pick the islands to be included.
!B
!B 	PICK CONTOUR TO BE TRIMMED: Pick an element on the contour to be
!B 		trimmed.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: boundary split ")

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


ActivateUndo
Active_workplane=0
Work=CurrentWorkplane
IF (ValidGeometry(Work)) THEN Active_workplane=1

Stat=SetInputFormat("n4","")

Boundary_loop:!
Contour=PickGroupEnt("PICK EXTERIOR CONTOUR",0,Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF (NOT ValidGeometry(Contour)) THEN Boundary_loop

Stat=SetWorkplane(Contour)

Closed=IsContClosed(Contour)
IF Closed THEN 
	Stat=SetInputFormat("n0=","")
	Stat= SetEqualsValue(0)
	Nisles=GetValue("NUMBER OF ISLANDS",Answer$)
	IF (ExitScript(Destination$)) THEN Leave
ELSE
	Nisles= 0
END IF

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

	Stat=SetInputFormat("n4","")
	Isle=PickGroupEnt("PICK ISLAND #"&VAL$(I),0)
	IF (ExitScript(Destination$)) THEN Leave

	Stat=AddToGroup(Islands,Isle)

NEXT I

Pick_loop:Trim_contour= PickGroupEnt("PICK CONTOUR TO BE TRIMMED",0,Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF (NOT ValidGeometry(Trim_contour)) THEN Pick_loop

Stat=SetWorkplane(Contour)

Stat= EraseEntity(Trim_contour)
PlotOff

Trim_contour1= CopyGroup(Trim_contour)
ActivateUndo
Stat= AdvanceUndoNumber("boundary split")
Stat= AddGroupToUndo(WsUBDeleteMode,Trim_contour,1,WsTrue)
Stat= DeleteGroup(Trim_contour,WsTrue)

Trim_group=BoundarySplit(Contour,Islands,Trim_contour1)
PlotOn
IF (ValidGeometry(Trim_group)) THEN
	Stat=UnLink(Trim_contour1)
	Stat= DeleteGroup(Trim_contour1,WsTrue)
	Stat= PlotEntity(Trim_group)
	Stat= AddGroupToUndo(WsUBCreateMode,Trim_group,0,WsTrue)
	Stat=DeleteEntity(Trim_group)
END IF

GOTO Pick_loop

Leave:!
Stat=DeleteEntity(Islands)

IF Active_workplane THEN
	Stat=SetWorkplane(Work)
ELSE
	StdWorkplane
END IF
Stat=SetInputFormat("n4","")
IF (NOT LEN(Destination$)) THEN
	  LOAD "typecontrol"
ELSE
	  LOAD Destination$
END IF
END
