
! script name: 3dcpaths.d/bdytrmcpthgrp
! 3dtopic: trim cutterpath group with boundary

!A
!A NAME:
!A
!A 	3D Modify: Boundary Trim Group
!A
!A DESCRIPTION:
!A
!A 	This script trims a 3D cutterpath Group 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 CUTTERPATH GROUP TO BE TRIMMED: Pick an element on the 
!B		cutterpath to be trimmed.
!B

Stat=ChangeLabelStr("ScriptNameStatus","Function: boundary trim cutterpath group")

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

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

Stat=SetInputFormat("n4","")

Boundary_loop:!
Stat=SetPickMask(WsPickNoSurf)
Contour=PickEntity("PICK EXTERIOR CONTOUR",Answer$)
IF ExitScript(Destination$) THEN Leave
IF NOT ValidGeometry(Contour) THEN Boundary_loop

!   Stat=SetWorkplane(Contour)

Closed=IsContClosed(Contour)
IF NOT Closed THEN Boundary_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

Pick_loop:!
Stat=SetPickMask(WsPickGeometry)
Trim_cpath=PickGroupEnt("PICK CUTTERPATH GROUP")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidGeometry(Trim_cpath) THEN Pick_loop

!   Stat=SetWorkplane(Contour)

New_cpath=BdyTrimCPathGrp(Contour,Islands,Trim_cpath)
IF ValidGeometry(New_cpath) THEN 
	Stat=DeleteGroup(Trim_cpath,1)
	Stat=PlotEntity(New_cpath)
END IF

GOTO Pick_loop

Leave:!
Stat=SetPickMask(WsPickGeometry)
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
